From cf9b3ddf221d7d900c48dd1c1822f31c58037c2b Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sun, 15 Jan 2023 18:50:23 +0100 Subject: [PATCH] Fix Entity position tracking --- .../src/de/steamwar/entity/REntityServer.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java index c8cf486..97ecc3a 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntityServer.java @@ -70,7 +70,7 @@ public class REntityServer implements Listener { } void addEntity(REntity entity) { - entities.computeIfAbsent(entityToId(entity), i -> new HashSet<>()).add(entity); + addEntityToChunk(entity); entity.spawn(packet -> updateEntity(entity, packet)); } @@ -81,6 +81,7 @@ public class REntityServer implements Listener { return; onMissing(players.get(fromId), players.get(toId), entity::despawn); + removeEntityFromChunk(entity); } void postEntityMove(REntity entity, double fromX, double fromZ) { @@ -89,6 +90,7 @@ public class REntityServer implements Listener { if(fromId == toId) return; + addEntityToChunk(entity); onMissing(players.get(toId), players.get(fromId), entity::spawn); } @@ -100,6 +102,14 @@ public class REntityServer implements Listener { void removeEntity(REntity entity) { entity.despawn(packet -> updateEntity(entity, packet)); + removeEntityFromChunk(entity); + } + + private void addEntityToChunk(REntity entity) { + entities.computeIfAbsent(entityToId(entity), i -> new HashSet<>()).add(entity); + } + + private void removeEntityFromChunk(REntity entity) { long id = entityToId(entity); HashSet entitiesInChunk = entities.get(id); entitiesInChunk.remove(entity);