add extra bounds checks just in case
This commit is contained in:
parent
dc42f1d519
commit
b4cca80243
|
@ -80,13 +80,25 @@ public class SimpleBiomeMap implements BiomeMap {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Biome getCoast(Cell cell) {
|
public Biome getCoast(Cell cell) {
|
||||||
int inland = land.getSize(cell);
|
// treat land & coast biome-sets as one combined set
|
||||||
|
Biome[] inland = land.getSet(cell);
|
||||||
Biome[] coastal = coast.getSet(cell);
|
Biome[] coastal = coast.getSet(cell);
|
||||||
int total = inland + coastal.length;
|
|
||||||
int index = NoiseUtil.round((total - 1) * cell.biome);
|
// calculate where in the combined set the cell.biome points
|
||||||
if (index >= inland) {
|
int maxIndex = inland.length + coastal.length - 1;
|
||||||
return coastal[index - inland];
|
int index = NoiseUtil.round(maxIndex * cell.biome);
|
||||||
|
|
||||||
|
// if index lies within the coast section of the set
|
||||||
|
if (index >= inland.length) {
|
||||||
|
// relativize the index to start at 0
|
||||||
|
index -= inland.length;
|
||||||
|
|
||||||
|
// shouldn't be required but check that index is within bounds
|
||||||
|
if (index < coastal.length) {
|
||||||
|
return coastal[index];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return DefaultBiomes.NONE;
|
return DefaultBiomes.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,16 @@ public abstract class BiomeSet {
|
||||||
if (set.length == 0) {
|
if (set.length == 0) {
|
||||||
return defaultBiome.getDefaultBiome(cell.temperature);
|
return defaultBiome.getDefaultBiome(cell.temperature);
|
||||||
}
|
}
|
||||||
return set[NoiseUtil.round((set.length - 1) * cell.biome)];
|
|
||||||
|
int maxIndex = set.length - 1;
|
||||||
|
int index = NoiseUtil.round(maxIndex * cell.biome);
|
||||||
|
|
||||||
|
// shouldn't happen but safety check the bounds
|
||||||
|
if (index < 0 || index >= set.length) {
|
||||||
|
return defaultBiome.getDefaultBiome(cell.temperature);
|
||||||
|
}
|
||||||
|
|
||||||
|
return set[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract int getIndex(Cell cell);
|
public abstract int getIndex(Cell cell);
|
||||||
|
|
Loading…
Reference in New Issue