Jump to content

[1.16.1] Block Registry Event Not Firing


NorthWestWind

Recommended Posts

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");
    }
}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by NorthWestWind
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.