From b87259f21bdf8e6e02bc629ffcb31995a46374c2 Mon Sep 17 00:00:00 2001 From: TheMode Date: Fri, 14 Jan 2022 21:34:20 +0100 Subject: [PATCH] properly update viewing references Signed-off-by: TheMode --- src/main/java/net/minestom/server/entity/Entity.java | 5 +++++ .../java/net/minestom/server/instance/EntityTracker.java | 2 ++ .../net/minestom/server/instance/EntityTrackerImpl.java | 8 ++++++++ 3 files changed, 15 insertions(+) diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index d270681e1..591becab8 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -126,6 +126,11 @@ public class Entity implements Viewable, Tickable, Schedulable, TagHandler, Perm public void remove(@NotNull Entity entity) { viewEngine.handleAutoViewRemoval(entity); } + + @Override + public void referenceUpdate(@NotNull Point point, @Nullable EntityTracker tracker) { + viewEngine.updateTracker(point, tracker); + } }; protected final ViewEngine viewEngine = new ViewEngine(this, diff --git a/src/main/java/net/minestom/server/instance/EntityTracker.java b/src/main/java/net/minestom/server/instance/EntityTracker.java index ed72cf7e3..ba805bacb 100644 --- a/src/main/java/net/minestom/server/instance/EntityTracker.java +++ b/src/main/java/net/minestom/server/instance/EntityTracker.java @@ -147,6 +147,8 @@ public sealed interface EntityTracker permits EntityTrackerImpl { void add(@NotNull E entity); void remove(@NotNull E entity); + + void referenceUpdate(@NotNull Point point, @Nullable EntityTracker tracker); } /** diff --git a/src/main/java/net/minestom/server/instance/EntityTrackerImpl.java b/src/main/java/net/minestom/server/instance/EntityTrackerImpl.java index 969e87704..e351929dd 100644 --- a/src/main/java/net/minestom/server/instance/EntityTrackerImpl.java +++ b/src/main/java/net/minestom/server/instance/EntityTrackerImpl.java @@ -44,6 +44,7 @@ final class EntityTrackerImpl implements EntityTracker { } } if (update != null) { + update.referenceUpdate(point, this); visibleEntities(point, target, newEntity -> { if (newEntity == entity) return; update.add(newEntity); @@ -64,6 +65,7 @@ final class EntityTrackerImpl implements EntityTracker { } } if (update != null) { + update.referenceUpdate(point, null); visibleEntities(point, target, update::remove); } } @@ -92,7 +94,13 @@ final class EntityTrackerImpl implements EntityTracker { public void remove(@NotNull T removed) { if (entity != removed) update.remove(removed); } + + @Override + public void referenceUpdate(@NotNull Point point, @Nullable EntityTracker tracker) { + // Empty + } }); + update.referenceUpdate(newPoint, this); } }