Biome selector updates.
Now uses a given seed to produce a biome. Chooses the deep equivalent of a requested ocean given a parameter.
This commit is contained in:
parent
9aaaede19f
commit
085827264b
@ -10,12 +10,12 @@ import org.bukkit.block.Biome;
|
|||||||
import ca.recrown.islandsurvivalcraft.Utilities;
|
import ca.recrown.islandsurvivalcraft.Utilities;
|
||||||
|
|
||||||
public class BiomeSelector {
|
public class BiomeSelector {
|
||||||
private boolean initialized = false;
|
private volatile boolean initialized = false;
|
||||||
private final HashMap<Biome, Float> lands = new HashMap<>();
|
private final HashMap<Biome, Float> lands = new HashMap<>();
|
||||||
private HashMap<Float, ArrayList<Biome>> temperaturesForLand = new HashMap<>();
|
private volatile HashMap<Float, ArrayList<Biome>> temperaturesForLand = new HashMap<>();
|
||||||
private final HashMap<Float, ArrayList<Biome>> temperaturePartitionedLandBiomes = new HashMap<>();
|
private final HashMap<Float, ArrayList<Biome>> temperaturePartitionedLandBiomes = new HashMap<>();
|
||||||
private final HashMap<Biome, Float> oceans = new HashMap<>();
|
private final HashMap<Biome, Float> oceans = new HashMap<>();
|
||||||
private HashMap<Float, ArrayList<Biome>> temperaturesForOcean = new HashMap<>();
|
private volatile HashMap<Float, ArrayList<Biome>> temperaturesForOcean = new HashMap<>();
|
||||||
private final HashMap<Float, ArrayList<Biome>> temperaturePartitionedOceanBiomes = new HashMap<>();
|
private final HashMap<Float, ArrayList<Biome>> temperaturePartitionedOceanBiomes = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
@ -26,6 +26,7 @@ public class BiomeSelector {
|
|||||||
temperaturePartitionedLandBiomes.put(2f, new ArrayList<>());
|
temperaturePartitionedLandBiomes.put(2f, new ArrayList<>());
|
||||||
|
|
||||||
temperaturePartitionedOceanBiomes.put(0.00f, new ArrayList<>());
|
temperaturePartitionedOceanBiomes.put(0.00f, new ArrayList<>());
|
||||||
|
temperaturePartitionedOceanBiomes.put(0.3f, new ArrayList<>());
|
||||||
temperaturePartitionedOceanBiomes.put(0.5f, new ArrayList<>());
|
temperaturePartitionedOceanBiomes.put(0.5f, new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,17 +92,15 @@ public class BiomeSelector {
|
|||||||
private void registerOceanBiomeTemperatures() {
|
private void registerOceanBiomeTemperatures() {
|
||||||
oceans.put(Biome.WARM_OCEAN, 0.5f);
|
oceans.put(Biome.WARM_OCEAN, 0.5f);
|
||||||
oceans.put(Biome.LUKEWARM_OCEAN, 0.5f);
|
oceans.put(Biome.LUKEWARM_OCEAN, 0.5f);
|
||||||
oceans.put(Biome.DEEP_LUKEWARM_OCEAN, 0.5f);
|
oceans.put(Biome.OCEAN, 0.3f);
|
||||||
oceans.put(Biome.OCEAN, 0.5f);
|
oceans.put(Biome.COLD_OCEAN, 0.3f);
|
||||||
oceans.put(Biome.DEEP_OCEAN, 0.5f);
|
|
||||||
oceans.put(Biome.COLD_OCEAN, 0.5f);
|
|
||||||
oceans.put(Biome.DEEP_COLD_OCEAN, 0.5f);
|
|
||||||
oceans.put(Biome.FROZEN_OCEAN, 0f);
|
oceans.put(Biome.FROZEN_OCEAN, 0f);
|
||||||
oceans.put(Biome.DEEP_FROZEN_OCEAN, 0.5f);
|
|
||||||
temperaturesForOcean = Utilities.invertHashMap(oceans);
|
temperaturesForOcean = Utilities.invertHashMap(oceans);
|
||||||
for (Entry<Float, ArrayList<Biome>> entry : temperaturesForOcean.entrySet()) {
|
for (Entry<Float, ArrayList<Biome>> entry : temperaturesForOcean.entrySet()) {
|
||||||
if (entry.getKey() <= 0.00f) {
|
if (entry.getKey() <= 0.00f) {
|
||||||
temperaturePartitionedOceanBiomes.get(0.0f).addAll(entry.getValue());
|
temperaturePartitionedOceanBiomes.get(0.0f).addAll(entry.getValue());
|
||||||
|
} else if (entry.getKey() <= 0.3f) {
|
||||||
|
temperaturePartitionedOceanBiomes.get(0.3f).addAll(entry.getValue());
|
||||||
} else {
|
} else {
|
||||||
temperaturePartitionedOceanBiomes.get(0.5f).addAll(entry.getValue());
|
temperaturePartitionedOceanBiomes.get(0.5f).addAll(entry.getValue());
|
||||||
}
|
}
|
||||||
@ -188,9 +187,10 @@ public class BiomeSelector {
|
|||||||
/**
|
/**
|
||||||
* Randomly selects a land biome that fits in given temperature.
|
* Randomly selects a land biome that fits in given temperature.
|
||||||
* @param temperature Minecraft temperature to select biome from.
|
* @param temperature Minecraft temperature to select biome from.
|
||||||
|
* @param seed The seed to use to select the biome.
|
||||||
* @return The randomly selected biome.
|
* @return The randomly selected biome.
|
||||||
*/
|
*/
|
||||||
public Biome getLandBiome(float temperature, Random random) {
|
public Biome getLandBiome(float temperature, long seed) {
|
||||||
if (!initialized) throw new IllegalStateException("Biome selector is not initialized.");
|
if (!initialized) throw new IllegalStateException("Biome selector is not initialized.");
|
||||||
ArrayList<Biome> biomes = null;
|
ArrayList<Biome> biomes = null;
|
||||||
if (temperature <= 0.05f) {
|
if (temperature <= 0.05f) {
|
||||||
@ -202,25 +202,32 @@ public class BiomeSelector {
|
|||||||
} else {
|
} else {
|
||||||
biomes = temperaturePartitionedLandBiomes.get(2.00f);
|
biomes = temperaturePartitionedLandBiomes.get(2.00f);
|
||||||
}
|
}
|
||||||
|
Random random = new Random(seed);
|
||||||
return biomes.get((int) random.nextFloat() * biomes.size());
|
return biomes.get((int) random.nextFloat() * biomes.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Randomly selects an ocean biome that fits in given temperature.
|
* Randomly selects an ocean biome that fits in given temperature.
|
||||||
|
*
|
||||||
* @param temperature Minecraft temperature to select biome from.
|
* @param temperature Minecraft temperature to select biome from.
|
||||||
|
* @param isDeep If this ocean should be of the deep variant.
|
||||||
|
* @param seed The seed to use to select the biome.
|
||||||
* @return The randomly selected biome.
|
* @return The randomly selected biome.
|
||||||
*/
|
*/
|
||||||
public Biome getOceanBiome(float temperature, Random random) {
|
public Biome getOceanBiome(float temperature, boolean isDeep, long seed) {
|
||||||
if (!initialized) throw new IllegalStateException("Biome selector is not initialized.");
|
if (!initialized) throw new IllegalStateException("Biome selector is not initialized.");
|
||||||
ArrayList<Biome> biomes = null;
|
ArrayList<Biome> biomes = null;
|
||||||
if (temperature <= 0.00f) {
|
if (temperature <= 0.00f) {
|
||||||
biomes = temperaturePartitionedOceanBiomes.get(0.0f);
|
biomes = temperaturePartitionedOceanBiomes.get(0.0f);
|
||||||
|
} else if (temperature <= 0.3) {
|
||||||
|
biomes = temperaturePartitionedOceanBiomes.get(0.3f);
|
||||||
} else {
|
} else {
|
||||||
biomes = temperaturePartitionedOceanBiomes.get(0.5f);
|
biomes = temperaturePartitionedOceanBiomes.get(0.5f);
|
||||||
}
|
}
|
||||||
|
Random random = new Random(seed);
|
||||||
return biomes.get((int) random.nextFloat() * biomes.size());
|
Biome oceanBiome = biomes.get((int) random.nextFloat() * biomes.size());
|
||||||
|
if (isDeep) oceanBiome = Biome.valueOf("DEEP_" + oceanBiome.name());
|
||||||
|
return oceanBiome;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user