Added biome generator and interface.
untested.
This commit is contained in:
parent
3c41444dfa
commit
2ace74972e
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user