From e05c585b374a3f41c7d009e656c0904a38f9e8c3 Mon Sep 17 00:00:00 2001 From: kennytv Date: Wed, 11 Aug 2021 08:55:42 +0200 Subject: [PATCH] Fix 1.14 position tracking of client Fixes #391 --- .../storage/EntityPositionHandler.java | 15 ++++++++++----- .../api/rewriters/EntityRewriterBase.java | 18 +++++++++--------- .../packets/EntityPackets1_14.java | 6 ++++++ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityPositionHandler.java b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityPositionHandler.java index c309905e..a7c0b150 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityPositionHandler.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/entities/storage/EntityPositionHandler.java @@ -63,14 +63,19 @@ public class EntityPositionHandler { return; } - EntityPositionStorage positionStorage = create ? storageSupplier.get() : storedEntity.get(storageClass); - if (positionStorage == null) { - ViaBackwards.getPlatform().getLogger().warning("Stored entity with id " + entityId + " missing " + storageClass.getSimpleName()); - return; + EntityPositionStorage positionStorage; + if (create) { + positionStorage = storageSupplier.get(); + storedEntity.put(positionStorage); + } else { + positionStorage = storedEntity.get(storageClass); + if (positionStorage == null) { + ViaBackwards.getPlatform().getLogger().warning("Stored entity with id " + entityId + " missing " + storageClass.getSimpleName()); + return; + } } positionStorage.setCoordinates(x, y, z, relative); - storedEntity.put(positionStorage); } public EntityPositionStorage getStorage(UserConnection user, int entityId) { diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java index 4ff9fa72..382e5f26 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/EntityRewriterBase.java @@ -65,7 +65,9 @@ public abstract class EntityRewriterBase extends En @Override public void handleMetadata(int entityId, List metadataList, UserConnection connection) { EntityType type = tracker(connection).entityType(entityId); - if (type == null) return; // Don't handle untracked entities - basically always the fault of a plugin sending virtual entities through concurrency-unsafe handling + if (type == null) { + return; // Don't handle untracked entities - basically always the fault of a plugin sending virtual entities through concurrency-unsafe handling + } super.handleMetadata(entityId, metadataList, connection); @@ -84,11 +86,9 @@ public abstract class EntityRewriterBase extends En } // Add any other extra meta for mapped entities - if (entityData != null) { - //TODO only do this once for a first meta packet? - if (entityData != null && entityData.hasBaseMeta()) { - entityData.defaultMeta().createMeta(new WrappedMetadata(metadataList)); - } + //TODO only do this once for a first meta packet? + if (entityData != null && entityData.hasBaseMeta()) { + entityData.defaultMeta().createMeta(new WrappedMetadata(metadataList)); } } @@ -180,9 +180,9 @@ public abstract class EntityRewriterBase extends En } // ONLY TRACKS, DOESN'T REWRITE IDS - protected PacketHandler getTrackerHandler(Type intType, int typeIndex) { + protected PacketHandler getTrackerHandler(Type intType, int typeIndex) { return wrapper -> { - Number id = (Number) wrapper.get(intType, typeIndex); + Number id = wrapper.get(intType, typeIndex); tracker(wrapper.user()).addEntity(wrapper.get(Type.VAR_INT, 0), typeFromId(id.intValue())); }; } @@ -191,7 +191,7 @@ public abstract class EntityRewriterBase extends En return getTrackerHandler(Type.VAR_INT, 1); } - protected PacketHandler getTrackerHandler(EntityType entityType, Type intType) { + protected PacketHandler getTrackerHandler(EntityType entityType, Type intType) { return wrapper -> tracker(wrapper.user()).addEntity((int) wrapper.get(intType, 0), entityType); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java index 81bea8ac..ee58baeb 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java @@ -25,6 +25,7 @@ import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2T import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage; import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14; import com.viaversion.viaversion.api.data.entity.EntityTracker; +import com.viaversion.viaversion.api.data.entity.StoredEntityData; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.VillagerData; import com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types; @@ -318,6 +319,11 @@ public class EntityPackets1_14 extends LegacyEntityRewriter