From a077ec6c0e2880b177aa97cb4f58bd717290fba3 Mon Sep 17 00:00:00 2001 From: Harrison Date: Sun, 3 May 2020 17:49:48 -0500 Subject: [PATCH] Refactoring. --- ...reMapGenerator.java => TemperatureMap.java} | 8 ++++---- .../generation/IslandWorldChunkGenerator.java | 5 ++++- .../{ => biomes}/BiomeGenerator.java | 5 +++-- .../{ => biomes}/UniBiomeIslandGenerator.java | 5 +++-- .../generation/populators/TreePopulator.java | 18 ++++++++++++++++++ .../UniBiomeIslandGeneratorTest.java | 6 ++++-- 6 files changed, 36 insertions(+), 11 deletions(-) rename src/main/java/ca/recrown/islandsurvivalcraft/world/{generation/TemperatureMapGenerator.java => TemperatureMap.java} (85%) rename src/main/java/ca/recrown/islandsurvivalcraft/world/generation/{ => biomes}/BiomeGenerator.java (88%) rename src/main/java/ca/recrown/islandsurvivalcraft/world/generation/{ => biomes}/UniBiomeIslandGenerator.java (97%) create mode 100644 src/main/java/ca/recrown/islandsurvivalcraft/world/generation/populators/TreePopulator.java rename src/test/java/ca/recrown/islandsurvivalcraft/world/generation/{ => biomes}/UniBiomeIslandGeneratorTest.java (97%) diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/TemperatureMapGenerator.java b/src/main/java/ca/recrown/islandsurvivalcraft/world/TemperatureMap.java similarity index 85% rename from src/main/java/ca/recrown/islandsurvivalcraft/world/generation/TemperatureMapGenerator.java rename to src/main/java/ca/recrown/islandsurvivalcraft/world/TemperatureMap.java index 39acc84..2b899d2 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/TemperatureMapGenerator.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/world/TemperatureMap.java @@ -1,4 +1,4 @@ -package ca.recrown.islandsurvivalcraft.world.generation; +package ca.recrown.islandsurvivalcraft.world; import java.util.Random; @@ -7,18 +7,18 @@ import org.bukkit.util.noise.SimplexOctaveGenerator; import ca.recrown.islandsurvivalcraft.datatypes.Point2; import ca.recrown.islandsurvivalcraft.caching.Cache; -class TemperatureMapGenerator { +public class TemperatureMap { private final Cache temperatureCache; private final double frequency = 0.5D; private final double amplitude = 0.5D; private volatile SimplexOctaveGenerator noiseGenerator; - public TemperatureMapGenerator() { + public TemperatureMap() { temperatureCache = new Cache<>(1024); } - public TemperatureMapGenerator(long seed) { + public TemperatureMap(long seed) { this(); setSeed(seed); } diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/IslandWorldChunkGenerator.java b/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/IslandWorldChunkGenerator.java index d8ec9c5..90ad8ee 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/IslandWorldChunkGenerator.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/IslandWorldChunkGenerator.java @@ -23,6 +23,9 @@ import ca.recrown.islandsurvivalcraft.caching.Cache; import ca.recrown.islandsurvivalcraft.datatypes.Point2; import ca.recrown.islandsurvivalcraft.world.BiomeSelector; import ca.recrown.islandsurvivalcraft.world.IslandWorldMapper; +import ca.recrown.islandsurvivalcraft.world.TemperatureMap; +import ca.recrown.islandsurvivalcraft.world.generation.biomes.BiomeGenerator; +import ca.recrown.islandsurvivalcraft.world.generation.biomes.UniBiomeIslandGenerator; import ca.recrown.islandsurvivalcraft.world.shaders.WorldHeightShader; import ca.recrown.islandsurvivalcraft.world.shaders.WorldLayerShader; @@ -46,7 +49,7 @@ public class IslandWorldChunkGenerator extends ChunkGenerator implements Listene int maxHeight = world.getMaxHeight(); int seaLevel = world.getSeaLevel(); IslandWorldMapper mapper = new IslandWorldMapper(seed, blockValueCache); - TemperatureMapGenerator temperatureMapGenerator = new TemperatureMapGenerator(seed); + TemperatureMap temperatureMapGenerator = new TemperatureMap(seed); WorldHeightShader heightShader = new WorldHeightShader(seed, mapper, seaLevel, world.getMaxHeight(), 3); WorldLayerShader layerShader = new WorldLayerShader(seed, seaLevel, maxHeight, mapper); BiomeGenerator biomeGenerator = new UniBiomeIslandGenerator(); diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/BiomeGenerator.java b/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/biomes/BiomeGenerator.java similarity index 88% rename from src/main/java/ca/recrown/islandsurvivalcraft/world/generation/BiomeGenerator.java rename to src/main/java/ca/recrown/islandsurvivalcraft/world/generation/biomes/BiomeGenerator.java index f6e6583..07139f4 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/BiomeGenerator.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/biomes/BiomeGenerator.java @@ -1,4 +1,4 @@ -package ca.recrown.islandsurvivalcraft.world.generation; +package ca.recrown.islandsurvivalcraft.world.generation.biomes; import org.bukkit.World; import org.bukkit.block.Biome; @@ -7,6 +7,7 @@ import ca.recrown.islandsurvivalcraft.caching.Cache; import ca.recrown.islandsurvivalcraft.datatypes.Point2; import ca.recrown.islandsurvivalcraft.world.BiomeSelector; import ca.recrown.islandsurvivalcraft.world.IslandWorldMapper; +import ca.recrown.islandsurvivalcraft.world.TemperatureMap; public interface BiomeGenerator { @@ -28,5 +29,5 @@ public interface BiomeGenerator { * @param chunkGenCache Cache for whether or not the chunk is generated. * @param seed The seed to use for the biome for this column. */ - public void generateBiomeColumn(Biome[][][] chunkBiomeSets, World world, int chunkX, int chunkZ, int localX, int localZ, IslandWorldMapper mapper, BiomeSelector biomeSelector, TemperatureMapGenerator tempGenerator, Cache biomeCache, Cache chunkGenCache, long seed); + public void generateBiomeColumn(Biome[][][] chunkBiomeSets, World world, int chunkX, int chunkZ, int localX, int localZ, IslandWorldMapper mapper, BiomeSelector biomeSelector, TemperatureMap tempGenerator, Cache biomeCache, Cache chunkGenCache, long seed); } \ No newline at end of file diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/UniBiomeIslandGenerator.java b/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/biomes/UniBiomeIslandGenerator.java similarity index 97% rename from src/main/java/ca/recrown/islandsurvivalcraft/world/generation/UniBiomeIslandGenerator.java rename to src/main/java/ca/recrown/islandsurvivalcraft/world/generation/biomes/UniBiomeIslandGenerator.java index 40fe486..71230b2 100644 --- a/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/UniBiomeIslandGenerator.java +++ b/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/biomes/UniBiomeIslandGenerator.java @@ -1,4 +1,4 @@ -package ca.recrown.islandsurvivalcraft.world.generation; +package ca.recrown.islandsurvivalcraft.world.generation.biomes; import org.bukkit.World; import org.bukkit.block.Biome; @@ -12,10 +12,11 @@ import ca.recrown.islandsurvivalcraft.pathfinding.CoordinateTargetValidatable; import ca.recrown.islandsurvivalcraft.pathfinding.DepthFirstSearch; import ca.recrown.islandsurvivalcraft.world.BiomeSelector; import ca.recrown.islandsurvivalcraft.world.IslandWorldMapper; +import ca.recrown.islandsurvivalcraft.world.TemperatureMap; public class UniBiomeIslandGenerator implements BiomeGenerator { @Override - public void generateBiomeColumn(Biome[][][] chunkBiomeSets, World world, int chunkX, int chunkZ, int localX, int localZ, IslandWorldMapper mapper, BiomeSelector biomeSelector, TemperatureMapGenerator tempGen, Cache biomeCache, Cache chunkGenCache, long seed) { + public void generateBiomeColumn(Biome[][][] chunkBiomeSets, World world, int chunkX, int chunkZ, int localX, int localZ, IslandWorldMapper mapper, BiomeSelector biomeSelector, TemperatureMap tempGen, Cache biomeCache, Cache chunkGenCache, long seed) { int worldX = 16 * chunkX + localX; int worldZ = 16 * chunkZ + localZ; Point2 chunkCoords = Utilities.worldToChunkCoordinates(new Point2(worldX, worldZ)); diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/populators/TreePopulator.java b/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/populators/TreePopulator.java new file mode 100644 index 0000000..fd9318b --- /dev/null +++ b/src/main/java/ca/recrown/islandsurvivalcraft/world/generation/populators/TreePopulator.java @@ -0,0 +1,18 @@ +package ca.recrown.islandsurvivalcraft.world.generation.populators; + +import java.util.Random; + +import org.bukkit.Chunk; +import org.bukkit.World; +import org.bukkit.generator.BlockPopulator; + +public class TreePopulator extends BlockPopulator { + + @Override + public void populate(World world, Random random, Chunk source) { + if (random.nextBoolean()) { + + } + } + +} \ No newline at end of file diff --git a/src/test/java/ca/recrown/islandsurvivalcraft/world/generation/UniBiomeIslandGeneratorTest.java b/src/test/java/ca/recrown/islandsurvivalcraft/world/generation/biomes/UniBiomeIslandGeneratorTest.java similarity index 97% rename from src/test/java/ca/recrown/islandsurvivalcraft/world/generation/UniBiomeIslandGeneratorTest.java rename to src/test/java/ca/recrown/islandsurvivalcraft/world/generation/biomes/UniBiomeIslandGeneratorTest.java index 8e13010..a47fd29 100644 --- a/src/test/java/ca/recrown/islandsurvivalcraft/world/generation/UniBiomeIslandGeneratorTest.java +++ b/src/test/java/ca/recrown/islandsurvivalcraft/world/generation/biomes/UniBiomeIslandGeneratorTest.java @@ -1,4 +1,4 @@ -package ca.recrown.islandsurvivalcraft.world.generation; +package ca.recrown.islandsurvivalcraft.world.generation.biomes; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -23,6 +23,8 @@ import ca.recrown.islandsurvivalcraft.caching.Cache; import ca.recrown.islandsurvivalcraft.datatypes.Point2; import ca.recrown.islandsurvivalcraft.world.BiomeSelector; import ca.recrown.islandsurvivalcraft.world.IslandWorldMapper; +import ca.recrown.islandsurvivalcraft.world.TemperatureMap; +import ca.recrown.islandsurvivalcraft.world.generation.DummyWorld; @TestInstance(Lifecycle.PER_CLASS) public class UniBiomeIslandGeneratorTest { @@ -53,7 +55,7 @@ public class UniBiomeIslandGeneratorTest { public void generateBiome(int chunkX, int chunkZ) { IslandWorldMapper mapper = new IslandWorldMapper(SEED, blockValueCache); - TemperatureMapGenerator temperatureMapGenerator = new TemperatureMapGenerator(SEED); + TemperatureMap temperatureMapGenerator = new TemperatureMap(SEED); BiomeGenerator biomeGenerator = new UniBiomeIslandGenerator(); Biome[][][] biomes = new Biome[Utilities.CHUNK_SIZE][Utilities.CHUNK_SIZE][4];