Skip to content

Commit

Permalink
Rename Water Region stuff to Liquid Region.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Young committed Feb 7, 2021
1 parent b526fb3 commit 3ce876d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,36 @@
import java.util.Objects;
import java.util.Random;

public class WaterRegionController {
private FastNoise waterRegionController;
public class LiquidRegionController {
private FastNoise liquidRegionSampler;
private ISeedReader world;
private String dimensionName;
private Random rand;

// Vars determined from config
private BlockState lavaBlock;
private BlockState waterBlock;
private float waterRegionThreshold;
private float liquidRegionThreshold;

// Constants
private static final float SMOOTH_RANGE = .04f;
private static final float SMOOTH_DELTA = .01f;

public WaterRegionController(ISeedReader worldIn, ConfigHolder config) {
public LiquidRegionController(ISeedReader worldIn, ConfigHolder config) {
this.world = worldIn;
this.dimensionName = Objects.requireNonNull(world.getWorld().getDimensionKey().getLocation()).toString();
this.rand = new Random();

// Vars from config
lavaBlock = getLavaBlockFromString(config.lavaBlock.get());
waterBlock = getWaterBlockFromString(config.waterBlock.get());
waterRegionThreshold = NoiseUtils.simplexNoiseOffsetByPercent(-1f, config.waterRegionSpawnChance.get().floatValue() / 100f);
liquidRegionThreshold = NoiseUtils.simplexNoiseOffsetByPercent(-1f, config.waterRegionSpawnChance.get().floatValue() / 100f);

// Water region controller
// Liquid region sampler
float waterRegionSize = config.cavernRegionSize.get().equals("ExtraLarge") ? .001f : .004f;
waterRegionController = new FastNoise();
waterRegionController.SetSeed((int) world.getSeed() + 444);
waterRegionController.SetFrequency(waterRegionSize);
liquidRegionSampler = new FastNoise();
liquidRegionSampler.SetSeed((int) world.getSeed() + 444);
liquidRegionSampler.SetFrequency(waterRegionSize);
}

public BlockState[][] getLiquidBlocksForChunk(int chunkX, int chunkZ) {
Expand All @@ -61,14 +61,14 @@ public BlockState[][] getLiquidBlocksForChunk(int chunkX, int chunkZ) {

private BlockState getLiquidBlockAtPos(Random rand, ColPos colPos) {
BlockState liquidBlock = lavaBlock;
if (waterRegionThreshold > -1f) { // Don't bother calculating noise if water regions are disabled
float waterRegionNoise = waterRegionController.GetNoise(colPos.getX(), colPos.getZ());
if (liquidRegionThreshold > -1f) { // Don't bother calculating noise if water regions are disabled
float liquidRegionNoise = liquidRegionSampler.GetNoise(colPos.getX(), colPos.getZ());

// If water region threshold check is passed, change liquid block to water
float randOffset = rand.nextFloat() * SMOOTH_DELTA + SMOOTH_RANGE;
if (waterRegionNoise < waterRegionThreshold - randOffset)
if (liquidRegionNoise < liquidRegionThreshold - randOffset)
liquidBlock = waterBlock;
else if (waterRegionNoise < waterRegionThreshold + randOffset)
else if (liquidRegionNoise < liquidRegionThreshold + randOffset)
liquidBlock = null;
}
return liquidBlock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class MasterController {
// Controllers
private CaveCarverController caveCarverController;
private CavernCarverController cavernCarverController;
private WaterRegionController waterRegionController;
private LiquidRegionController liquidRegionController;
private RavineCarverController ravineCarverController;

public boolean carveRegion(IChunk chunkIn, Function<BlockPos, Biome> biomePos, int chunkX, int chunkZ, BitSet airCarvingMask, BitSet liquidCarvingMask) {
Expand All @@ -46,7 +46,7 @@ public boolean carveRegion(IChunk chunkIn, Function<BlockPos, Biome> biomePos, i
}

// Determine liquid blocks for this chunk
BlockState[][] liquidBlocks = waterRegionController.getLiquidBlocksForChunk(chunkX, chunkZ);
BlockState[][] liquidBlocks = liquidRegionController.getLiquidBlocksForChunk(chunkX, chunkZ);

// Carve chunk
ravineCarverController.carveChunk(chunkIn, chunkX, chunkZ, liquidBlocks, biomePos, airCarvingMask, liquidCarvingMask);
Expand Down Expand Up @@ -77,7 +77,7 @@ public void initialize(ISeedReader worldIn) {
// Initialize controllers
this.caveCarverController = new CaveCarverController(worldIn, configHolder);
this.cavernCarverController = new CavernCarverController(worldIn, configHolder);
this.waterRegionController = new WaterRegionController(worldIn, configHolder);
this.liquidRegionController = new LiquidRegionController(worldIn, configHolder);
this.ravineCarverController = new RavineCarverController(worldIn, configHolder);

BetterCaves.LOGGER.debug(String.format("BETTER CAVES WORLD CARVER INITIALIZED WITH SEED %d IN %s", seed, dimensionName));
Expand All @@ -90,7 +90,7 @@ public void setWorld(ISeedReader worldIn) {
this.world = worldIn;
this.caveCarverController.setWorld(worldIn);
this.cavernCarverController.setWorld(worldIn);
this.waterRegionController.setWorld(worldIn);
this.liquidRegionController.setWorld(worldIn);
this.ravineCarverController.setWorld(worldIn);
}

Expand Down

0 comments on commit 3ce876d

Please sign in to comment.