diff --git a/src/main/java/com/seibel/lod/builders/worldGeneration/LodNodeGenWorker.java b/src/main/java/com/seibel/lod/builders/worldGeneration/LodNodeGenWorker.java index 81363825a..b8464f25c 100644 --- a/src/main/java/com/seibel/lod/builders/worldGeneration/LodNodeGenWorker.java +++ b/src/main/java/com/seibel/lod/builders/worldGeneration/LodNodeGenWorker.java @@ -192,6 +192,12 @@ public class LodNodeGenWorker implements IWorker //} //else //{ + if (lodDim.isChunkPreGenerated(pos.x, pos.z) && LodConfig.CLIENT.worldGenerator.useExperimentalPreGenLoading.get()) + { + generateWithServer(); + } + else + { switch (generationMode) { case NONE: @@ -215,6 +221,7 @@ public class LodNodeGenWorker implements IWorker generateWithServer(); break; } + } //} //lodRenderer.regenerateLODsNextFrame(); @@ -469,7 +476,7 @@ public class LodNodeGenWorker implements IWorker ConfiguredFeature configuredFeature = featureSupplier.get(); if (!allowUnstableFeatures && - configuredFeaturesToAvoid.containsKey(configuredFeature.hashCode())) + configuredFeaturesToAvoid.containsKey(configuredFeature.hashCode())) continue; diff --git a/src/main/java/com/seibel/lod/config/LodConfig.java b/src/main/java/com/seibel/lod/config/LodConfig.java index 7c5220cb2..e860b8ec1 100644 --- a/src/main/java/com/seibel/lod/config/LodConfig.java +++ b/src/main/java/com/seibel/lod/config/LodConfig.java @@ -212,7 +212,7 @@ public class LodConfig public final ForgeConfigSpec.EnumValue horizontalQuality; public final ForgeConfigSpec.BooleanValue avoidBlocksWithNoCollision; public final ForgeConfigSpec.BooleanValue avoidNonFullBlocks; - //public final ForgeConfigSpec.BooleanValue alwaysLoadPregeneratedChunks; + public final ForgeConfigSpec.BooleanValue useExperimentalPreGenLoading; WorldGenerator(ForgeConfigSpec.Builder builder) { @@ -342,11 +342,11 @@ public class LodConfig + " Turning this on will make plains smoother since the tall grass won't be used. \n") .define("Avoid Blocks With No Collision", true); - /*alwaysLoadPregeneratedChunks = builder + useExperimentalPreGenLoading = builder .comment("\n\n" + " if a chunk has been pre-generated, then the mod would use the real chunk for the \n" + "fake chunk creation. May require a deletion of the lod file to see the result. \n") - .define("Use pre-generated chunks", true);*/ + .define("Use pre-generated chunks", false); avoidNonFullBlocks = builder .comment("\n\n" + " If true LODs will only show full bocks when generating. \n" diff --git a/src/main/java/com/seibel/lod/objects/LodDimension.java b/src/main/java/com/seibel/lod/objects/LodDimension.java index d732cb9b7..6ddbc0aff 100644 --- a/src/main/java/com/seibel/lod/objects/LodDimension.java +++ b/src/main/java/com/seibel/lod/objects/LodDimension.java @@ -583,8 +583,6 @@ public class LodDimension } - //Now we check if the current chunk has been generated with the correct complexity - complexity = LodConfig.CLIENT.worldGenerator.distanceGenerationMode.get().complexity; xChunkToCheck = x + playerChunkX; zChunkToCheck = z + playerChunkZ; @@ -593,6 +591,13 @@ public class LodDimension if (lodRegion == null) continue; + //Now we check if the current chunk has been generated with the correct complexity + //if(lodRegion.isChunkPreGenerated(xChunkToCheck,zChunkToCheck)) + // complexity = DistanceGenerationMode.SERVER.complexity; + //else + complexity = LodConfig.CLIENT.worldGenerator.distanceGenerationMode.get().complexity; + + //we create the level position info of the chunk detailLevel = lodRegion.getMinDetailLevel(); posX = LevelPosUtil.convert(LodUtil.CHUNK_DETAIL_LEVEL, xChunkToCheck, detailLevel); @@ -802,6 +807,19 @@ public class LodDimension } + /** + * Return true if the chunk has been pregenerated in game + */ + public boolean isChunkPreGenerated(int xChunkPos, int zChunkPos) + { + + LodRegion region = getRegion(LodUtil.CHUNK_DETAIL_LEVEL, xChunkPos, zChunkPos); + if (region == null) + return false; + + return region.isChunkPreGenerated(xChunkPos, zChunkPos); + } + /** * Returns whether the region at the given RegionPos * is within the loaded range. diff --git a/src/main/java/com/seibel/lod/objects/LodRegion.java b/src/main/java/com/seibel/lod/objects/LodRegion.java index 672f7ea3c..5c80b493a 100644 --- a/src/main/java/com/seibel/lod/objects/LodRegion.java +++ b/src/main/java/com/seibel/lod/objects/LodRegion.java @@ -48,7 +48,7 @@ public class LodRegion /** * This chunk Pos has been generated */ - //private final boolean[] preGeneratedChunkPos; + private final boolean[] preGeneratedChunkPos; /** * the generation mode for this region @@ -84,47 +84,72 @@ public class LodRegion dataContainer[lod] = new VerticalLevelContainer(lod); } - /*boolean fileFound = false; + boolean fileFound = false; - preGeneratedChunkPos = new boolean[32*32]; + preGeneratedChunkPos = new boolean[32 * 32]; - if (MinecraftWrapper.INSTANCE.hasSinglePlayerServer()) + if (MinecraftWrapper.INSTANCE.hasSinglePlayerServer() && LodConfig.CLIENT.worldGenerator.useExperimentalPreGenLoading.get()) { - File regionFileDirParent; File regionFileDirHead; + File regionFileDirParent; // local world ServerWorld serverWorld = LodUtil.getServerWorldFromDimension(MinecraftWrapper.INSTANCE.getCurrentDimension()); // provider needs a separate variable to prevent // the compiler from complaining - ServerChunkProvider provider = serverWorld.getChunkSource(); - regionFileDirParent = new File(provider.dataStorage.dataFolder.getParentFile().getPath() + File.separatorChar + "region"); - regionFileDirHead = new File("r." + regionPosZ + "." + regionPosX + ".mca"); - try{ - RegionFile regionFile = new RegionFile(regionFileDirParent, regionFileDirHead, true); - for(int x = 0; x < 32; x++) + StringBuilder string = new StringBuilder(); + try + { + ServerChunkProvider provider = serverWorld.getChunkSource(); + + //System.out.println(provider.dataStorage.dataFolder); + regionFileDirHead = new File(provider.dataStorage.dataFolder.getCanonicalFile().getParentFile().toPath().toAbsolutePath().toString() + File.separatorChar + "region", "r." + regionPosZ + "." + regionPosX + ".mca"); + if (regionFileDirHead.exists()) { - for(int z = 0; z < 32; z++) + regionFileDirParent = regionFileDirHead.getParentFile(); + //string.append(regionFileDirParent.toString()); + string.append(regionFileDirHead); + RegionFile regionFile = new RegionFile(regionFileDirHead, regionFileDirParent, true); + for (int x = 0; x < 32; x++) { - preGeneratedChunkPos[x*32 + z] = regionFile.hasChunk(new ChunkPos(regionPosX*32 + x, regionPosZ*32 + z)); + for (int z = 0; z < 32; z++) + { + preGeneratedChunkPos[x * 32 + z] = regionFile.doesChunkExist(new ChunkPos(regionPosX * 32 + x, regionPosZ * 32 + z)); + } } + + string.append("region " + regionPosX + " " + regionPosZ + "\n"); + for (int x = 0; x < 32; x++) + { + for (int z = 0; z < 32; z++) + { + //regionFile.doesChunkExist() + string.append(preGeneratedChunkPos[x * 32 + z] + "\t"); + } + string.append("\n"); + } + regionFile.close(); } - }catch (Exception e){ } + catch (Exception e) + { + e.printStackTrace(); + } + System.out.println(string); } - StringBuilder string = new StringBuilder(); - string.append("region " + regionPosX + " " + regionPosZ + "\n"); - for(int x = 0; x < 32; x++) - { - for(int z = 0; z < 32; z++) - { - string.append(preGeneratedChunkPos[x*32 + z] + "\t"); - } - string.append("\n"); - } - System.out.println(string);*/ + } + + + /** + * Return true if the chunk has been pregenerated in game + */ + public boolean isChunkPreGenerated(int xChunkPos, int zChunkPos) + { + xChunkPos = LevelPosUtil.getRegionModule(LodUtil.CHUNK_DETAIL_LEVEL, xChunkPos); + zChunkPos = LevelPosUtil.getRegionModule(LodUtil.CHUNK_DETAIL_LEVEL, zChunkPos); + return preGeneratedChunkPos[xChunkPos * 32 + zChunkPos]; } /** diff --git a/src/main/java/com/seibel/lod/util/LodUtil.java b/src/main/java/com/seibel/lod/util/LodUtil.java index a20f4f5dd..784777d2e 100644 --- a/src/main/java/com/seibel/lod/util/LodUtil.java +++ b/src/main/java/com/seibel/lod/util/LodUtil.java @@ -291,7 +291,6 @@ public class LodUtil public static String getServerId() { ServerData server = mc.getCurrentServer(); - String serverName = server.name.replaceAll(INVALID_FILE_CHARACTERS_REGEX, ""); String serverIp = server.ip.replaceAll(INVALID_FILE_CHARACTERS_REGEX, ""); String serverMcVersion = server.version.getString().replaceAll(INVALID_FILE_CHARACTERS_REGEX, "");