From 841c99148ec8f998bd6496bc1e95f954c49b8ac9 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Sat, 11 Dec 2021 11:00:57 +0100 Subject: [PATCH] Fix initial entity rotation getting lost (fixes #619) This fixes the rotation of already existing entities that just got sent to the client. Those get spawned with their rotation, which we didn't capture. This commit fixes that by initializing our tracked rotation to NaN and returning the original rotation until the tracked one is initialized (we do it this way rather than initializing during the spawn packet handling because there are many spawn packets, especially with modded, and we cannot possibly inject into all of them). This does not fix the rotation of newly placed entities (cause they seem to get spawned with 0/0 and then get teleported to their correct rotation). The previous commit fixed that case by capturing the rotation from the teleport packet. --- .../mixin/entity_tracking/Mixin_EntityExt.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/replaymod/replay/mixin/entity_tracking/Mixin_EntityExt.java b/src/main/java/com/replaymod/replay/mixin/entity_tracking/Mixin_EntityExt.java index 993e9c6e..7b5642eb 100644 --- a/src/main/java/com/replaymod/replay/mixin/entity_tracking/Mixin_EntityExt.java +++ b/src/main/java/com/replaymod/replay/mixin/entity_tracking/Mixin_EntityExt.java @@ -3,25 +3,32 @@ package com.replaymod.replay.mixin.entity_tracking; import com.replaymod.replay.ext.EntityExt; import net.minecraft.entity.Entity; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @Mixin(Entity.class) public abstract class Mixin_EntityExt implements EntityExt { - @Unique - private float trackedYaw; + @Shadow + public float yaw; + + @Shadow + public float pitch; @Unique - private float trackedPitch; + private float trackedYaw = Float.NaN; + + @Unique + private float trackedPitch = Float.NaN; @Override public float replaymod$getTrackedYaw() { - return this.trackedYaw; + return !Float.isNaN(this.trackedYaw) ? this.trackedYaw : this.yaw; } @Override public float replaymod$getTrackedPitch() { - return this.trackedPitch; + return !Float.isNaN(this.trackedPitch) ? this.trackedPitch : this.pitch; } @Override