-
-
Notifications
You must be signed in to change notification settings - Fork 0
Experiment with fully integrating EventBus 7 into Forge #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 1.21.x
Are you sure you want to change the base?
Conversation
Yup. A lot is going to need to be cleaned up in order for us to play with our new legos. Do what you are able to for now, while I do my best to try and get FG7 underway. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall it looks fine, bulk of the changes being adding the bus to each event.
need to go through and migrate as many things off the mod bus as possible for simplicities sake.
should be simple enough to gather a list of events and throw exception if wrong bus.
aside from that a few comments.
tons of your todos to finish
would it also be possible to have a
public Helper extends EventBusGroup {
register(class) {
wrapped.register(getLookup(class), class)
}
}
namely a wrapper with helprr functions doing stuff you dont want in the official event bus api, but i want exposed to modders to make their lives easier.
@@ -29,7 +28,9 @@ | |||
* The event is fired on each reload and lets modders add their own ReloadListeners, for server-side resources. | |||
* The event is fired on the {@link MinecraftForge#EVENT_BUS} | |||
*/ | |||
public class AddReloadListenerEvent extends Event { | |||
public class AddReloadListenerEvent extends MutableEvent { | |||
public static final EventBus<AddReloadListenerEvent> BUS = EventBus.create(AddReloadListenerEvent.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do these need MutableEvent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They don't, but you asked for no record events at first :P
Changing them would be trivial, I left it because the PoC already showcased the feature-set and I wanted to focus more on the integration side of things/getting it booting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean why is it using MutableEvent instead of just Event? I thought that was only needed for monitor aware things. I'm still not solid on the name/use of MutableEvent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple reasons, should be clear from the javadocs once @Jonathing gets around to it. I've left a couple of explainer comments here and here
@@ -21,8 +21,9 @@ | |||
* Please note that as this is fired for ALL object creations efficient code is recommended. | |||
* And if possible use one of the sub-classes to filter your intended objects. | |||
*/ | |||
public class AttachCapabilitiesEvent<T> extends GenericEvent<T> | |||
{ | |||
public class AttachCapabilitiesEvent<T> extends MutableEvent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only sane way for now is to make this abstract and have the concrete subclasses for each "generic" we have
@@ -108,7 +109,7 @@ public static boolean completeModLoading() { | |||
File dumpedLocation = null; | |||
if (error == null) { | |||
// We can finally start the forge eventbus up | |||
MinecraftForge.EVENT_BUS.start(); | |||
BusGroup.DEFAULT.startup(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should spend the time to move as many of the mod bus events to the default bus, and instead of starting the bus here. we disable it in the error handler. as the point is trying to get minecraft into a state where we can show a friendly error without mod event handlers erroring it out. it got polluted because a lot of vanilla code gets called, and thus events need to fire, before this handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that we should move more events away from the mod bus. Some stuff is on there and doesn't really need to be, but some is there either because it's mod-specific (e.g. ConfigEvent only firing for configs your mod registered) or for parallel mod loading.
The whole 'try to stop mod loading but continue loading the game to show an in-game error screen' idea doesn't seem to work well enough in practice as some mods may have already loaded enough to start doing things and end up crashing the game before the error screen is showed.
These things are wider issues with FML in general that I'd like to tackle in the rewrite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes overall things need to be handled in the re-write.
If we want to hold off on moving the events between busses until then, we can keep this as disabled.
But I would like to see some debug logger that prints out what events are fired before the bus is started.
Something so we can have a concrete list of things that need moving.
/** | ||
* The EventBus for all the Forge Events. | ||
* | ||
* Events marked with {@link net.minecraftforge.fml.event.IModBusEvent} | ||
* belong on the ModBus and not this bus | ||
*/ | ||
public static final IEventBus EVENT_BUS = BusBuilder.builder().startShutdown().useModLauncher().build(); | ||
@Deprecated(forRemoval = true, since = "1.21.5") | ||
public static final BusGroup EVENT_BUS = BusGroup.DEFAULT;// BusBuilder.builder().startShutdown().useModLauncher().build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we should deprecate this, instead we should make a wrapper that has helpers like not needing to pass in the module lookup, event type, and the link.
@@ -0,0 +1,10 @@ | |||
package net.minecraftforge.common.util; | |||
|
|||
// Temporary solution for events that rely on the cancellation state being stored inside the event object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal get vs external set? or perhaps turn this into a record <T> Result(boolean canceled, T event){}
?
useItem = Result.DENY; | ||
} | ||
} | ||
// Todo: [Forge][Event] PlayerInteractEvent.RightClickBlock#setCanceled(boolean) override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think for these we just need to have this propogation on the event factory side
@@ -102,4 +101,8 @@ boolean isRemotePresent(Connection con) { | |||
var channels = NetworkContext.get(con).getRemoteChannels(); | |||
return channels.containsAll(ids); | |||
} | |||
|
|||
public BusGroup getNetworkEventBusGroup() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the point is to hide this event stuff from modders. honestly killing off all event style networking would probable be better then trying to migrate it
Made all subclasses package-private too.
And fixed commands...
Signed-off-by: RealMangoRage <[email protected]>
Signed-off-by: RealMangoRage <[email protected]>
Signed-off-by: RealMangoRage <[email protected]>
Supersedes MinecraftForge#10495.
Unlike the PoC PR, this tries to get it compiling and booting, without taking full advantage of the new features.
My observations from this experiment:
getClass()
on itThread-safety issues, sometimes requires multiple attempts to successfully bootfire()
, checkisCanceled()
and may read other parts of the event object even when cancelled. The separation of cancellation state means that you need to hold the object, post(), then conditionally return null for some events, and longer patches for other eventssetCanceled()
inside certain unrelated methods or set a custom cancellation state before the event is postedRenderHighlightEvent.Entity
seems to have an oversight where it's not intentionally cancellable but inherits cancellable from the superclassRenderLivingEvent
involves instance generics that aren't accessible from a static final context. Not sure how to solve thisThis compiles and boots, but fails to load into a world due to the networking internals not being fully ported over yet.