snackbag / TT20

TT20 helps reduce lag by optimizing how ticks work when the server's TPS is low.
GNU Affero General Public License v3.0
28 stars 3 forks source link

SleepTimer advances when not sleeping #11

Open lexi-the-cute opened 1 month ago

lexi-the-cute commented 1 month ago

tt20-0.6.0+mc1.20.1.jar

2024-07-23_20 02 31

This causes problems with my datapacks for custom dimensions as I check the SleepTimer to determine when I need to reset the daylight cycle and weather cycle in custom dimensions

JXSnack commented 1 month ago

Oh, I see what's going on. I'm changing the value each time the variable is accessed. This also means that it will be changed when the player is not sleeping.

Minecraft's code: Minecraft's Code

My code:

@ModifyExpressionValue(method = "tick", at = @At(value = "FIELD", target = "Lnet/minecraft/entity/player/PlayerEntity;sleepTimer:I", opcode = Opcodes.GETFIELD))
private int tickTT20(int original) {
    if (!TT20.config.enabled() || !TT20.config.sleepingAcceleration()) return original;
    if (((Entity)(Object)this).getWorld().isClient()) return original;
    return original + TT20.TPS_CALCULATOR.applicableMissedTicks();
}

I'm unsure about how I can fix this so I'll leave this issue be for now. Will fix whenever I find a fix, I'm sorry :(