加载模组时无法注册方块


版本信息
你使用的系统:win10
你是用的JDK: jdk8 64位
你使用的IDE:IntelliJ IDEA
你使用的IDE版本: 2019.3.3
Forge版本: 1.15.2-31.2.0-mdk
Minecraft版本: 1.15.2
Mapping 文件版本: 20200514-1.15.1

出错图


错误情况简述
照着教程敲一个方块,进游戏时就这样了。我认为是注册方面出现了问题,但无论怎么敲,注册阶段总是会出现错误

报错日志

[21七月2020 08:00:25.612] [Render thread/ERROR] [net.minecraftforge.fml.javafmlmod.FMLModContainer/]: Exception caught during firing event: Registry Object not present: crystal:obsidian_block
	Index: 1
	Listeners:
		0: NORMAL
		1: net.minecraftforge.eventbus.EventBus$$Lambda$2094/[email protected]
java.lang.NullPointerException: Registry Object not present: crystal:obsidian_block
	at java.util.Objects.requireNonNull(Objects.java:290)
	at net.minecraftforge.fml.RegistryObject.get(RegistryObject.java:92)
	at com.Github.craft.crystal.Registry.ItemRegistry.lambda$static$7(ItemRegistry.java:40)
	at net.minecraftforge.registries.DeferredRegister.lambda$register$0(DeferredRegister.java:84)
	at net.minecraftforge.registries.DeferredRegister.addEntries(DeferredRegister.java:117)
	at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:212)
	at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:204)
	at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258)
	at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106)
	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65)
	at java.util.function.Consumer.lambda$andThen$0(Consumer.java:65)
	at net.minecraftforge.fml.ModContainer.transitionState(ModContainer.java:112)
	at net.minecraftforge.fml.ModList.lambda$dispatchSynchronousEvent$5(ModList.java:126)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
	at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
	at net.minecraftforge.fml.ModList.dispatchSynchronousEvent(ModList.java:126)
	at net.minecraftforge.fml.ModList.lambda$static$1(ModList.java:96)
	at net.minecraftforge.fml.LifecycleEventProvider.dispatch(LifecycleEventProvider.java:71)
	at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:214)
	at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$25(ModLoader.java:206)
	at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:976)
	at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:206)
	at net.minecraftforge.fml.client.ClientModLoader.lambda$begin$2(ClientModLoader.java:97)
	at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$5(ClientModLoader.java:113)
	at net.minecraftforge.fml.client.ClientModLoader.begin(ClientModLoader.java:97)
	at net.minecraft.client.Minecraft.<init>(Minecraft.java:397)
	at net.minecraft.client.main.Main.main(Main.java:141)
	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:498)
	at net.minecraftforge.userdev.FMLUserdevClientLaunchProvider.lambda$launchService$0(FMLUserdevClientLaunchProvider.java:55)
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:54)
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:72)
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:81)
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:65)
	at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:102)
日志位置`run/logs/debug.log`

相关代码

public class BlockRegistry {
    public static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>(ForgeRegistries.BLOCKS, "crystal");
//    public static RegistryObject<Block> grayCrystalOre = BLOCKS.register("grayCrystal_ore", () -> {
//        return new GrayCrystalOre();
//    });
    public static RegistryObject<Block> obsidianBlock = BLOCKS.register("obsidian_block", () -> {
        return new ObsidianBlock();
    });
}


public class ItemRegistry {
    .....
//    public static RegistryObject<Item> grayCrystalOre = ITEMS.register("grayCrystal_ore", () -> {
//        return new BlockItem(BlockRegistry.grayCrystalOre.get(), new Item.Properties().group(Mod_Group.itemGroup));
//    });
    public static RegistryObject<Item> obsidianBlock = ITEMS.register("obsidian_block", () -> {
        return new BlockItem(BlockRegistry.obsidianBlock.get(), new Item.Properties().group(Mod_Group.itemGroup));
    });

public class ObsidianBlock extends Block {
    public ObsidianBlock() {
        super(Properties.create(Material.ROCK).hardnessAndResistance(5));
    }
}


FledgeXu


你没有把你方块注册的DeferredRegister写到Mod主类的构造方法里去。


system


该主题在最后一个回复创建后7天后自动关闭。不再允许新的回复。