Jump to content

Event registration checks for correct bus


Recommended Posts



Perhaps it would be helpful to new modders if the Event handler registration would check that you have registered your event handler to the correct bus.  It is rather easy to get them confused (or be unaware that eg the FML has a different bus) and all you can tell is that your event is not called.



Link to comment
Share on other sites

Perhaps something like


public class MinecraftForge
     * The core Forge EventBusses, all events for Forge will be fired on these,
     * you should use this to register all your listeners.
     * This replaces every register*Handler() function in the old version of Forge.
     * TERRAIN_GEN_BUS for terrain gen events
     * ORE_GEN_BUS for ore gen events
     * EVENT_BUS for everything else
    public static final EventBus EVENT_BUS = new EventBus("EVENT_BUS");
    public static final EventBus TERRAIN_GEN_BUS = new EventBus("TERRAIN_GEN_BUS");
    public static final EventBus ORE_GEN_BUS = new EventBus("ORE_GEN_BUS");




public class EventBus
    private static int maxID = 0;
    private ConcurrentHashMap<Object, ArrayList<IEventListener>> listeners = new ConcurrentHashMap<Object, ArrayList<IEventListener>>();
    private final int busID = maxID++;
    private String busName;

    public EventBus(String init_busName)
        busName = init_busName;
        ListenerList.resize(busID + 1);
// ...

     private void register(Class<?> eventType, Object target, Method method)
            Constructor<?> ctr = eventType.getConstructor();
            Event event = (Event)ctr.newInstance();
            if (! event.whichBus().equals(busName)) {
                            throw new IllegalArgumentException(
                                "Method " + method + " has @ForgeSubscribe annotation, but is being registered on the wrong bus " +
                                "(" + busName + " instead of " + event.whichBus() + ")"
// ... etc ... 
        catch (Exception e)




public class Event

    private static ListenerList listeners = new ListenerList();
    public String whichBus() {return "";};
// ...

public class BlockEvent extends Event {
    public String whichBus() {return "EVENT_BUS";};

Link to comment
Share on other sites

But what if people want to fire our events on different busses?

Short answer is no, you just need to register your shit on the correct bus. It's REALLY easy to tell if you use the correct bus. Does your event fire when it should? No? Wrong bus.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

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.

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.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi I have an issue with a server it solved deleting the ice and fire but my friends and me really want to use it does any of these mods are causing the issue due to incompatibility  Security craft Aquaculture Architectury Artifacts Astikorcarts Baubles BetterCaves yungs BetterStrongholds yungs BetterMineshafts yungs Bountiful Byg  Callablehorses Carry on Chococraft Citadel Clumps Collective Comforts Corailrecycler Craftable horse armor Comes alive Curios forge Decocraft Dungeonsarise  Open blocks elevator Expandability Farlanders Goblin traders Hwyla  Ice and fire Infernal expansion Jei Jump over fences Mantle  Macaws bridges Macaws doors Macaws fences Macaws furniture  Macaws fencesbyg Morpheus Mouse tweaks Mowzies mobs Obfuscate Paraglider Patchouli  Pick up notifier Random village names Spartan shields Small ships Sophisticated backpacks Spartan weaponry Storage drawers straw golem Structure gel Twilight forest  Tinkers construct Two players one horse  Valhesia core  Valhesia structures  Way stones  Vehicle mod  Wall jump Wings Wolves with armor Xptome  Xaeros minimap  Yungsapi  
    • { "type": "magic_overhaul:rune_inscribing", "base": { "item": "//base item" }, "template": { "item": "//template item" }, "output": { "count": 1, "item": "//output item" } } ^ Ok, where is your recipe JSON placed in your file structure? What's it called? And paste the actual JSON you're testing with, because it needs to be valid.
    • I'm trying to run Forge 1.12.2 on Minecraft  so I can use certain mods, but this error popped up. I've seen multiple errors but I just can't figure this one out. Unable to locate the Java runtime. Error details: 0x00000000 - system: The operation completed successfully. Filename on disk:  Path: . Exists: Directory
    • https://mclo.gs/b422RFc
    • Плагин и Приват
  • Topics

  • Create New...

Important Information

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