Replies: 8 comments 3 replies
-
Sounds and looks great so far |
Beta Was this translation helpful? Give feedback.
-
I expects MinecraftForge.EVENT_BUS.addListener( (Consumer<RegistryEvent.Register<Item>>) (evt -> {...} ) ) |
Beta Was this translation helpful? Give feedback.
-
The syntax seems good enough. Events.register(CustomEvent.class, customEvent -> { }); For generics, the equivalent would be: Events.register(CustomGenericEvent.class, GenericType.class, customGenericEvent -> { }); I think we should still allow an annotation-based way of registering, similar to Forge's, but perhaps with I do believe there is still overhead to be optimized when actually publishing (firing) the events. Such as the listener should not be checking if itself is a generic event listener, etc. |
Beta Was this translation helpful? Give feedback.
-
@Ametsuchiru waiting on your benchmarks, I need some numbers, preferably with comparison to Forge's current ASM system. |
Beta Was this translation helpful? Give feedback.
-
In neoforge,they have a checker for event listener |
Beta Was this translation helpful? Give feedback.
-
As I mentioned before in Discord, I hope ModBus (
To maintain compatibility, ModBus extends the original Now, mod bus uses reflection driver and constructs a bus for each mod to implement I wonder if we should start now and make some related attempts or stopgap measures. |
Beta Was this translation helpful? Give feedback.
-
I'm curious if this API is worth it. Most mods don't use lambda directly, but build a method and then reference it (
In summary, supporting lambda has no visible benefits and will bring visible disadvantages. We can't support lambda just for the sake of supporting it - as a Java feature. If we support it just for the sake of supporting it, we can also try to support the new |
Beta Was this translation helpful? Give feedback.
-
We can try introducing ListenerToken to implement generics and unregister. var token = BUS.addListener(new ListenerToken<AttachCapabilityEvent<ItemStack>>(event ->...){});
token.unregister(); Works like TypeToken. |
Beta Was this translation helpful? Give feedback.
-
Summary
Maintain compatibility with current event system that Forge provides, and to enhance upon it in both performance and cleanliness.
Goals
EventBus
(thus merging current TERRAIN_GEN/ORE_GEN event buses).Non Goals
IGenericEvent
, as they are abundant in functionality and uses.Motivation
Events have always been a bikeshedding topic, even more so now. Thus, it is perfect to take all the good talking points from modern Fabric and Forge and attempt to establish a clean approach for Cleanroom's events.
As well as that, Forge's event system have always suffered from annotation magic and the unclear nature of how it was being registered. Developers would see no errors when registering their event classes but finding out the listeners were inactive. It is time to clear the confusion and to modernize the system while keeping overheads low.
Description
Events right now work as such, and we can see that there are two different ways of registering events and how they differ vastly.
@Subscribe
forFMLEvents
@SubscribeEvent
forEvents
This should be united, there is no reason of separating these. As well as the different
EventBus
types:MinecraftForge.EVENT_BUS
MinecraftForge.ORE_GEN_BUS
MinecraftForge.TERRAIN_GEN_BUS
... should also be united. The configuration can differ from one
Event
to anotherEvent
instead.Registration of events should be revamped as well, away from being annotation-based. With using modern lambda syntax such as:
With using lambdas like this, using ASM to create event listener classes internally would also no longer be required, as the event should call this lambda like its a callback (it essentially is). However, what if we have a lot of listeners to register, registering it one-by-one could be troublesome also. Hence we still use the old method of
EventBus#register(Class)
, and we essentially re-route each method to theEvent#register
method, but instead of as a lambda, we could utilize the invocation API's MethodHandle, with near if not native call speeds with some penalty in bootstrapping.[Unfinished Post]
Dependencies
No response
References
No response
Guidelines
Beta Was this translation helpful? Give feedback.
All reactions