Improve the world changing logic
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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()));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user