From 055f64e7c63457aa8992f306db6a53eab14afea1 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 27 Feb 2021 19:09:52 -0600 Subject: [PATCH] Improve the world changing logic --- .../com/backsun/lod/builders/LodBuilder.java | 24 ++++------ .../com/backsun/lod/proxy/ClientProxy.java | 44 ++++++------------- 2 files changed, 22 insertions(+), 46 deletions(-) diff --git a/src/main/java/com/backsun/lod/builders/LodBuilder.java b/src/main/java/com/backsun/lod/builders/LodBuilder.java index ffbf0cbc5..c1ec997b1 100644 --- a/src/main/java/com/backsun/lod/builders/LodBuilder.java +++ b/src/main/java/com/backsun/lod/builders/LodBuilder.java @@ -43,6 +43,13 @@ public class LodBuilder */ public LodWorld generateLodChunkAsync(Chunk chunk) { + if (lodWorld != null) + // is this chunk from the same world as the lodWorld? + if (!lodWorld.worldName.equals(LodDimensionFileHandler.getCurrentWorldID())) + // we are not in the same world anymore, + // remove the old world so it can be recreated later + lodWorld = null; + // don't try to create an LOD object // if for some reason we aren't // given a valid chunk object @@ -68,22 +75,7 @@ public class LodBuilder if (lodWorld == null) { - lodWorld = new LodWorld(LodDimensionFileHandler.getWorldName()); - } - else - { - // if we have a lodWorld make sure - // it is for this minecraft world - if (!lodWorld.worldName.equals(LodDimensionFileHandler.getWorldName())) - { - // this lodWorld isn't for this minecraft world - // delete it so we can get a new one - lodWorld = null; - - // skip this frame - // we'll get this set up next time - return; - } + lodWorld = new LodWorld(LodDimensionFileHandler.getCurrentWorldID()); } diff --git a/src/main/java/com/backsun/lod/proxy/ClientProxy.java b/src/main/java/com/backsun/lod/proxy/ClientProxy.java index db893f476..e1b20977e 100644 --- a/src/main/java/com/backsun/lod/proxy/ClientProxy.java +++ b/src/main/java/com/backsun/lod/proxy/ClientProxy.java @@ -3,6 +3,7 @@ package com.backsun.lod.proxy; import org.lwjgl.opengl.GL11; import com.backsun.lod.builders.LodBuilder; +import com.backsun.lod.handlers.LodDimensionFileHandler; import com.backsun.lod.objects.LodChunk; import com.backsun.lod.objects.LodDimension; import com.backsun.lod.objects.LodRegion; @@ -37,6 +38,7 @@ public class ClientProxy public ClientProxy() { lodBuilder = new LodBuilder(); + renderer = new LodRenderer(); } @@ -64,6 +66,7 @@ public class ClientProxy */ public void renderLods(float partialTicks) { + // update the int newWidth = Math.max(4, (mc.gameSettings.renderDistanceChunks * LodChunk.WIDTH * 2) / LodRegion.SIZE); if (lodWorld != null && lodBuilder.regionWidth != newWidth) { @@ -75,6 +78,12 @@ public class ClientProxy return; } + // are we still in the same world? + if (!lodWorld.worldName.equals(LodDimensionFileHandler.getCurrentWorldID())) + // no, don't render the wrong world + return; + + if (mc == null || mc.player == null || lodWorld == null) return; @@ -83,6 +92,8 @@ public class ClientProxy return; + + // offset the regions double playerX = mc.player.getPosX(); double playerZ = mc.player.getPosZ(); @@ -94,18 +105,9 @@ public class ClientProxy lodDim.move(xOffset, zOffset); } - // we wait to create the renderer until the first frame - // to make sure that the EntityRenderer has - // been created, that way we can get the fovModifer - // method from it through reflection. - if (renderer == null) - { - renderer = new LodRenderer(); - } - else - { - renderer.drawLODs(lodDim, partialTicks, mc.getProfiler()); - } + + + renderer.drawLODs(lodDim, partialTicks, mc.getProfiler()); } @@ -123,24 +125,6 @@ public class ClientProxy lodWorld = lodBuilder.generateLodChunkAsync((Chunk) event.getChunk()); } - /** - * this event is called whenever a chunk is created for the first time. - */ -// @SubscribeEvent -// public void onChunkPopulate(PopulateChunkEvent event) -// { -// Minecraft mc = Minecraft.getMinecraft(); -// if (mc != null && event != null) -// { -// WorldClient world = mc.world; -// -// if(world != null) -// { -// lodWorld = lodBuilder.generateLodChunkAsync(world.getChunkFromChunkCoords(event.getChunkX(), event.getChunkZ())); -// } -// } -// } -