Finished untested biome per island generator.
This commit is contained in:
parent
44f183cca0
commit
5b0942202a
@ -1,53 +1,72 @@
|
|||||||
package ca.recrown.islandsurvivalcraft.worldgen;
|
package ca.recrown.islandsurvivalcraft.worldgen;
|
||||||
|
|
||||||
import java.util.Random;
|
import org.bukkit.World;
|
||||||
|
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||||
|
|
||||||
|
import ca.recrown.islandsurvivalcraft.islandbedrockmetadata.IslandMetadataType;
|
||||||
|
import ca.recrown.islandsurvivalcraft.islandbedrockmetadata.IslandOwnerMetadata;
|
||||||
|
import ca.recrown.islandsurvivalcraft.islandbedrockmetadata.IslandShoreBiomeMetadata;
|
||||||
|
import ca.recrown.islandsurvivalcraft.islandbedrockmetadata.IslandTUIDMetadata;
|
||||||
|
import ca.recrown.islandsurvivalcraft.islandbedrockmetadata.IslandTemperatureMetadata;
|
||||||
|
import ca.recrown.islandsurvivalcraft.IslandSurvivalCraft;
|
||||||
|
import ca.recrown.islandsurvivalcraft.islandbedrockmetadata.IslandBedrockMetadataHelper;
|
||||||
|
import ca.recrown.islandsurvivalcraft.islandbedrockmetadata.IslandMainBiomeMetadata;
|
||||||
|
import ca.recrown.islandsurvivalcraft.islandbedrockmetadata.IslandMetadataPack;
|
||||||
|
|
||||||
public class BiomePerIslandGenerator implements IslandBiomeGenerator {
|
public class BiomePerIslandGenerator implements IslandBiomeGenerator {
|
||||||
private boolean begun;
|
|
||||||
private IslandMapGenerator mapGenerator;
|
private IslandMapGenerator mapGenerator;
|
||||||
private Biome currentIslandBiome;
|
private Biome currentIslandBiome;
|
||||||
private float currentIslandTemperature;
|
private float currentIslandTemperature;
|
||||||
private Biome currentIslandShoreBiome;
|
private Biome currentIslandShoreBiome;
|
||||||
private BiomeSelector biomeSelector;
|
private BiomeSelector biomeSelector;
|
||||||
private Random random;
|
|
||||||
private int worldHeight;
|
private int worldHeight;
|
||||||
|
private World world;
|
||||||
|
private IslandBedrockMetadataHelper metadataHelper;
|
||||||
|
private TemperatureMapGenerator temperatureMapGenerator;
|
||||||
|
private String currentTUID;
|
||||||
|
private IslandSurvivalCraft plugin;
|
||||||
|
|
||||||
public BiomePerIslandGenerator(int buildHeight, IslandMapGenerator mapGenerator, Random random, BiomeSelector biomeSelector) {
|
public BiomePerIslandGenerator(IslandSurvivalCraft plugin, World world, IslandMapGenerator mapGenerator, BiomeSelector biomeSelector, TemperatureMapGenerator temperatureMapGenerator) {
|
||||||
this.worldHeight = buildHeight;
|
this.plugin = plugin;
|
||||||
|
this.temperatureMapGenerator = temperatureMapGenerator;
|
||||||
|
this.worldHeight = world.getMaxHeight();
|
||||||
this.mapGenerator = mapGenerator;
|
this.mapGenerator = mapGenerator;
|
||||||
this.random = random;
|
this.biomeSelector = biomeSelector;
|
||||||
}
|
this.world = world;
|
||||||
|
this.metadataHelper = new IslandBedrockMetadataHelper(plugin, world);
|
||||||
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) {
|
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 worldX = chunkX * 16 + localX;
|
||||||
int worldZ = chunkZ * 16 + localZ;
|
int worldZ = chunkZ * 16 + localZ;
|
||||||
|
|
||||||
|
if (mapGenerator.isIsland(worldX, worldZ)) {
|
||||||
|
IslandMetadataPack sameIslandPack = getSurroundingIslandData(world, worldX, worldZ);
|
||||||
|
if (sameIslandPack != null) {
|
||||||
|
//Old island
|
||||||
|
currentIslandBiome = sameIslandPack.mainBiomeMetadata.getMainBiome();
|
||||||
|
currentIslandShoreBiome = sameIslandPack.shoreBiomeMetadata.getShoreBiome();
|
||||||
|
currentIslandTemperature = sameIslandPack.temperatureMetadata.getTemperature();
|
||||||
|
currentTUID = sameIslandPack.islandTIUDMetadata.getIUID();
|
||||||
|
} else {
|
||||||
|
//New island
|
||||||
|
currentIslandTemperature = temperatureMapGenerator.getTemperature(worldX, worldZ);
|
||||||
|
currentIslandBiome = biomeSelector.getLandBiome(currentIslandTemperature);
|
||||||
|
currentIslandShoreBiome = biomeSelector.getShoreBiome(currentIslandBiome, currentIslandTemperature);
|
||||||
|
if (currentIslandShoreBiome == null) {
|
||||||
|
currentIslandShoreBiome = currentIslandBiome;
|
||||||
|
}
|
||||||
|
currentTUID = String.valueOf(worldX) + String.valueOf(worldZ);
|
||||||
|
}
|
||||||
|
//saving information
|
||||||
|
IslandMetadataPack current = new IslandMetadataPack();
|
||||||
|
current.setMainBiome(currentIslandBiome, plugin);
|
||||||
|
current.setTemperature(currentIslandTemperature, plugin);
|
||||||
|
current.setShoreBiome(currentIslandShoreBiome, plugin);
|
||||||
|
current.setTUID(currentTUID, plugin);
|
||||||
|
metadataHelper.setIslandBedrockMetadataPack(worldX, worldZ, current);
|
||||||
|
|
||||||
if (mapGenerator.isShore(worldX, worldZ)) {
|
if (mapGenerator.isShore(worldX, worldZ)) {
|
||||||
setBiome(localX, localZ, biome, currentIslandShoreBiome);
|
setBiome(localX, localZ, biome, currentIslandShoreBiome);
|
||||||
} else {
|
} else {
|
||||||
@ -55,6 +74,41 @@ public class BiomePerIslandGenerator implements IslandBiomeGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private IslandMetadataPack getSurroundingIslandData(World world, int worldX, int worldZ) {
|
||||||
|
IslandMetadataPack data = null;
|
||||||
|
if (mapGenerator.isSameIsland(worldX, worldZ, worldX + 1, worldZ)) {
|
||||||
|
data = getMetadataPackAt(worldX + 1, worldZ, world);
|
||||||
|
|
||||||
|
} else if (mapGenerator.isSameIsland(worldX, worldZ, worldX - 1, worldZ)) {
|
||||||
|
data = getMetadataPackAt(worldX - 1, worldZ, world);
|
||||||
|
|
||||||
|
} else if (mapGenerator.isSameIsland(worldX, worldZ, worldX, worldZ + 1)) {
|
||||||
|
data = getMetadataPackAt(worldX, worldZ + 1, world);
|
||||||
|
|
||||||
|
} else if (mapGenerator.isSameIsland(worldX, worldZ, worldX, worldZ - 1)) {
|
||||||
|
data = getMetadataPackAt(worldX, worldZ - 1, world);
|
||||||
|
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IslandMetadataPack getMetadataPackAt(int worldX, int worldZ, World world) {
|
||||||
|
IslandMetadataPack data = new IslandMetadataPack();
|
||||||
|
data.mainBiomeMetadata = (IslandMainBiomeMetadata) metadataHelper.getIslandBedrockMetadata(worldX, worldZ,
|
||||||
|
IslandMetadataType.mainBiome);
|
||||||
|
data.shoreBiomeMetadata = (IslandShoreBiomeMetadata) metadataHelper.getIslandBedrockMetadata(worldX, worldZ,
|
||||||
|
IslandMetadataType.shoreBiome);
|
||||||
|
data.temperatureMetadata = (IslandTemperatureMetadata) metadataHelper.getIslandBedrockMetadata(worldX, worldZ,
|
||||||
|
IslandMetadataType.temperature);
|
||||||
|
data.ownerMetadata = (IslandOwnerMetadata) metadataHelper.getIslandBedrockMetadata(worldX, worldZ,
|
||||||
|
IslandMetadataType.ownerUUID);
|
||||||
|
data.islandTIUDMetadata = (IslandTUIDMetadata) metadataHelper.getIslandBedrockMetadata(worldX, worldZ,
|
||||||
|
IslandMetadataType.TIUD);
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
private void setBiome(int localX, int localZ, BiomeGrid biomeGrid, Biome biome) {
|
private void setBiome(int localX, int localZ, BiomeGrid biomeGrid, Biome biome) {
|
||||||
for (int y = 0; y < worldHeight; y++) {
|
for (int y = 0; y < worldHeight; y++) {
|
||||||
biomeGrid.setBiome(localX, y, localZ, biome);
|
biomeGrid.setBiome(localX, y, localZ, biome);
|
||||||
|
@ -1,16 +1,8 @@
|
|||||||
package ca.recrown.islandsurvivalcraft.worldgen;
|
package ca.recrown.islandsurvivalcraft.worldgen;
|
||||||
|
|
||||||
import org.bukkit.block.Biome;
|
|
||||||
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
|
||||||
|
|
||||||
public interface IslandBiomeGenerator {
|
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);
|
public void GenerateBiome(int chunkX, int chunkZ, int localX, int localZ, BiomeGrid biome);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user