From 2ace74972e47525ac7f1195421242af6b45c66e4 Mon Sep 17 00:00:00 2001 From: Harrison Date: Sun, 19 Apr 2020 20:20:35 -0500 Subject: [PATCH] Added biome generator and interface. untested. --- .../worldgen/BiomePerIslandGenerator.java | 63 +++++++++++++++++++ .../worldgen/IslandBiomeGenerator.java | 16 +++++ 2 files changed, 79 insertions(+) create mode 100644 src/main/java/ca/recrown/islandsurvivalcraft/worldgen/BiomePerIslandGenerator.java create mode 100644 src/main/java/ca/recrown/islandsurvivalcraft/worldgen/IslandBiomeGenerator.java diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/worldgen/BiomePerIslandGenerator.java b/src/main/java/ca/recrown/islandsurvivalcraft/worldgen/BiomePerIslandGenerator.java new file mode 100644 index 0000000..06fb588 --- /dev/null +++ b/src/main/java/ca/recrown/islandsurvivalcraft/worldgen/BiomePerIslandGenerator.java @@ -0,0 +1,63 @@ +package ca.recrown.islandsurvivalcraft.worldgen; + +import java.util.Random; + +import org.bukkit.block.Biome; +import org.bukkit.generator.ChunkGenerator.BiomeGrid; + +public class BiomePerIslandGenerator implements IslandBiomeGenerator { + private boolean begun; + private IslandMapGenerator mapGenerator; + private Biome currentIslandBiome; + private float currentIslandTemperature; + private Biome currentIslandShoreBiome; + private BiomeSelector biomeSelector; + private Random random; + private int worldHeight; + + public BiomePerIslandGenerator(int buildHeight, IslandMapGenerator mapGenerator, Random random, BiomeSelector biomeSelector) { + this.worldHeight = buildHeight; + this.mapGenerator = mapGenerator; + this.random = random; + } + + public void beginIslandBiome() { + if (begun) throw new IllegalStateException("Already generating biome for one island! Remember to call endIslandBiome() when done with one island."); + begun = true; + currentIslandTemperature = random.nextFloat() * 2f - 1f; + currentIslandBiome = biomeSelector.getLandBiome(currentIslandTemperature); + currentIslandShoreBiome = biomeSelector.getShoreBiome(currentIslandBiome, currentIslandTemperature); + } + + public void endIslandBiome() { + if (!begun) throw new IllegalStateException("Can't end island biome as there wasn't one that was started."); + begun = false; + currentIslandBiome = null; + } + + public void setBiome(Biome biome) { + + } + + public void setTemperature(float temperature) { + + } + + public void GenerateBiome(int chunkX, int chunkZ, int localX, int localZ, BiomeGrid biome) { + if (!begun) throw new IllegalStateException("Please enclose this function call between beginning and ending a biome cycle."); + int worldX = chunkX * 16 + localX; + int worldZ = chunkZ * 16 + localZ; + + if (mapGenerator.isShore(worldX, worldZ)) { + setBiome(localX, localZ, biome, currentIslandShoreBiome); + } else { + setBiome(localX, localZ, biome, currentIslandBiome); + } + } + + private void setBiome(int localX, int localZ, BiomeGrid biomeGrid, Biome biome) { + for (int y = 0; y < worldHeight; y++) { + biomeGrid.setBiome(localX, y, localZ, biome); + } + } +} \ No newline at end of file diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/worldgen/IslandBiomeGenerator.java b/src/main/java/ca/recrown/islandsurvivalcraft/worldgen/IslandBiomeGenerator.java new file mode 100644 index 0000000..bbd9ebe --- /dev/null +++ b/src/main/java/ca/recrown/islandsurvivalcraft/worldgen/IslandBiomeGenerator.java @@ -0,0 +1,16 @@ +package ca.recrown.islandsurvivalcraft.worldgen; + +import org.bukkit.block.Biome; +import org.bukkit.generator.ChunkGenerator.BiomeGrid; + +public interface IslandBiomeGenerator { + public void beginIslandBiome(); + + public void endIslandBiome(); + + public void setBiome(Biome biome); + + public void setTemperature(float temperature); + + public void GenerateBiome(int chunkX, int chunkZ, int localX, int localZ, BiomeGrid biome); +}