Simplify chunk refreshing and fix a bug in it
where block-specific distance is used instead of chunk distance
This commit is contained in:
1 file changed
+5
-7
@@ -139,17 +139,15 @@ public class WorldTools
|
|||||||
|
|
||||||
public static void forceChunkUpdate(BlockPos pos, ServerLevel world)
|
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)
|
if (worldChunk != null)
|
||||||
{
|
{
|
||||||
int vd = world.getServer().getPlayerList().getViewDistance() * 16;
|
List<ServerPlayer> players = world.getChunkSource().chunkMap.getPlayers(chunkPos, false);
|
||||||
int vvd = vd * vd;
|
if (!players.isEmpty())
|
||||||
List<ServerPlayer> nearbyPlayers = world.getPlayers(p -> pos.distToCenterSqr(p.getX(), pos.getY(), p.getZ()) < vvd);
|
|
||||||
if (!nearbyPlayers.isEmpty())
|
|
||||||
{
|
{
|
||||||
ClientboundLevelChunkWithLightPacket packet = new ClientboundLevelChunkWithLightPacket(worldChunk, world.getLightEngine(), null, null, false); // false seems to update neighbours as well.
|
ClientboundLevelChunkWithLightPacket packet = new ClientboundLevelChunkWithLightPacket(worldChunk, world.getLightEngine(), null, null, false); // false seems to update neighbours as well.
|
||||||
ChunkPos chpos = new ChunkPos(pos);
|
players.forEach(p -> p.connection.send(packet));
|
||||||
nearbyPlayers.forEach(p -> p.connection.send(packet));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user