Posted December 30, 20204 yr Hello there. I was just coding my mod and I tried to use `RegistryEvent.Register<Block>` to register my block, but the event doesn't fire. Other events can be fired though. In my case, `FMLCommonSetupEvent` fired just as normal as it should be. Here is my code: @Mod(Musician.MOD_ID) public class Musician { public static Musician INSTANCE; public static final String MOD_ID = "musician"; public Musician() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); MinecraftForge.EVENT_BUS.register(this); INSTANCE = this; } @SubscribeEvent public void setup(final FMLCommonSetupEvent event) { LogManager.getLogger().info("Hello from common setup"); } public static final Block NOTE_BLOCK = new MoreNoteBlock().setRegistryName("note_block"); @SubscribeEvent public void registerBlocks(final RegistryEvent.Register<Block> event) { event.getRegistry().register(NOTE_BLOCK); Item.BLOCK_TO_ITEM.put(NOTE_BLOCK, Blocks.NOTE_BLOCK.asItem()); LogManager.getLogger().info("Registered Custom Note Block"); } }
December 30, 20204 yr There a few things wrong with code style here. You are trying to execute the registry event on the forge bus and the common setup on both buses. You might want to review events and figure out how to fix this issue.
December 30, 20204 yr Author I took a look at the events and tested them. Method 1 doesn't work: @Mod(Musician.MOD_ID) public class Musician { public static Musician INSTANCE; public static final String MOD_ID = "musician"; public Musician() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); INSTANCE = this; } @SubscribeEvent public void setup(final FMLCommonSetupEvent event) { LogManager.getLogger().info("Hello from common setup"); } } @Mod.EventBusSubscriber(modid = Musician.MOD_ID) class RegistryHandler { public static final Block NOTE_BLOCK = new MoreNoteBlock().setRegistryName("note_block"); @SubscribeEvent public static void registerBlocks(final RegistryEvent.Register<Block> event) { event.getRegistry().register(NOTE_BLOCK); Item.BLOCK_TO_ITEM.put(NOTE_BLOCK, Blocks.NOTE_BLOCK.asItem()); LogManager.getLogger().info("Registered Custom Note Block"); } } So does method 2: @Mod(Musician.MOD_ID) public class Musician { public static Musician INSTANCE; public static final String MOD_ID = "musician"; public Musician() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); MinecraftForge.EVENT_BUS.register(RegistryHandler.class); INSTANCE = this; } @SubscribeEvent public void setup(final FMLCommonSetupEvent event) { LogManager.getLogger().info("Hello from common setup"); } } class RegistryHandler { public static final Block NOTE_BLOCK = new MoreNoteBlock().setRegistryName("note_block"); @SubscribeEvent public static void registerBlocks(final RegistryEvent.Register<Block> event) { event.getRegistry().register(NOTE_BLOCK); Item.BLOCK_TO_ITEM.put(NOTE_BLOCK, Blocks.NOTE_BLOCK.asItem()); LogManager.getLogger().info("Registered Custom Note Block"); } } Method 3 also: @Mod(Musician.MOD_ID) public class Musician { public static Musician INSTANCE; public static final String MOD_ID = "musician"; public Musician() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); MinecraftForge.EVENT_BUS.register(new RegistryHandler()); INSTANCE = this; } @SubscribeEvent public void setup(final FMLCommonSetupEvent event) { LogManager.getLogger().info("Hello from common setup"); } } class RegistryHandler { public static final Block NOTE_BLOCK = new MoreNoteBlock().setRegistryName("note_block"); @SubscribeEvent public void registerBlocks(final RegistryEvent.Register<Block> event) { event.getRegistry().register(NOTE_BLOCK); Item.BLOCK_TO_ITEM.put(NOTE_BLOCK, Blocks.NOTE_BLOCK.asItem()); LogManager.getLogger().info("Registered Custom Note Block"); } } The 4th method still doesn't work: @Mod(Musician.MOD_ID) public class Musician { public static Musician INSTANCE; public static final String MOD_ID = "musician"; public Musician() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); MinecraftForge.EVENT_BUS.addListener(this::registerBlocks); INSTANCE = this; } @SubscribeEvent public void setup(final FMLCommonSetupEvent event) { LogManager.getLogger().info("Hello from common setup"); } public static final Block NOTE_BLOCK = new MoreNoteBlock().setRegistryName("note_block"); public void registerBlocks(final RegistryEvent.Register<Block> event) { event.getRegistry().register(NOTE_BLOCK); Item.BLOCK_TO_ITEM.put(NOTE_BLOCK, Blocks.NOTE_BLOCK.asItem()); LogManager.getLogger().info("Registered Custom Note Block"); } } Method 5 also failed: @Mod(Musician.MOD_ID) public class Musician { public static Musician INSTANCE; public static final String MOD_ID = "musician"; public Musician() { FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); MinecraftForge.EVENT_BUS.addGenericListener(Block.class, this::registerBlocks); INSTANCE = this; } @SubscribeEvent public void setup(final FMLCommonSetupEvent event) { LogManager.getLogger().info("Hello from common setup"); } public static final Block NOTE_BLOCK = new MoreNoteBlock().setRegistryName("note_block"); @SubscribeEvent public void registerBlocks(final RegistryEvent.Register<Block> event) { event.getRegistry().register(NOTE_BLOCK); Item.BLOCK_TO_ITEM.put(NOTE_BLOCK, Blocks.NOTE_BLOCK.asItem()); LogManager.getLogger().info("Registered Custom Note Block"); } } Now I'm really confused.
December 30, 20204 yr Method 1: annotation on common setup does nothing, registry event still on forge bus Method 2: same as method 1 Method 3: same as above Method 4: crash on startup Method 5: same as method 1 Essentially, you did the same thing over and over. You read the resources but ignored my comment.
December 30, 20204 yr Author Ok I just went back and tried all of them again without the lines FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); and @SubscribeEvent public void setup(final FMLCommonSetupEvent event) { LogManager.getLogger().info("Hello from common setup"); } And I still can register my block Edited December 30, 20204 yr by NorthWestWind
December 30, 20204 yr Author Alright, I clearly misunderstood everything. I just swapped `MinecraftForge.EVENT_BUS` with `FMLJavaModLoadingContext.get().getModEventBus()` and then everything works again. Sorry for being dumb.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.