0

I have created a Minecraft mod in forge 1.12.2, it works just fine in IntelliJ when I run it there, but when I build it I get a noclassdeffound error. From the crash logs, I can see that the issue is in one specific line of code:

    registerEntity("Ghost",
        EntityGhost.class,
        Reference.ENTITY_TEST, 50, 5923, 6096);

more specifically the EntityGhost.class line.

The code for EntityInit, where the error is found

package com.example.examplemod.init;

import com.example.examplemod.ExampleMod;
import com.example.examplemod.Reference;
import com.example.examplemod.entity.ghost.EntityGhost;
import net.minecraft.entity.Entity;

import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.EntityRegistry;

public class EntityInit {
    public static void registerEntities() {
        registerEntity("Ghost",
            EntityGhost.class,
            Reference.ENTITY_TEST, 50, 5923, 6096);
    }

    private static void registerEntity(
        String name, 
        Class<? extends Entity> entity, 
        int id, 
        int range, 
        int color1, 
        int color2
    ) {
        EntityRegistry.registerModEntity(
            new ResourceLocation(Reference.MOD_ID + ":" + name), 
            entity, 
            name, 
            id, 
            ExampleMod.instance, 
            range, 
            1, 
            true, 
            color1, 
            color2
        );
    }

    private static void registerNonMobEntity() {

    }
}

EntityGhost:

package com.example.examplemod.entity.ghost;

import com.example.examplemod.Util.SoundsHandler;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.monster.EntityMob;
// import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraft.world.World;

import javax.annotation.Nullable;

public class EntityGhost extends EntityCreature {

    public EntityGhost(World worldIn) {
        super(worldIn);
        this.setSize(width, height);
    }

    @Override
    protected void initEntityAI() {
        this.tasks.addTask(2, new EntityAISwimming(this));
        this.tasks.addTask(3, new EntityAIWander(this, 0.6));
        this.tasks.addTask(2, new EntityAIAvoidEntity<>(this, EntityMob.class, 4.0F, 2.2D, 2.2D));
        // this.tasks.addTask(4, new EntityAIWatchClosest(this, EntityPlayer.class, 10.0F));
        this.tasks.addTask(2, new EntityAIAttackMelee(this, 1D, false));
    }

    @Override
    protected void applyEntityAttributes() {
        super.applyEntityAttributes();
        this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(5.0);
        this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.215);
        this.getEntityAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(10.0D);
    }

    @Nullable
    @Override
    protected SoundEvent getDeathSound() {
        return SoundsHandler.Ghost_Death;
    }

    @Nullable
    @Override
    protected SoundEvent getAmbientSound() {
        return SoundsHandler.Ghost_Ambient;
    }

    @Nullable
    @Override
    protected SoundEvent getHurtSound(DamageSource damageSourceIn) {
        return SoundsHandler.Ghost_Hurt;
    }

    @Nullable
    @Override
    protected ResourceLocation getLootTable() {
        return super.getLootTable();
    }
}

Here is the complete error log

---- Minecraft Crash Report ----
// There are four lights!

Time: 11/17/22 9:39 AM
Description: There was a severe problem during mod loading that has caused the game to fail

net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from Example Mod (examplemod)
Caused by: java.lang.NoClassDefFoundError: com/example/examplemod/entity/ghost/EntityGhost
    at com.example.examplemod.init.EntityInit.registerEntities(EntityInit.java:15)
    at com.example.examplemod.Util.RegistryHandler.preInitRegistries(RegistryHandler.java:38)
    at com.example.examplemod.ExampleMod.preInit(ExampleMod.java:38)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:637)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
    at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
    at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
    at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
    at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
    at com.google.common.eventbus.EventBus.post(EventBus.java:217)
    at net.minecraftforge.fml.common.LoadController.sendEventToModContainer(LoadController.java:219)
    at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.google.common.eventbus.Subscriber.invokeSubscriberMethod(Subscriber.java:91)
    at com.google.common.eventbus.Subscriber$SynchronizedSubscriber.invokeSubscriberMethod(Subscriber.java:150)
    at com.google.common.eventbus.Subscriber$1.run(Subscriber.java:76)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutor.execute(MoreExecutors.java:399)
    at com.google.common.eventbus.Subscriber.dispatchEvent(Subscriber.java:71)
    at com.google.common.eventbus.Dispatcher$PerThreadQueuedDispatcher.dispatch(Dispatcher.java:116)
    at com.google.common.eventbus.EventBus.post(EventBus.java:217)
    at net.minecraftforge.fml.common.LoadController.distributeStateMessage(LoadController.java:136)
    at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:629)
    at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:252)
    at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:467)
    at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:378)
    at net.minecraft.client.main.Main.main(SourceFile:123)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
Caused by: java.lang.ClassNotFoundException: com.example.examplemod.entity.ghost.EntityGhost
    at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 44 more
Caused by: java.lang.NullPointerException
    at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:182)
    ... 46 more


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- System Details --
Details:
    Minecraft Version: 1.12.2
    Operating System: Windows 10 (amd64) version 10.0
    Java Version: 1.8.0_51, Oracle Corporation
    Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
    Memory: 551627568 bytes (526 MB) / 872415232 bytes (832 MB) up to 2147483648 bytes (2048 MB)
    JVM Flags: 8 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xmx2G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M
    IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
    FML: MCP 9.42 Powered by Forge 14.23.5.2859 5 mods loaded, 5 mods active
    States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

    | State | ID         | Version      | Source                        | Signature                                |
    |:----- |:---------- |:------------ |:----------------------------- |:---------------------------------------- |
    | LCH   | minecraft  | 1.12.2       | minecraft.jar                 | None                                     |
    | LCH   | mcp        | 9.42         | minecraft.jar                 | None                                     |
    | LCH   | FML        | 8.0.99.99    | forge-1.12.2-14.23.5.2859.jar | e3c3d50c7c986df74c645c0ac54639741c90a557 |
    | LCH   | forge      | 14.23.5.2859 | forge-1.12.2-14.23.5.2859.jar | e3c3d50c7c986df74c645c0ac54639741c90a557 |
    | LCE   | examplemod | 1.0          | modid-1.0.jar                 | None                                     |

    Loaded coremods (and transformers): 
    GL info: ' Vendor: 'Intel' Version: '4.6.0 - Build 30.0.101.1003' Renderer: 'Intel(R) Iris(R) Xe Graphics'

If there is anything else I can provide please let me know, I have absolutely no idea where to go frrom here.

Dmitriy Popov
  • 2,150
  • 3
  • 25
  • 34

0 Answers0