PatchworkMC / patchwork-api

An attempt to reimplement the Minecraft Forge API on Fabric
GNU Lesser General Public License v2.1
282 stars 48 forks source link

Impl ServerTickEvent and RenderTickEvent #158

Closed GammaWhiskey closed 4 years ago

GammaWhiskey commented 4 years ago

Contained herein are my efforts to eliminate every TODO from the TickEvent class! A few things of note here:

    protected void tick(BooleanSupplier booleanSupplier) {
        long l = Util.getMeasuringTimeNano();
        // Forge fires here
        ++this.ticks;
        // Fabric API fires here
        this.tickWorlds(booleanSupplier);
        ...

If this is problematic, I could create a custom inject to match Forge. (This issue does not exist with Fabric API's END_SERVER_TICK, which I've also used, as both Forge and Fabric API fire their respective events at the very end of the method.)

kitlith commented 4 years ago

Ehhh. I wouldn't be too torn up if the profiler results were slightly thrown off.

However, you can inject to after a method call (and any variable assignment with the return value) with INVOKE_ASSIGN. Does that help?

GammaWhiskey commented 4 years ago

Ehhh. I wouldn't be too torn up if the profiler results were slightly thrown off.

However, you can inject to after a method call (and any variable assignment with the return value) with INVOKE_ASSIGN. Does that help?

I was under the impression that INVOKE_ASSIGN could only be used if the method returned a value, and DisableableProfiler.pop() returns void.

kitlith commented 4 years ago

https://jenkins.liteloader.com/view/Other/job/Mixin/javadoc/index.html?org/spongepowered/asm/mixin/injection/Inject.html says that it merely has special handling for invokes that return and immediately assign, not that it can only be used in that case.

Even if it couldn't be used, you could use 'shift' to shift the injection point to after the method call.

EDIT: apparently i copied the wrong link, I need to fix that.

GammaWhiskey commented 4 years ago

Huh. That seems to contradict the Mixin wiki:

Like BeforeInvoke, this injection point searches for invoke instructions within the target instruction list and returns instructions which match the criteria. However the method targetted must return a value.

Plus, whenever I set it to use INVOKE_ASSIGN, it fails. Either way, I can just shift the injection point, so I'll do that!

kitlith commented 4 years ago

Huh, I didn't see that. Fair enough!

rikka0w0 commented 4 years ago

if ++this.ticks; is not public, then implementing Forge's ServerTickEvent with Fabric API's START_SERVER_TICK should be fine. I don't think there are any mod uses tick as a timestamp or care about its state.

TheGlitch76 commented 4 years ago

At worst it could cause an off-by-one error, but having that cause a genuine issue is very unlikely.

TheGlitch76 commented 4 years ago

Thank you for the in-depth PR description by the way, it was very helpful!

GammaWhiskey commented 4 years ago

Thank you for the in-depth PR description by the way, it was very helpful!

I always aspire to be helpful. 👈😉👈