From 0631aefec2f905152c05bce7f5d342e7816cceb7 Mon Sep 17 00:00:00 2001 From: Revela Date: Wed, 11 Mar 2026 22:12:03 -0500 Subject: [PATCH] Fix portal cache key to use chunk coordinates --- Minecraft.World/PortalForcer.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Minecraft.World/PortalForcer.cpp b/Minecraft.World/PortalForcer.cpp index 9695afdf..a67cb23a 100644 --- a/Minecraft.World/PortalForcer.cpp +++ b/Minecraft.World/PortalForcer.cpp @@ -93,7 +93,7 @@ bool PortalForcer::findPortal(shared_ptr e, double xOriginal, double yOr int xc = Mth::floor(e->x); int zc = Mth::floor(e->z); - long hash = ChunkPos::hashCode(xc, zc); + long hash = ChunkPos::hashCode(xc >> 4, zc >> 4); bool updateCache = true; auto it = cachedPortals.find(hash); @@ -148,8 +148,17 @@ bool PortalForcer::findPortal(shared_ptr e, double xOriginal, double yOr if (updateCache) { - cachedPortals[hash] = new PortalPosition(x, y, z, level->getGameTime()); - cachedPortalKeys.push_back(hash); + auto existing = cachedPortals.find(hash); + if (existing != cachedPortals.end()) + { + delete existing->second; + existing->second = new PortalPosition(x, y, z, level->getGameTime()); + } + else + { + cachedPortals[hash] = new PortalPosition(x, y, z, level->getGameTime()); + cachedPortalKeys.push_back(hash); + } } double xt = x + 0.5;