Skip to content

Commit

Permalink
Add option for blacklisted dimensions #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Young committed Sep 24, 2019
1 parent 5bcf200 commit 3940e3d
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/app.properties
Original file line number Diff line number Diff line change
@@ -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."
}

0 comments on commit 3940e3d

Please sign in to comment.