Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

 

  • 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.

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.

  • 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 by NorthWestWind

  • 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.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.