From e306d828e90327ba6e96bd70923832b10ecdfc83 Mon Sep 17 00:00:00 2001 From: Harrison Date: Tue, 21 Apr 2020 19:31:09 -0500 Subject: [PATCH] Added the shape shader, also refactored. --- ...er.java => IslandWorldBaseTerrainMap.java} | 4 +- .../world/IslandWorldGenerator.java | 4 +- .../generation/BiomePerIslandGenerator.java | 8 +-- .../generation/IslandBiomeGenerator.java | 4 +- .../world/shapers/IslandShaper.java | 5 -- .../world/shapers/WorldShapeShader.java | 67 +++++++++++++++++++ 6 files changed, 77 insertions(+), 15 deletions(-) rename src/main/java/ca/recrown/islandsurvivalcraft/world/{IslandLocationMapper.java => IslandWorldBaseTerrainMap.java} (97%) delete mode 100644 src/main/java/ca/recrown/islandsurvivalcraft/world/shapers/IslandShaper.java create mode 100644 src/main/java/ca/recrown/islandsurvivalcraft/world/shapers/WorldShapeShader.java diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/world/IslandLocationMapper.java b/src/main/java/ca/recrown/islandsurvivalcraft/world/IslandWorldBaseTerrainMap.java similarity index 97% rename from src/main/java/ca/recrown/islandsurvivalcraft/world/IslandLocationMapper.java rename to src/main/java/ca/recrown/islandsurvivalcraft/world/IslandWorldBaseTerrainMap.java index 9f0eb2d..026a0fc 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/world/IslandLocationMapper.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/world/IslandWorldBaseTerrainMap.java @@ -7,7 +7,7 @@ import org.bukkit.util.noise.SimplexOctaveGenerator; import ca.recrown.islandsurvivalcraft.pathfinding.CoordinateValidatable; import ca.recrown.islandsurvivalcraft.pathfinding.DepthFirstSearch; -public class IslandLocationMapper implements CoordinateValidatable { +public class IslandWorldBaseTerrainMap implements CoordinateValidatable { private SimplexOctaveGenerator noiseGenerator; private final int noiseOctaves = 8; private final int islandGenerationPercent = 47; @@ -21,7 +21,7 @@ public class IslandLocationMapper implements CoordinateValidatable { private int shallowDepth; private final DepthFirstSearch dfs; - public IslandLocationMapper(Random random, int seaLevel, int shallowDepth) { + public IslandWorldBaseTerrainMap(Random random, int seaLevel, int shallowDepth) { dfs = new DepthFirstSearch(this); this.seaLevel = seaLevel; this.shallowDepth = shallowDepth; diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/world/IslandWorldGenerator.java b/src/main/java/ca/recrown/islandsurvivalcraft/world/IslandWorldGenerator.java index 5a26d80..eec0cc2 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/world/IslandWorldGenerator.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/world/IslandWorldGenerator.java @@ -20,7 +20,7 @@ public class IslandWorldGenerator { private final IslandBiomeGenerator biomeGenerator; public final World world; - public final IslandLocationMapper islandMapGenerator; + public final IslandWorldBaseTerrainMap islandMapGenerator; public final Random random; public IslandWorldGenerator(World world, IslandBiomeGenerator generator, Random random) { @@ -29,7 +29,7 @@ public class IslandWorldGenerator { this.random = random; this.biomeSelector = new BiomeSelector(random); this.bedrockGenerator = new BedrockGenerator(random); - this.islandMapGenerator = new IslandLocationMapper(random, world.getSeaLevel(), 4); + this.islandMapGenerator = new IslandWorldBaseTerrainMap(random, world.getSeaLevel(), 4); this.biomeGenerator = generator; biomeSelector.initialize(); } diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/BiomePerIslandGenerator.java b/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/BiomePerIslandGenerator.java index a97f6f0..167eb0d 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/BiomePerIslandGenerator.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/BiomePerIslandGenerator.java @@ -7,11 +7,11 @@ import org.bukkit.generator.ChunkGenerator.BiomeGrid; import ca.recrown.islandsurvivalcraft.pathfinding.CoordinateTargetValidatable; import ca.recrown.islandsurvivalcraft.pathfinding.DepthFirstSearch; import ca.recrown.islandsurvivalcraft.world.BiomeSelector; -import ca.recrown.islandsurvivalcraft.world.IslandLocationMapper; +import ca.recrown.islandsurvivalcraft.world.IslandWorldBaseTerrainMap; public class BiomePerIslandGenerator implements IslandBiomeGenerator, CoordinateTargetValidatable { private boolean initialized; - private IslandLocationMapper islandLocator; + private IslandWorldBaseTerrainMap islandLocator; private BiomeSelector biomeSelector; private TemperatureMapGenerator temperatureMapGenerator; private int buildHeight; @@ -30,7 +30,7 @@ public class BiomePerIslandGenerator implements IslandBiomeGenerator, Coordinate } @Override - public void initialize(World world, IslandLocationMapper mapGenerator, BiomeSelector biomeSelector) { + public void initialize(World world, IslandWorldBaseTerrainMap mapGenerator, BiomeSelector biomeSelector) { if (initialized) throw new IllegalStateException("Biome generator already initialized."); initialized = true; this.islandLocator = mapGenerator; @@ -92,7 +92,7 @@ public class BiomePerIslandGenerator implements IslandBiomeGenerator, Coordinate Biome designatedBiome = mainBiome; if (mainBiome == null) { - designatedBiome = Biome.OCEAN; + designatedBiome = biomeSelector.getOceanBiome(temperatureMapGenerator.getTemperature(worldX, worldZ)); } else if (islandLocator.isShore(worldX, worldZ)) { designatedBiome = shoreBiome; } diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/IslandBiomeGenerator.java b/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/IslandBiomeGenerator.java index 041b3fa..f9465e3 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/IslandBiomeGenerator.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/IslandBiomeGenerator.java @@ -5,10 +5,10 @@ import org.bukkit.block.Biome; import org.bukkit.generator.ChunkGenerator.BiomeGrid; import ca.recrown.islandsurvivalcraft.world.BiomeSelector; -import ca.recrown.islandsurvivalcraft.world.IslandLocationMapper; +import ca.recrown.islandsurvivalcraft.world.IslandWorldBaseTerrainMap; public interface IslandBiomeGenerator { - public void initialize(World world, IslandLocationMapper mapGenerator, BiomeSelector biome); + public void initialize(World world, IslandWorldBaseTerrainMap mapGenerator, BiomeSelector biome); public void GenerateBiome(int chunkX, int chunkZ, int localX, int localZ, BiomeGrid biomeGrid); public IslandBiomeGenerator getInstance(); } diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/world/shapers/IslandShaper.java b/src/main/java/ca/recrown/islandsurvivalcraft/world/shapers/IslandShaper.java deleted file mode 100644 index 0dc689b..0000000 --- a/src/main/java/ca/recrown/islandsurvivalcraft/world/shapers/IslandShaper.java +++ /dev/null @@ -1,5 +0,0 @@ -package ca.recrown.islandsurvivalcraft.world.shapers; - -public class IslandShaper { - -} \ No newline at end of file diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/world/shapers/WorldShapeShader.java b/src/main/java/ca/recrown/islandsurvivalcraft/world/shapers/WorldShapeShader.java new file mode 100644 index 0000000..48314e3 --- /dev/null +++ b/src/main/java/ca/recrown/islandsurvivalcraft/world/shapers/WorldShapeShader.java @@ -0,0 +1,67 @@ +package ca.recrown.islandsurvivalcraft.world.shapers; + +import java.util.Random; + +import org.bukkit.block.Biome; +import org.bukkit.util.noise.SimplexOctaveGenerator; + +import ca.recrown.islandsurvivalcraft.world.IslandWorldBaseTerrainMap; + +public class WorldShapeShader { + private Random random; + private SimplexOctaveGenerator noiseGenerator; + private IslandWorldBaseTerrainMap islandLocator; + private final float probabilityOfAdditive = 0.75f; + + public WorldShapeShader(long seed, IslandWorldBaseTerrainMap islandLocator) { + random = new Random(seed); + noiseGenerator = new SimplexOctaveGenerator(random, 2); + noiseGenerator.setScale(0.05D); + this.islandLocator = islandLocator; + } + + public int getAltitude(int worldX, int worldZ, Biome biome) { + double modifier = getHeightModifier(worldX, worldZ); + int baseValue = islandLocator.getBaseTerrainHeight(worldX, worldZ); + int height = 0; + String biomeName = biome.name(); + if (biomeName.contains("hills")) { + height = (int) (modifier * 40D + baseValue); + } else if (biomeName.contains("mountains")) { + height = (int) (modifier * 70D + baseValue); + } else if (biomeName.contains("plateau")) { + height = (int) (Math.min(60, Math.max(2, modifier * 80D)) + baseValue); + } else if (biomeName.contains("modified")) { + height = (int) (modifier * 50D + baseValue); + } else if (biomeName.contains("shattered")) { + height = (int) (modifier * 60D + baseValue); + } else if (biomeName.contains("tall")) { + height = (int) (modifier * 55D + baseValue); + } else if (!biomeName.contains("ocean")) { + height = (int) (getNormalizedHeightModifier(worldX, worldZ) * 20D + baseValue); + } else { + height = (int) (getNormalizedHeightModifier(worldX, worldZ) * 10D + baseValue); + } + return height; + } + + private double getHeightModifier(int worldX, int worldZ) { + return (2 * probabilityOfAdditive - noiseGenerator.noise(worldX, worldZ, 0.5D, 0.5D, true)); + } + + private double maxHeightModifier() { + return 2 * probabilityOfAdditive + 1; + } + + private double minHeightModifier() { + return 2 * probabilityOfAdditive - 1; + } + + private double getNormalizedHeightModifier(int worldX, int worldZ) { + double heightModifier = getHeightModifier(worldX, worldZ); + if (heightModifier > 0) { + return heightModifier / maxHeightModifier(); + } + return minHeightModifier(); + } + } \ No newline at end of file