From 3940e3d6005f9b8ca15f07406c9797f8f606b380 Mon Sep 17 00:00:00 2001 From: Nicholas Young Date: Tue, 24 Sep 2019 16:14:17 -0400 Subject: [PATCH] Add option for blacklisted dimensions #3 --- .../bettercaves/config/ConfigCaveGen.java | 5 + .../bettercaves/world/MapGenBetterCaves.java | 199 +++++++++--------- src/main/resources/app.properties | 2 +- 3 files changed, 109 insertions(+), 97 deletions(-) diff --git a/src/main/java/com/yungnickyoung/minecraft/bettercaves/config/ConfigCaveGen.java b/src/main/java/com/yungnickyoung/minecraft/bettercaves/config/ConfigCaveGen.java index 6869af3..0a61eed 100644 --- a/src/main/java/com/yungnickyoung/minecraft/bettercaves/config/ConfigCaveGen.java +++ b/src/main/java/com/yungnickyoung/minecraft/bettercaves/config/ConfigCaveGen.java @@ -57,4 +57,9 @@ public class ConfigCaveGen { @Config.Comment("The maximum altitude at which caves can generate") @Config.RequiresWorldRestart public int maxCaveAltitude = 128; + + @Config.Name("Blacklisted Dimension IDs") + @Config.Comment("List of ID's of dimensions that won't have Better Caves") + @Config.RequiresWorldRestart + public int[] blacklistedDimensionIDs = {-1, 1}; } diff --git a/src/main/java/com/yungnickyoung/minecraft/bettercaves/world/MapGenBetterCaves.java b/src/main/java/com/yungnickyoung/minecraft/bettercaves/world/MapGenBetterCaves.java index 4a83630..9cdb5ba 100644 --- a/src/main/java/com/yungnickyoung/minecraft/bettercaves/world/MapGenBetterCaves.java +++ b/src/main/java/com/yungnickyoung/minecraft/bettercaves/world/MapGenBetterCaves.java @@ -107,111 +107,118 @@ public void generate(World worldIn, int chunkX, int chunkZ, @Nonnull ChunkPrimer int cavernTopY; int caveBottomY; - if (worldIn.provider.getDimension() == 0) { // Only use Better Caves generation in overworld - // We split chunks into 2x2 subchunks for surface height calculations - for (int subX = 0; subX < 8; subX++) { - for (int subZ = 0; subZ < 8; subZ++) { - if (!Configuration.debugsettings.debugVisualizer) - maxSurfaceHeight = BetterCaveUtil.getMaxSurfaceHeightSubChunk(primer, subX, subZ); - - // maxSurfaceHeight (also used for max cave altitude) cannot exceed Max Cave Altitude setting - maxSurfaceHeight = Math.min(maxSurfaceHeight, Configuration.caveSettings.maxCaveAltitude); - - for (int offsetX = 0; offsetX < 2; offsetX++) { - for (int offsetZ = 0; offsetZ < 2; offsetZ++) { - int localX = (subX * 2) + offsetX; // chunk-local x-coordinate (0-15, inclusive) - int localZ = (subZ * 2) + offsetZ; // chunk-local z-coordinate (0-15, inclusive) - int realX = (chunkX * 16) + localX; - int realZ = (chunkZ * 16) + localZ; - - /* --------------------------- Configure Caves --------------------------- */ - - // Get noise values used to determine cave biome - float caveBiomeNoise = caveBiomeController.GetNoise(realX, realZ); - - /* Determine cave type for this column. We have two thresholds, one for cubic caves and one for - * simplex caves. Since the noise value generated for the biome is between -1 and 1, we (by - * default) designate all negative values as cubic caves, and all positive as simplex. However, - * we allow the user to tweak the cutoff values based on the frequency they designate for each cave - * type, so we must also check for values between the two thresholds, - * e.g. if (cubicCaveThreshold <= noiseValue < simplexCaveThreshold). - * In this case, we use vanilla cave generation if it is enabled; otherwise we dig no caves - * out of this chunk. - */ - if (caveBiomeNoise < this.cubicCaveThreshold) { - caveGen = this.caveCubic; - caveBottomY = Configuration.caveSettings.cubicCave.caveBottom; - } else if (caveBiomeNoise >= this.simplexCaveThreshold) { - caveGen = this.caveSimplex; - caveBottomY = Configuration.caveSettings.simplexCave.caveBottom; - } else { - if (this.enableVanillaCaves) { - defaultCaveGen.generate(worldIn, chunkX, chunkZ, primer); - return; - } - caveGen = null; - caveBottomY = 255; + int dimensionID = worldIn.provider.getDimension(); + + // Only use Better Caves generation in non-blacklisted dimensions + for (int dim : Configuration.caveSettings.blacklistedDimensionIDs) { + if (dimensionID == dim) { + defaultCaveGen.generate(worldIn, chunkX, chunkZ, primer); + return; + } + } + + // We split chunks into 2x2 subchunks for surface height calculations + for (int subX = 0; subX < 8; subX++) { + for (int subZ = 0; subZ < 8; subZ++) { + if (!Configuration.debugsettings.debugVisualizer) + maxSurfaceHeight = BetterCaveUtil.getMaxSurfaceHeightSubChunk(primer, subX, subZ); + + // maxSurfaceHeight (also used for max cave altitude) cannot exceed Max Cave Altitude setting + maxSurfaceHeight = Math.min(maxSurfaceHeight, Configuration.caveSettings.maxCaveAltitude); + + for (int offsetX = 0; offsetX < 2; offsetX++) { + for (int offsetZ = 0; offsetZ < 2; offsetZ++) { + int localX = (subX * 2) + offsetX; // chunk-local x-coordinate (0-15, inclusive) + int localZ = (subZ * 2) + offsetZ; // chunk-local z-coordinate (0-15, inclusive) + int realX = (chunkX * 16) + localX; + int realZ = (chunkZ * 16) + localZ; + + /* --------------------------- Configure Caves --------------------------- */ + + // Get noise values used to determine cave biome + float caveBiomeNoise = caveBiomeController.GetNoise(realX, realZ); + + /* Determine cave type for this column. We have two thresholds, one for cubic caves and one for + * simplex caves. Since the noise value generated for the biome is between -1 and 1, we (by + * default) designate all negative values as cubic caves, and all positive as simplex. However, + * we allow the user to tweak the cutoff values based on the frequency they designate for each cave + * type, so we must also check for values between the two thresholds, + * e.g. if (cubicCaveThreshold <= noiseValue < simplexCaveThreshold). + * In this case, we use vanilla cave generation if it is enabled; otherwise we dig no caves + * out of this chunk. + */ + if (caveBiomeNoise < this.cubicCaveThreshold) { + caveGen = this.caveCubic; + caveBottomY = Configuration.caveSettings.cubicCave.caveBottom; + } else if (caveBiomeNoise >= this.simplexCaveThreshold) { + caveGen = this.caveSimplex; + caveBottomY = Configuration.caveSettings.simplexCave.caveBottom; + } else { + if (this.enableVanillaCaves) { + defaultCaveGen.generate(worldIn, chunkX, chunkZ, primer); + return; } + caveGen = null; + caveBottomY = 255; + } + + /* --------------------------- Configure Caverns --------------------------- */ - /* --------------------------- Configure Caverns --------------------------- */ - - // Get noise values used to determine cavern biome - float cavernBiomeNoise = cavernBiomeController.GetNoise(realX, realZ); - float waterBiomeNoise = 99; - - // Only bother calculating noise for water biome if enabled - if (enableWaterBiomes) - waterBiomeNoise = waterCavernController.GetNoise(realX, realZ); - - // If water biome threshold check is passed, change lava block to water - IBlockState lavaBlock = Blocks.FLOWING_LAVA.getDefaultState(); - if (waterBiomeNoise < waterBiomeThreshold) - lavaBlock = Blocks.WATER.getDefaultState(); - - // Determine cavern type for this column. Caverns generate at low altitudes only. - if (cavernBiomeNoise < lavaCavernThreshold) { - if (this.enableWaterBiomes && waterBiomeNoise < this.waterBiomeThreshold) { - // Generate water cavern in this column - cavernGen = this.cavernWater; - } else { - // Generate lava cavern in this column - cavernGen = this.cavernLava; - } - // Water caverns use the same cave top/bottom as lava caverns - cavernBottomY = Configuration.caveSettings.lavaCavern.caveBottom; - cavernTopY = Configuration.caveSettings.lavaCavern.caveTop; - } else if (cavernBiomeNoise >= lavaCavernThreshold && cavernBiomeNoise <= flooredCavernThreshold) { - /* Similar to determining cave type above, we must check for values between the two adjusted - * thresholds, i.e. lavaCavernThreshold < noiseValue <= flooredCavernThreshold. - * In this case, we just continue generating the caves we were generating above, instead - * of generating a cavern. - */ - cavernGen = caveGen; - cavernBottomY = caveBottomY; - cavernTopY = caveBottomY; + // Get noise values used to determine cavern biome + float cavernBiomeNoise = cavernBiomeController.GetNoise(realX, realZ); + float waterBiomeNoise = 99; + + // Only bother calculating noise for water biome if enabled + if (enableWaterBiomes) + waterBiomeNoise = waterCavernController.GetNoise(realX, realZ); + + // If water biome threshold check is passed, change lava block to water + IBlockState lavaBlock = Blocks.FLOWING_LAVA.getDefaultState(); + if (waterBiomeNoise < waterBiomeThreshold) + lavaBlock = Blocks.WATER.getDefaultState(); + + // Determine cavern type for this column. Caverns generate at low altitudes only. + if (cavernBiomeNoise < lavaCavernThreshold) { + if (this.enableWaterBiomes && waterBiomeNoise < this.waterBiomeThreshold) { + // Generate water cavern in this column + cavernGen = this.cavernWater; } else { - // Generate floored cavern in this column - cavernGen = this.cavernFloored; - cavernBottomY = Configuration.caveSettings.flooredCavern.caveBottom; - cavernTopY = Configuration.caveSettings.flooredCavern.caveTop; + // Generate lava cavern in this column + cavernGen = this.cavernLava; } + // Water caverns use the same cave top/bottom as lava caverns + cavernBottomY = Configuration.caveSettings.lavaCavern.caveBottom; + cavernTopY = Configuration.caveSettings.lavaCavern.caveTop; + } else if (cavernBiomeNoise >= lavaCavernThreshold && cavernBiomeNoise <= flooredCavernThreshold) { + /* Similar to determining cave type above, we must check for values between the two adjusted + * thresholds, i.e. lavaCavernThreshold < noiseValue <= flooredCavernThreshold. + * In this case, we just continue generating the caves we were generating above, instead + * of generating a cavern. + */ + cavernGen = caveGen; + cavernBottomY = caveBottomY; + cavernTopY = caveBottomY; + } else { + // Generate floored cavern in this column + cavernGen = this.cavernFloored; + cavernBottomY = Configuration.caveSettings.flooredCavern.caveBottom; + cavernTopY = Configuration.caveSettings.flooredCavern.caveTop; + } - /* --------------- Dig out caves and caverns for this column --------------- */ - // Top (Cave) layer: - if (caveGen != null) - caveGen.generateColumn(chunkX, chunkZ, primer, localX, localZ, caveBottomY, maxSurfaceHeight, - maxSurfaceHeight, minSurfaceHeight, surfaceCutoff, lavaBlock); - // Bottom (Cavern) layer: - if (cavernGen != null) - cavernGen.generateColumn(chunkX, chunkZ, primer, localX, localZ, cavernBottomY, cavernTopY, - maxSurfaceHeight, minSurfaceHeight, surfaceCutoff, lavaBlock); + /* --------------- Dig out caves and caverns for this column --------------- */ + // Top (Cave) layer: + if (caveGen != null) + caveGen.generateColumn(chunkX, chunkZ, primer, localX, localZ, caveBottomY, maxSurfaceHeight, + maxSurfaceHeight, minSurfaceHeight, surfaceCutoff, lavaBlock); + // Bottom (Cavern) layer: + if (cavernGen != null) + cavernGen.generateColumn(chunkX, chunkZ, primer, localX, localZ, cavernBottomY, cavernTopY, + maxSurfaceHeight, minSurfaceHeight, surfaceCutoff, lavaBlock); - } } } } - } else // use vanilla generation in other dimensions - defaultCaveGen.generate(worldIn, chunkX, chunkZ, primer); + } } /** diff --git a/src/main/resources/app.properties b/src/main/resources/app.properties index 9b826dc..67cc4d3 100644 --- a/src/main/resources/app.properties +++ b/src/main/resources/app.properties @@ -1,7 +1,7 @@ ext { bc_modid = "bettercaves" bc_name = "YUNG's Better Caves" - bc_version = "1.12.2-1.0.3.1" + bc_version = "1.12.2-1.0.4.0-dev" bc_desc = "YUNG's Better Caves overhauls Vanilla Minecraft's cave generation, making caves much more structurally diverse and exciting!" bc_credits = "Thanks to superfluke's WorleyCaves code for some algorithmic insight, and TheMasterCaver for inspiration from his work." } \ No newline at end of file