-
-
Notifications
You must be signed in to change notification settings - Fork 172
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
[1.20.5] Refactor tick events into distinct subclasses #542
[1.20.5] Refactor tick events into distinct subclasses #542
Conversation
Last commit published: 7dc32e7b3961b3c4ae1224486bd1f49f02646863. PR PublishingThe artifacts published by this PR:
Repository DeclarationIn order to use the artifacts published by the PR, add the following repository to your buildscript: repositories {
maven {
name 'Maven for PR #542' // https://github.com/neoforged/NeoForge/pull/542
url 'https://prmaven.neoforged.net/NeoForge/pr542'
content {
includeModule('net.neoforged', 'neoforge')
includeModule('net.neoforged', 'testframework')
}
}
} MDK installationIn order to setup a MDK using the latest PR version, run the following commands in a terminal. mkdir NeoForge-pr542
cd NeoForge-pr542
curl -L https://prmaven.neoforged.net/NeoForge/pr542/net/neoforged/neoforge/20.5.19-beta-pr-542-tick-event-refactor/mdk-pr542.zip -o mdk.zip
jar xf mdk.zip
rm mdk.zip || del mdk.zip To test a production environment, you can download the installer from here. |
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.
Small tiny suggestion.
src/main/java/net/neoforged/neoforge/capabilities/CapabilityHooks.java
Outdated
Show resolved
Hide resolved
tests/src/main/java/net/neoforged/neoforge/oldtest/entity/GravityAttributeTest.java
Outdated
Show resolved
Hide resolved
src/main/java/net/neoforged/neoforge/client/event/RenderFrameEvent.java
Outdated
Show resolved
Hide resolved
src/main/java/net/neoforged/neoforge/event/tick/ClientTickEvent.java
Outdated
Show resolved
Hide resolved
Maybe split LevelTick into client & server variants? Would get rid of the unused Also maybe include the |
@Fuzss I thought about that, however many methods are already called on both client and server side, so modders should be used to handling both cases in common paths. It is also quite easy to check with an Regarding |
please prepare a blogpost and the text for an announcement since this is a rather big breaking change |
Do we want to keep this for 1.20.5? (IMO yes) |
Don't really see a reason to hold it back myself; it's a fairly trivial refactor in comparison to everything else we've done. |
It's more a question of timing for me - we tried to do the most impactful refactors as soon as possible. This is coming a bit late and will require many people to release another version of their mods. |
285f54a
to
41f2cf6
Compare
Updated to account for |
7b1546f
to
1f0b919
Compare
Rebased and re-targeted to |
10aae6d
to
b1c5f05
Compare
src/main/java/net/neoforged/neoforge/event/tick/LivingTickEvent.java
Outdated
Show resolved
Hide resolved
src/main/java/net/neoforged/neoforge/event/tick/LivingTickEvent.java
Outdated
Show resolved
Hide resolved
Since this PR now also touches upon Firing at the head of Even more subclasses run code after calling super, which the new Why not move the event hooks to the call sites of
It's unlikely for modders to call |
Also moving the hooks for both |
Looking into moving it. Potentially also dropping |
Ah yes, expanding the event to Maybe revert the current |
b1c5f05
to
d8853c5
Compare
Updated to remove |
Yeah Just a bit weird at the moment, since |
9144197
to
34fe790
Compare
34fe790
to
5366b25
Compare
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.
Looks very nice.
What
This PR refactors
TickEvent
and all child classes into individual abstract classes with Pre/Post subclasses. The number of events being fired and the timing of the events is unchanged, but the notion of one event that fires twice per tick has been removed, and the events have been moved out of a single file.Additionally, all the events have been documented.
The list of changes is:
TickEvent.ServerTickEvent
->ServerTickEvent.Pre/Post
TickEvent.ClientTickEvent
->ClientTickEvent.Pre/Post
TickEvent.LevelTickEvent
->LevelTickEvent.Pre/Post
TickEvent.PlayerTickEvent
->PlayerTickEvent.Pre/Post
TickEvent.RenderTickEvent
->RenderFrameEvent.Pre/Post
(naming changed here as this is unrelated to ticks).LivingEvent.LivingTickEvent
->EntityTickEvent.Pre/Post
(Pre retains the cancellable nature of the original event) [expanded to all entities].Why
These events are more than a decade old, have no documentation, and easily confuse users. On numerous occasions have I had to inform users that all tick events fire twice per tick.
I could simply document this in the classes, but this would not remedy the issue that all information in the base class
TickEvent
is redundant, with the exception ofTickEvent#phase
(which is just confusing).Instead, this refactor makes it obvious what event you are subscribing to and when it will fire, entirely removing the possibility that work is erroneously performed twice per tick.
There even exists a bug in one of the legacy tests where we are running a tick handler twice per tick due to not checking
TickEvent#phase
:NeoForge/tests/src/main/java/net/neoforged/neoforge/oldtest/entity/GravityAttributeTest.java
Lines 63 to 70 in 34f85e1