Move getCurrentWorldID into the LodUtils class

This commit is contained in:
James Seibel
2021-03-31 10:56:50 -05:00
parent 0649504770
commit 50aee9dfb2
3 changed files with 40 additions and 40 deletions
@@ -66,12 +66,14 @@ public class LodBuilder
*/
public LodWorld generateLodChunkAsync(IChunk chunk, DimensionType dim)
{
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
// don't add this LOD
return lodWorld;
if (lodWorld == null)
return;
// is this chunk from the same world as the lodWorld?
if (!lodWorld.getWorldName().equals(LodUtils.getCurrentWorldID()))
// we are not in the same world anymore
// don't add this LOD
return;
// don't try to create an LOD object
@@ -11,11 +11,8 @@ import java.util.concurrent.Executors;
import com.backsun.lod.objects.LodChunk;
import com.backsun.lod.objects.LodDimension;
import com.backsun.lod.objects.LodRegion;
import com.backsun.lod.util.LodUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.world.server.ServerChunkProvider;
import net.minecraft.world.server.ServerWorld;
/**
* This object handles creating LodRegions
@@ -23,7 +20,7 @@ import net.minecraft.world.server.ServerWorld;
* to file.
*
* @author James Seibel
* @version 03-30-2021
* @version 03-31-2021
*/
public class LodDimensionFileHandler
{
@@ -257,33 +254,4 @@ public class LodDimensionFileHandler
/**
* If on single player this will return the name of the user's
* world, if in multiplayer it will return the server name
* and game version.
*/
public static String getCurrentWorldID()
{
Minecraft mc = Minecraft.getInstance();
if(mc.isIntegratedServerRunning())
{
ServerWorld serverWorld = LodUtils.getFirstValidServerWorld();
if (serverWorld == null)
return "";
ServerChunkProvider provider = serverWorld.getChunkProvider();
if(provider != null)
return provider.getSavedData().folder.toString();
return "";
}
else
{
return mc.getCurrentServerData().serverName + "_version_" + mc.getCurrentServerData().gameVersion;
}
}
}
@@ -9,13 +9,14 @@ import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.DimensionType;
import net.minecraft.world.chunk.ChunkSection;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.server.ServerChunkProvider;
import net.minecraft.world.server.ServerWorld;
/**
* This class holds methods that may be used in multiple places.
*
* @author James Seibel
* @version 03-24-2021
* @version 03-31-2021
*/
public class LodUtils
{
@@ -107,4 +108,33 @@ public class LodUtils
return false;
}
/**
* If on single player this will return the name of the user's
* world, if in multiplayer it will return the server name
* and game version.
*/
public static String getCurrentWorldID()
{
Minecraft mc = Minecraft.getInstance();
if(mc.isIntegratedServerRunning())
{
ServerWorld serverWorld = LodUtils.getFirstValidServerWorld();
if (serverWorld == null)
return "";
ServerChunkProvider provider = serverWorld.getChunkProvider();
if(provider != null)
return provider.getSavedData().folder.toString();
return "";
}
else
{
return mc.getCurrentServerData().serverName + "_version_" + mc.getCurrentServerData().gameVersion;
}
}
}