I tried to register a custom Stairs Block in my mod, but it always leads to a crash:
java.lang.ExceptionInInitializerError
at net.minecraftforge.registries.NamespacedDefaultedWrapper$Factory.onCreate(NamespacedDefaultedWrapper.java:154)
at net.minecraftforge.registries.RegistryBuilder.lambda$getCreate$2(RegistryBuilder.java:228)
at net.minecraftforge.registries.ForgeRegistry.<init>(ForgeRegistry.java:127)
at net.minecraftforge.registries.RegistryManager.createRegistry(RegistryManager.java:134)
at net.minecraftforge.registries.RegistryBuilder.create(RegistryBuilder.java:184)
at net.minecraftforge.registries.GameData.init(GameData.java:169)
at net.minecraftforge.registries.GameData.<clinit>(GameData.java:153)
at net.minecraft.block.Block.<clinit>(Block.java:81)
at com.faendir.minecraft.hadron.generated.ModObjects0.<clinit>(ModObjects0.java:76)
at com.faendir.minecraft.hadron.generated.Registry1.registerBlock(Registry1.java:35)
at net.minecraftforge.eventbus.ASMEventHandler_10_Registry1_registerBlock_Register.invoke(.dynamic)
at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:80)
at net.minecraftforge.eventbus.EventBus.post(EventBus.java:258)
at net.minecraftforge.fml.javafmlmod.FMLModContainer.fireEvent(FMLModContainer.java:106)
at java.base/java.util.function.Consumer.lambda$andThen$0(Consumer.java:65)
at java.base/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$4(ModList.java:110)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1378)
at net.minecraftforge.fml.ModList.dispatchSynchronousEvent(ModList.java:110)
at net.minecraftforge.fml.ModList.lambda$static$0(ModList.java:81)
at net.minecraftforge.fml.LifecycleEventProvider.dispatch(LifecycleEventProvider.java:71)
at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:173)
at net.minecraftforge.fml.ModLoader.lambda$gatherAndInitializeMods$21(ModLoader.java:165)
at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:918)
at net.minecraftforge.fml.ModLoader.gatherAndInitializeMods(ModLoader.java:165)
at net.minecraftforge.fml.client.ClientModLoader.lambda$begin$2(ClientModLoader.java:68)
at net.minecraftforge.fml.client.ClientModLoader.lambda$createRunnableWithCatch$5(ClientModLoader.java:84)
at net.minecraftforge.fml.client.ClientModLoader.begin(ClientModLoader.java:68)
at net.minecraft.client.Minecraft.init(Minecraft.java:456)
at net.minecraft.client.Minecraft.run(Minecraft.java:365)
at net.minecraft.client.main.Main.main(Main.java:128)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
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:50)
at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:68)
at cpw.mods.modlauncher.Launcher.run(Launcher.java:80)
at cpw.mods.modlauncher.Launcher.main(Launcher.java:65)
at net.minecraftforge.userdev.LaunchTesting.main(LaunchTesting.java:101)
Caused by: java.lang.NullPointerException: Attempted to get vanilla wrapper for unknown registry: class net.minecraft.util.SoundEvent
at org.apache.commons.lang3.Validate.notNull(Validate.java:225)
at net.minecraftforge.registries.GameData.getWrapper(GameData.java:233)
at net.minecraft.util.registry.Registry.forge(Registry.java:250)
at net.minecraft.util.registry.Registry.<clinit>(Registry.java:77)
... 43 more
I'll try to add all relevant classes here, please ask if I need to provide more information to receive help.
@Mod.EventBusSubscriber(
modid = "hadron",
bus = Mod.EventBusSubscriber.Bus.MOD
)
public class Registry1 {
...
@SubscribeEvent
public static void registerBlock(RegistryEvent.Register<Block> event) {
event.getRegistry().register(ModObjects0.OAK_WOOD_WALL);
event.getRegistry().register(ModObjects0.DIORITE_BRICK_STAIRS);
event.getRegistry().register(ModObjects0.ANDESITE_BRICK_STAIRS);
event.getRegistry().register(ModObjects0.GRANITE_BRICK_SLABS);
event.getRegistry().register(ModObjects0.ANDESITE_BRICK_SLABS);
event.getRegistry().register(ModObjects0.DIORITE_BRICK_SLABS);
event.getRegistry().register(ModObjects0.OAK_WOOD_SLABS);
event.getRegistry().register(ModObjects0.OAK_WOOD_STAIRS);
event.getRegistry().register(ModObjects0.GRANITE_BRICK_STAIRS);
}
}
public class ModObjects0 {
...
public static final Block DIORITE_BRICK_SLABS = new SlabBlock(Block.Properties.from(StoneBricks.DIORITE_BRICKS)).setRegistryName("diorite_brick_slabs");
public static final Block OAK_WOOD_SLABS = new SlabBlock(Block.Properties.from(MoreBark.OAK_BARK)).setRegistryName("oak_wood_slabs");
public static final Block GRANITE_BRICK_SLABS = new SlabBlock(Block.Properties.from(StoneBricks.GRANITE_BRICKS)).setRegistryName("granite_brick_slabs");
public static final Block ANDESITE_BRICK_SLABS = new SlabBlock(Block.Properties.from(StoneBricks.ANDESITE_BRICKS)).setRegistryName("andesite_brick_slabs");
public static final Block DIORITE_BRICK_STAIRS = new HadronStairsBlock(StoneBricks.DIORITE_BRICKS.getDefaultState(), Block.Properties.from(StoneBricks.DIORITE_BRICKS)).setRegistryName("diorite_brick_stairs");
public static final Block OAK_WOOD_STAIRS = new HadronStairsBlock(MoreBark.OAK_BARK.getDefaultState(), Block.Properties.from(MoreBark.OAK_BARK)).setRegistryName("oak_wood_stairs");
public static final Block GRANITE_BRICK_STAIRS = new HadronStairsBlock(StoneBricks.GRANITE_BRICKS.getDefaultState(), Block.Properties.from(StoneBricks.GRANITE_BRICKS)).setRegistryName("granite_brick_stairs");
public static final Block ANDESITE_BRICK_STAIRS = new HadronStairsBlock(StoneBricks.ANDESITE_BRICKS.getDefaultState(), Block.Properties.from(StoneBricks.ANDESITE_BRICKS)).setRegistryName("andesite_brick_stairs");
public static final Block OAK_WOOD_WALL = new WallBlock(Block.Properties.from(MoreBark.OAK_BARK)).setRegistryName("oak_wood_wall");
}
public class HadronStairsBlock extends StairsBlock {
public HadronStairsBlock(BlockState state, Properties properties) {
super(state, properties);
}
}
It seems to me that my class is loaded at the wrong point in time (too late?), but I'm not sure if that's the issue or how to fix it.
Am I doing something wrong?