diff options
-rw-r--r-- | src/main/java/makamys/lodmod/renderer/LODRegion.java | 13 | ||||
-rw-r--r-- | src/main/java/makamys/lodmod/renderer/LODRenderer.java | 16 |
2 files changed, 22 insertions, 7 deletions
diff --git a/src/main/java/makamys/lodmod/renderer/LODRegion.java b/src/main/java/makamys/lodmod/renderer/LODRegion.java index 0d91e22..b797531 100644 --- a/src/main/java/makamys/lodmod/renderer/LODRegion.java +++ b/src/main/java/makamys/lodmod/renderer/LODRegion.java @@ -149,4 +149,17 @@ public class LODRegion { } } + public double distanceTaxicab(Entity entity) { + double centerX = ((regionX * 32) + 16) * 16; + double centerZ = ((regionZ * 32) + 16) * 16; + + return Math.max(Math.abs(centerX - entity.posX), Math.abs(centerZ - entity.posZ)); + + } + + @Override + public String toString() { + return "LODRegion(" + regionX + ", " + regionZ + ")"; + } + } diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java index 56ca600..3a0ff9d 100644 --- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java +++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java @@ -159,12 +159,14 @@ public class LODRenderer { for(int x = -renderRange; x <= renderRange; x++) { for(int z = -renderRange; z <= renderRange; z++) { - int chunkX = centerX + x; - int chunkZ = centerZ + z; - - if(getLODChunk(chunkX, chunkZ).needsChunk) { - newServerChunkLoadQueue.add(new ChunkCoordIntPair(chunkX, chunkZ)); - getLODChunk(chunkX, chunkZ).needsChunk = false; + if(x * x + z * z < renderRange * renderRange) { + int chunkX = centerX + x; + int chunkZ = centerZ + z; + + if(getLODChunk(chunkX, chunkZ).needsChunk) { + newServerChunkLoadQueue.add(new ChunkCoordIntPair(chunkX, chunkZ)); + getLODChunk(chunkX, chunkZ).needsChunk = false; + } } } } @@ -178,7 +180,7 @@ public class LODRenderer { ChunkCoordIntPair k = it.next(); LODRegion v = loadedRegionsMap.get(k); - if(!v.tick(player)) { + if(v.distanceTaxicab(player) > renderRange * 16 + 16 * 16) { System.out.println("unloading " + v); v.destroy(getSaveDir()); it.remove(); |