【问题标题】:How to fix Minecraft 1.12 Null pointer exception error with entities?如何修复实体的 Minecraft 1.12 空指针异常错误?
【发布时间】:2020-05-19 13:48:34
【问题描述】:

我已经尝试修复它很久了,我很难过,每次我打开它都会崩溃并显示相同的错误消息“java.lang.NullPointerException”,这是完整的错误消息:

net.minecraftforge.fml.common.LoaderExceptionModCrash: Caught exception from The Human Tools Mod (sword)
Caused by: java.lang.NullPointerException
    at net.minecraftforge.fml.common.registry.EntityRegistry.doModEntityRegistration(EntityRegistry.java:207)
    at net.minecraftforge.fml.common.registry.EntityRegistry.registerModEntity(EntityRegistry.java:192)
    at com.example.examplemod.init.EntityInit.registerEntity(EntityInit.java:18)
    at com.example.examplemod.init.EntityInit.registerEntities(EntityInit.java:13)
    at com.example.examplemod.util.handlers.RegistryHandler.preInitRegistries(RegistryHandler.java:62)
    at com.example.examplemod.util.ExampleMod.preInit(ExampleMod.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraftforge.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:626)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    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:218)
    at net.minecraftforge.fml.common.LoadController.propogateStateMessage(LoadController.java:196)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    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:135)
    at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:627)
    at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:252)
    at net.minecraft.client.Minecraft.init(Minecraft.java:513)
    at net.minecraft.client.Minecraft.run(Minecraft.java:421)
    at net.minecraft.client.main.Main.main(Main.java:118)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
    at GradleStart.main(GradleStart.java:25)**

以及我的一些代码:

尝试注册实体的代码:

public class EntityInit
{
    public static void registerEntities()
    {
        registerEntity("human", EntityHuman.class, ExampleMod.ENTITY_HUMAN, 50, 3093151, 16287108);
    }

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

【问题讨论】:

  • 它并没有说代码中有任何问题,它只是在尝试运行时崩溃
  • 我不知道 minecraft API,但我建议你使用调试器。
  • 我认为你的模组本身注册不正确。你能发布你的 ExampleMod.java 吗?

标签: java entity minecraft minecraft-forge


【解决方案1】:

我有同样的问题。我对其进行了调试,发现它是由我认为是 net.minecraftforge.fml.common.network.NetworkRegistry 类和枚举 net.minecraftforge.fml.relauncher.Side 之间的版本不匹配引起的。

Side 有 3 个值,但 NetworkRegistry 代码似乎假设只有 2 个,CLIENT 和 SERVER。

我通过复制 NetworkRegistry 类并按如下方式编辑它来解决此问题:

在私有的无参数构造函数中,添加以下行:

channels.put(Side.BUKKIT, Maps.<String,FMLEmbeddedChannel>newConcurrentMap());

Code change

然后你只需要确保你的类的版本在原始版本之前的类路径中(如果你使用的是 eclipse,那么它将是自动的)。您还需要确保为您的类版本使用完全相同的包名称。

【讨论】:

    猜你喜欢
    • 2023-03-15
    • 1970-01-01
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多