From d8b36666d55a17e163ad3759f5bebb75029c1ade Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Sun, 29 Oct 2023 02:29:19 +0200 Subject: [PATCH] Cleaned entity tracker code --- .../viarewind/api/rewriter/ReplacementEntityTracker.java | 6 +----- .../protocol1_7_6_10to1_8/packets/PlayerPackets.java | 2 +- .../storage/EntityTracker1_7_6_10.java | 9 ++------- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/com/viaversion/viarewind/api/rewriter/ReplacementEntityTracker.java b/common/src/main/java/com/viaversion/viarewind/api/rewriter/ReplacementEntityTracker.java index 9559baf3d..0274a65ea 100644 --- a/common/src/main/java/com/viaversion/viarewind/api/rewriter/ReplacementEntityTracker.java +++ b/common/src/main/java/com/viaversion/viarewind/api/rewriter/ReplacementEntityTracker.java @@ -57,17 +57,13 @@ public boolean isReplaced(final EntityTypes1_10.EntityType type) { return ENTITY_REPLACEMENTS.containsKey(type); } - public void updateMetadata(final int entityId, final List metadata) { + public void updateMetadata(final int entityId, final List metadata) throws Exception { final String name = ENTITY_REPLACEMENTS.get(entityMap.get(entityId)).value(); metadata.add(new Metadata(MetaIndex1_7_6_10To1_8.ENTITY_LIVING_NAME_TAG_VISIBILITY.getNewIndex(), MetaType1_7_6_10.Byte, (byte) 1)); // TODO: Make this definable for 1.8 -> 1.9 ? metadata.add(new Metadata(MetaIndex1_7_6_10To1_8.ENTITY_LIVING_NAME_TAG.getNewIndex(), MetaType1_7_6_10.String, name)); } - public void setPlayerId(int playerId) { - this.playerId = playerId; - } - @Override public void setClientEntityId(int entityId) { removeEntity(this.playerId); diff --git a/common/src/main/java/com/viaversion/viarewind/protocol/protocol1_7_6_10to1_8/packets/PlayerPackets.java b/common/src/main/java/com/viaversion/viarewind/protocol/protocol1_7_6_10to1_8/packets/PlayerPackets.java index cfcc8ffcf..aa5f5e6bc 100644 --- a/common/src/main/java/com/viaversion/viarewind/protocol/protocol1_7_6_10to1_8/packets/PlayerPackets.java +++ b/common/src/main/java/com/viaversion/viarewind/protocol/protocol1_7_6_10to1_8/packets/PlayerPackets.java @@ -72,7 +72,7 @@ public void register() { } final EntityTracker1_7_6_10 tracker = wrapper.user().get(EntityTracker1_7_6_10.class); - tracker.setPlayerId(wrapper.get(Type.INT, 0)); + tracker.setClientEntityId(wrapper.get(Type.INT, 0)); tracker.addPlayer(wrapper.get(Type.INT, 0), wrapper.user().getProtocolInfo().getUuid()); wrapper.user().get(PlayerSessionStorage.class).gameMode = wrapper.get(Type.UNSIGNED_BYTE, 0); diff --git a/common/src/main/java/com/viaversion/viarewind/protocol/protocol1_7_6_10to1_8/storage/EntityTracker1_7_6_10.java b/common/src/main/java/com/viaversion/viarewind/protocol/protocol1_7_6_10to1_8/storage/EntityTracker1_7_6_10.java index d90808f66..f994e721b 100644 --- a/common/src/main/java/com/viaversion/viarewind/protocol/protocol1_7_6_10to1_8/storage/EntityTracker1_7_6_10.java +++ b/common/src/main/java/com/viaversion/viarewind/protocol/protocol1_7_6_10to1_8/storage/EntityTracker1_7_6_10.java @@ -50,7 +50,7 @@ public void trackHologram(final int entityId, final VirtualHologramEntity hologr } @Override - public void updateMetadata(int entityId, List metadata) { + public void updateMetadata(int entityId, List metadata) throws Exception { if (virtualHologramMap.containsKey(entityId)) { virtualHologramMap.get(entityId).updateMetadata(metadata); return; @@ -86,12 +86,6 @@ public void setClientEntityId(int entityId) { super.setClientEntityId(entityId); } - @Override - public void setPlayerId(int playerId) { - super.setPlayerId(playerId); - this.spectatingPlayerId = playerId; - } - public void addPlayer(final Integer entityId, final UUID uuid) { playersByUniqueId.put(uuid, entityId); playersByEntityId.put(entityId, uuid); @@ -134,6 +128,7 @@ protected void startSneaking() { public void setPassenger(int vehicleId, int passengerId) { if (vehicleId == this.spectatingPlayerId && this.spectatingPlayerId != this.getPlayerId()) { startSneaking(); + setSpectating(this.getPlayerId()); } if (vehicleId == -1) {