From 8ff9354c04a7a15ae5d4c85b76ad4b83b7d63b93 Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Sun, 27 Oct 2024 17:21:10 +0100 Subject: [PATCH] Revert previous behaviour in entity and respawn packets in <= 1.21.1 - EntityPositionPacket's now fallback to the player if it was sent for a vehicle which got removed - onPlayerRespawn now restores player rotation and velocity if KEEP_TRACKED_DATA is set --- .../MixinClientPlayNetworkHandler.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinClientPlayNetworkHandler.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinClientPlayNetworkHandler.java index d12bb99c..7055cb7e 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinClientPlayNetworkHandler.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinClientPlayNetworkHandler.java @@ -34,6 +34,7 @@ import net.minecraft.client.gui.screen.ingame.BookScreen; import net.minecraft.client.network.*; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.Entity; +import net.minecraft.entity.TrackedPosition; import net.minecraft.entity.attribute.AttributeContainer; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.vehicle.AbstractBoatEntity; @@ -47,6 +48,7 @@ import net.minecraft.network.packet.c2s.play.ChatCommandSignedC2SPacket; import net.minecraft.network.packet.c2s.play.ClientStatusC2SPacket; import net.minecraft.network.packet.s2c.play.*; import net.minecraft.registry.RegistryKey; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.GameMode; import net.minecraft.world.World; import net.raphimc.viabedrock.api.BedrockProtocolVersion; @@ -61,6 +63,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import java.time.Instant; import java.util.LinkedHashSet; import java.util.List; +import java.util.OptionalInt; import java.util.Set; @Mixin(ClientPlayNetworkHandler.class) @@ -87,6 +90,23 @@ public abstract class MixinClientPlayNetworkHandler extends ClientCommonNetworkH super(client, connection, connectionState); } + @Redirect(method = "onEntityPosition", at = @At(value = "INVOKE", target = "Ljava/util/OptionalInt;isPresent()Z")) + private boolean dontHandleRemovedVehiclePositionChange(OptionalInt instance) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_1)) { + return false; + } else { + return instance.isPresent(); + } + } + + @Inject(method = "onPlayerRespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/world/ClientWorld;addEntity(Lnet/minecraft/entity/Entity;)V", shift = At.Shift.BEFORE)) + private void dontApplyRotationAndVelocity(PlayerRespawnS2CPacket packet, CallbackInfo ci, @Local(ordinal = 1) ClientPlayerEntity clientPlayerEntity) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_1)) { + clientPlayerEntity.init(); + clientPlayerEntity.setYaw(-180.0F); + } + } + @WrapWithCondition(method = "onPlayerRespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/attribute/AttributeContainer;setBaseFrom(Lnet/minecraft/entity/attribute/AttributeContainer;)V")) private boolean dontApplyBaseValues(AttributeContainer instance, AttributeContainer other) { return ProtocolTranslator.getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_21);