diff --git a/src/main/java/net/minecraft/entity/player/EntityPlayerMP.java b/src/main/java/net/minecraft/entity/player/EntityPlayerMP.java index 558a190..326fca5 100644 --- a/src/main/java/net/minecraft/entity/player/EntityPlayerMP.java +++ b/src/main/java/net/minecraft/entity/player/EntityPlayerMP.java @@ -912,10 +912,7 @@ this.translator = p_147100_1_.func_149524_c(); int i = /*256 >>*/ p_147100_1_.func_149521_d(); - if (i > 3 && i < 15) - { - this.renderDistance = i; - } + this.renderDistance = MathHelper.clamp_int(i, 3, 15); this.chatVisibility = p_147100_1_.func_149523_e(); this.chatColours = p_147100_1_.func_149520_f(); diff --git a/src/main/java/org/ultramine/server/chunk/ChunkSendManager.java b/src/main/java/org/ultramine/server/chunk/ChunkSendManager.java index 6d5d5dd..e64b310 100644 --- a/src/main/java/org/ultramine/server/chunk/ChunkSendManager.java +++ b/src/main/java/org/ultramine/server/chunk/ChunkSendManager.java @@ -41,6 +41,7 @@ private final EntityPlayerMP player; private PlayerManager manager; private BlockFace lastFace; + private int lastViewDistance; private final TIntArrayListImpl toSend = new TIntArrayListImpl(441); private final TIntSet sending = TCollections.synchronizedSet(new TIntHashSet()); @@ -58,6 +59,11 @@ this.player = player; } + private int getViewDistance() + { + return Math.min(manager.getWorldServer().getConfig().chunkLoading.viewDistance, player.getRenderDistance()); + } + private void sortSendQueue() { int cx = MathHelper.floor_double(player.posX) >> 4; @@ -65,6 +71,61 @@ toSend.sort(ChunkCoordComparator.get(lastFace = BlockFace.yawToFace(player.rotationYaw), cx, cz)); } + private void checkDistance() + { + int curView = getViewDistance(); + if(curView != lastViewDistance) + { + int cx = MathHelper.floor_double(player.posX) >> 4; + int cz = MathHelper.floor_double(player.posZ) >> 4; + + if(curView < lastViewDistance) + { + for(TIntIterator it = toSend.iterator(); it.hasNext();) + { + int key = it.next(); + if(!overlaps(cx, cz, ChunkHash.keyToX(key), ChunkHash.keyToZ(key), curView)) + it.remove(); + } + + for(TIntIterator it = sending.iterator(); it.hasNext();) + { + int key = it.next(); + if(!overlaps(cx, cz, ChunkHash.keyToX(key), ChunkHash.keyToZ(key), curView)) + it.remove(); + } + + for(TIntIterator it = sended.iterator(); it.hasNext();) + { + int key = it.next(); + if(!overlaps(cx, cz, ChunkHash.keyToX(key), ChunkHash.keyToZ(key), curView)) + { + PlayerManager.PlayerInstance pi = manager.getOrCreateChunkWatcher(ChunkHash.keyToX(key), ChunkHash.keyToZ(key), false); + if(pi != null) pi.removePlayer(player); + it.remove(); + } + } + } + else + { + for (int x = cx - curView; x <= cx + curView; ++x) + { + for (int z = cz - curView; z <= cz + curView; ++z) + { + int key = ChunkHash.chunkToKey(x, z); + if(!toSend.contains(key) && !sended.contains(key) && !sending.contains(key)) + { + toSend.add(key); + } + } + } + } + + lastViewDistance = curView; + sortSendQueue(); + } + } + public void addTo(PlayerManager manager) { if(this.manager != null) throw new IllegalStateException("PlayerManager already set"); @@ -75,7 +136,7 @@ int cx = MathHelper.floor_double(player.posX) >> 4; int cz = MathHelper.floor_double(player.posZ) >> 4; - int viewRadius = manager.getWorldServer().getConfig().chunkLoading.viewDistance; + int viewRadius = lastViewDistance = getViewDistance(); for (int x = cx - viewRadius; x <= cx + viewRadius; ++x) { @@ -203,19 +264,23 @@ private void sendChunks(int count) { - for(int i = 0, s = Math.min(count, toSend.size()); i < s; i++) + count = Math.min(count, toSend.size()); + for(int i = 0; i < count; i++) { - int key = toSend.removeAt(0); + int key = toSend.get(i); sending.add(key); sendingQueueSize.incrementAndGet(); int ncx = ChunkHash.keyToX(key); int ncz = ChunkHash.keyToZ(key); manager.getWorldServer().theChunkProviderServer.loadAsync(ncx, ncz, chunkLoadCallback); } + toSend.remove(0, count); } public void updatePlayerPertinentChunks() { + checkDistance(); + int cx = MathHelper.floor_double(player.posX) >> 4; int cz = MathHelper.floor_double(player.posZ) >> 4; double d0 = player.managedPosX - player.posX; @@ -228,7 +293,7 @@ { int lastX = MathHelper.floor_double(player.managedPosX) >> 4; int lastZ = MathHelper.floor_double(player.managedPosZ) >> 4; - int view = manager.getWorldServer().getConfig().chunkLoading.viewDistance; + int view = getViewDistance(); int movX = cx - lastX; int movZ = cz - lastZ;