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

Hi

 

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.

 

-TGG

  • Author

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

 

and

 

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)
    {
        try
        {
            Constructor<?> ctr = eventType.getConstructor();
            ctr.setAccessible(true);
            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)
        {
            e.printStackTrace();
        }
    }

 

and

 

public class Event
{

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

public class BlockEvent extends Event {
//...
    @Override
    public String whichBus() {return "EVENT_BUS";};
//...
}

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

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.