Skip to content

Commit

Permalink
Simplify chunk refreshing and fix a bug in it
Browse files Browse the repository at this point in the history
where block-specific distance is used instead of chunk distance
  • Loading branch information
altrisi committed Dec 28, 2022
1 parent ccd6512 commit 7efa9df
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/main/java/carpet/script/utils/WorldTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServerPlayer> nearbyPlayers = world.getPlayers(p -> pos.distToCenterSqr(p.getX(), pos.getY(), p.getZ()) < vvd);
if (!nearbyPlayers.isEmpty())
List<ServerPlayer> 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));
}
}
}
Expand Down

0 comments on commit 7efa9df

Please sign in to comment.