From b2045a5b3d55eb51fd6caef9207bb082d860751a Mon Sep 17 00:00:00 2001 From: Valaphee The Meerkat <32491319+valaphee@users.noreply.github.com> Date: Wed, 11 Dec 2024 03:04:33 +0100 Subject: [PATCH] Fix skull mix-up by not reusing skulls (#5206) --- .../entity/type/player/SkullPlayerEntity.java | 11 ----- .../geyser/session/cache/SkullCache.java | 45 ++++--------------- 2 files changed, 9 insertions(+), 47 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java b/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java index 1c5060de0..4c8d1d20b 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java +++ b/core/src/main/java/org/geysermc/geyser/entity/type/player/SkullPlayerEntity.java @@ -102,17 +102,6 @@ public class SkullPlayerEntity extends PlayerEntity { session.sendUpstreamPacket(addPlayerPacket); } - /** - * Hide the player entity so that it can be reused for a different skull. - */ - public void free() { - setFlag(EntityFlag.INVISIBLE, true); - updateBedrockMetadata(); - - // Move skull entity out of the way - moveAbsolute(session.getPlayerEntity().getPosition().up(128), 0, 0, 0, false, true); - } - public void updateSkull(SkullCache.Skull skull) { skullPosition = skull.getPosition(); diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java index 0eec39b0b..a3cf1247f 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/SkullCache.java @@ -50,20 +50,14 @@ import java.util.*; public class SkullCache { private final int maxVisibleSkulls; private final boolean cullingEnabled; - + private final int skullRenderDistanceSquared; - - /** - * The time in milliseconds before unused skull entities are despawned - */ - private static final long CLEANUP_PERIOD = 10000; @Getter private final Map skulls = new Object2ObjectOpenHashMap<>(); private final List inRangeSkulls = new ArrayList<>(); - private final Deque unusedSkullEntities = new ArrayDeque<>(); private int totalSkullEntities = 0; private final GeyserSession session; @@ -188,43 +182,26 @@ public class SkullCache { } } } - - // Occasionally clean up unused entities as we want to keep skull - // entities around for later use, to reduce "player" pop-in - if ((System.currentTimeMillis() - lastCleanup) > CLEANUP_PERIOD) { - lastCleanup = System.currentTimeMillis(); - for (SkullPlayerEntity entity : unusedSkullEntities) { - entity.despawnEntity(); - totalSkullEntities--; - } - unusedSkullEntities.clear(); - } } private void assignSkullEntity(Skull skull) { if (skull.entity != null) { return; } - if (unusedSkullEntities.isEmpty()) { - if (!cullingEnabled || totalSkullEntities < maxVisibleSkulls) { - // Create a new entity - long geyserId = session.getEntityCache().getNextEntityId().incrementAndGet(); - skull.entity = new SkullPlayerEntity(session, geyserId); - skull.entity.spawnEntity(); - skull.entity.updateSkull(skull); - totalSkullEntities++; - } - } else { - // Reuse an entity - skull.entity = unusedSkullEntities.removeFirst(); + if (!cullingEnabled || totalSkullEntities < maxVisibleSkulls) { + // Create a new entity + long geyserId = session.getEntityCache().getNextEntityId().incrementAndGet(); + skull.entity = new SkullPlayerEntity(session, geyserId); + skull.entity.spawnEntity(); skull.entity.updateSkull(skull); + totalSkullEntities++; } } private void freeSkullEntity(Skull skull) { if (skull.entity != null) { - skull.entity.free(); - unusedSkullEntities.addFirst(skull.entity); + skull.entity.despawnEntity(); + totalSkullEntities--; skull.entity = null; } } @@ -250,10 +227,6 @@ public class SkullCache { } skulls.clear(); inRangeSkulls.clear(); - for (SkullPlayerEntity skull : unusedSkullEntities) { - skull.despawnEntity(); - } - unusedSkullEntities.clear(); totalSkullEntities = 0; lastPlayerPosition = null; }