From d64ee82b4dc59c21cbe86e364fd51785f38ec8ba Mon Sep 17 00:00:00 2001 From: makamys Date: Wed, 16 Jun 2021 18:07:47 +0200 Subject: Fix LOD chunks loading from wrong coordinate when entering new dimension --- src/main/java/makamys/lodmod/LODMod.java | 2 +- .../java/makamys/lodmod/renderer/LODRenderer.java | 66 +++++++++++----------- src/main/resources/META-INF/LODMod_at.cfg | 5 +- 3 files changed, 39 insertions(+), 34 deletions(-) (limited to 'src/main') diff --git a/src/main/java/makamys/lodmod/LODMod.java b/src/main/java/makamys/lodmod/LODMod.java index 3852cdc..ceed97d 100644 --- a/src/main/java/makamys/lodmod/LODMod.java +++ b/src/main/java/makamys/lodmod/LODMod.java @@ -112,7 +112,7 @@ public class LODMod renderer.destroy(); renderer = null; } - if(enabled) { + if(enabled && newWorld != null) { renderer = new LODRenderer(newWorld); } } diff --git a/src/main/java/makamys/lodmod/renderer/LODRenderer.java b/src/main/java/makamys/lodmod/renderer/LODRenderer.java index c3ae345..2f958d0 100644 --- a/src/main/java/makamys/lodmod/renderer/LODRenderer.java +++ b/src/main/java/makamys/lodmod/renderer/LODRenderer.java @@ -165,43 +165,45 @@ public class LODRenderer { sendChunkToGPU(lodChunk); } - Entity player = Minecraft.getMinecraft().renderViewEntity; - - List newServerChunkLoadQueue = new ArrayList<>(); - - if(Double.isNaN(lastSortX) || getLastSortDistanceSq(player) > 16 * 16) { - int centerX = (int)Math.floor(player.posX / 16.0); - int centerZ = (int)Math.floor(player.posZ / 16.0); + if(Minecraft.getMinecraft().playerController.netClientHandler.doneLoadingTerrain) { + Entity player = Minecraft.getMinecraft().renderViewEntity; - for(int x = -renderRange; x <= renderRange; x++) { - for(int z = -renderRange; z <= renderRange; z++) { - 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; + List newServerChunkLoadQueue = new ArrayList<>(); + + if(Double.isNaN(lastSortX) || getLastSortDistanceSq(player) > 16 * 16) { + int centerX = (int)Math.floor(player.posX / 16.0); + int centerZ = (int)Math.floor(player.posZ / 16.0); + + for(int x = -renderRange; x <= renderRange; x++) { + for(int z = -renderRange; z <= renderRange; z++) { + 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; + } } } } - } - Collections.sort(newServerChunkLoadQueue, new ChunkCoordDistanceComparator(player.posX, player.posY, player.posZ)); - addToServerChunkLoadQueue(newServerChunkLoadQueue); - - lastSortX = player.posX; - lastSortY = player.posY; - lastSortZ = player.posZ; - for(Iterator it = loadedRegionsMap.keySet().iterator(); it.hasNext();) { - ChunkCoordIntPair k = it.next(); - LODRegion v = loadedRegionsMap.get(k); + Collections.sort(newServerChunkLoadQueue, new ChunkCoordDistanceComparator(player.posX, player.posY, player.posZ)); + addToServerChunkLoadQueue(newServerChunkLoadQueue); - if(v.distanceTaxicab(player) > renderRange * 16 + 16 * 16) { - System.out.println("unloading " + v); - v.destroy(getSaveDir()); - it.remove(); - } else { - v.tick(player); + lastSortX = player.posX; + lastSortY = player.posY; + lastSortZ = player.posZ; + for(Iterator it = loadedRegionsMap.keySet().iterator(); it.hasNext();) { + ChunkCoordIntPair k = it.next(); + LODRegion v = loadedRegionsMap.get(k); + + if(v.distanceTaxicab(player) > renderRange * 16 + 16 * 16) { + System.out.println("unloading " + v); + v.destroy(getSaveDir()); + it.remove(); + } else { + v.tick(player); + } } } } diff --git a/src/main/resources/META-INF/LODMod_at.cfg b/src/main/resources/META-INF/LODMod_at.cfg index e28c810..766965a 100644 --- a/src/main/resources/META-INF/LODMod_at.cfg +++ b/src/main/resources/META-INF/LODMod_at.cfg @@ -1,3 +1,6 @@ public net.minecraft.client.renderer.texture.TextureMap field_94252_e #mapUploadedSprites public net.minecraft.client.renderer.Tessellator func_78379_d()V #reset -public net.minecraft.world.biome.BiomeGenBase field_150605_ac #temperatureNoise \ No newline at end of file +public net.minecraft.world.biome.BiomeGenBase field_150605_ac #temperatureNoise + +public net.minecraft.client.multiplayer.PlayerControllerMP field_78774_b #netClientHandler +public net.minecraft.client.network.NetHandlerPlayClient field_147309_h #doneLoadingTerrain \ No newline at end of file -- cgit