From 7efa9df3ee9e2f49ccbe8040fcc1dff711bfc000 Mon Sep 17 00:00:00 2001 From: altrisi Date: Wed, 28 Dec 2022 16:30:33 +0100 Subject: [PATCH] Simplify chunk refreshing and fix a bug in it where block-specific distance is used instead of chunk distance --- src/main/java/carpet/script/utils/WorldTools.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/carpet/script/utils/WorldTools.java b/src/main/java/carpet/script/utils/WorldTools.java index d592810421..1c9c0543df 100644 --- a/src/main/java/carpet/script/utils/WorldTools.java +++ b/src/main/java/carpet/script/utils/WorldTools.java @@ -139,17 +139,15 @@ public static boolean createWorld(MinecraftServer server, String worldKey, Long public static void forceChunkUpdate(BlockPos pos, ServerLevel world) { - LevelChunk worldChunk = world.getChunkSource().getChunk(pos.getX()>>4, pos.getZ()>>4, false); + ChunkPos chunkPos = new ChunkPos(pos); + LevelChunk worldChunk = world.getChunkSource().getChunk(chunkPos.x, chunkPos.z, false); if (worldChunk != null) { - int vd = world.getServer().getPlayerList().getViewDistance() * 16; - int vvd = vd * vd; - List nearbyPlayers = world.getPlayers(p -> pos.distToCenterSqr(p.getX(), pos.getY(), p.getZ()) < vvd); - if (!nearbyPlayers.isEmpty()) + List players = world.getChunkSource().chunkMap.getPlayers(chunkPos, false); + if (!players.isEmpty()) { ClientboundLevelChunkWithLightPacket packet = new ClientboundLevelChunkWithLightPacket(worldChunk, world.getLightEngine(), null, null, false); // false seems to update neighbours as well. - ChunkPos chpos = new ChunkPos(pos); - nearbyPlayers.forEach(p -> p.connection.send(packet)); + players.forEach(p -> p.connection.send(packet)); } } }