properly update viewing references

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-01-14 21:34:20 +01:00
parent 6e6da5df06
commit b87259f21b
3 changed files with 15 additions and 0 deletions

View File

@ -126,6 +126,11 @@ public class Entity implements Viewable, Tickable, Schedulable, TagHandler, Perm
public void remove(@NotNull Entity entity) { public void remove(@NotNull Entity entity) {
viewEngine.handleAutoViewRemoval(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, protected final ViewEngine viewEngine = new ViewEngine(this,

View File

@ -147,6 +147,8 @@ public sealed interface EntityTracker permits EntityTrackerImpl {
void add(@NotNull E entity); void add(@NotNull E entity);
void remove(@NotNull E entity); void remove(@NotNull E entity);
void referenceUpdate(@NotNull Point point, @Nullable EntityTracker tracker);
} }
/** /**

View File

@ -44,6 +44,7 @@ final class EntityTrackerImpl implements EntityTracker {
} }
} }
if (update != null) { if (update != null) {
update.referenceUpdate(point, this);
visibleEntities(point, target, newEntity -> { visibleEntities(point, target, newEntity -> {
if (newEntity == entity) return; if (newEntity == entity) return;
update.add(newEntity); update.add(newEntity);
@ -64,6 +65,7 @@ final class EntityTrackerImpl implements EntityTracker {
} }
} }
if (update != null) { if (update != null) {
update.referenceUpdate(point, null);
visibleEntities(point, target, update::remove); visibleEntities(point, target, update::remove);
} }
} }
@ -92,7 +94,13 @@ final class EntityTrackerImpl implements EntityTracker {
public void remove(@NotNull T removed) { public void remove(@NotNull T removed) {
if (entity != removed) update.remove(removed); if (entity != removed) update.remove(removed);
} }
@Override
public void referenceUpdate(@NotNull Point point, @Nullable EntityTracker tracker) {
// Empty
}
}); });
update.referenceUpdate(newPoint, this);
} }
} }