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
This commit is contained in:
FlorianMichael 2024-10-27 17:21:10 +01:00
parent 9f5f6e8421
commit 8ff9354c04
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126

View File

@ -34,6 +34,7 @@ import net.minecraft.client.gui.screen.ingame.BookScreen;
import net.minecraft.client.network.*; import net.minecraft.client.network.*;
import net.minecraft.client.world.ClientWorld; import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.TrackedPosition;
import net.minecraft.entity.attribute.AttributeContainer; import net.minecraft.entity.attribute.AttributeContainer;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.vehicle.AbstractBoatEntity; 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.c2s.play.ClientStatusC2SPacket;
import net.minecraft.network.packet.s2c.play.*; import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKey;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.GameMode; import net.minecraft.world.GameMode;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.raphimc.viabedrock.api.BedrockProtocolVersion; import net.raphimc.viabedrock.api.BedrockProtocolVersion;
@ -61,6 +63,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.time.Instant; import java.time.Instant;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.OptionalInt;
import java.util.Set; import java.util.Set;
@Mixin(ClientPlayNetworkHandler.class) @Mixin(ClientPlayNetworkHandler.class)
@ -87,6 +90,23 @@ public abstract class MixinClientPlayNetworkHandler extends ClientCommonNetworkH
super(client, connection, connectionState); 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")) @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) { private boolean dontApplyBaseValues(AttributeContainer instance, AttributeContainer other) {
return ProtocolTranslator.getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_21); return ProtocolTranslator.getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_21);