Try to make climate layer generation more robust (and catch an annoying bug)

This commit is contained in:
Cheeserolls 2017-05-18 11:43:03 +01:00
parent 406dd93a2f
commit 553641d9bb
4 changed files with 39 additions and 19 deletions

View file

@ -128,7 +128,7 @@ public class BiomeProviderBOP extends BiomeProvider
}
// superimpose hot and cold regions an a land and sea layer
public static GenLayer climateLayer(BOPWorldSettings settings, long worldSeed)
public static GenLayerClimate climateLayer(BOPWorldSettings settings, long worldSeed)
{
GenLayer temperature;
switch(settings.tempScheme)
@ -167,12 +167,12 @@ public class BiomeProviderBOP extends BiomeProvider
break;
}
GenLayer climate = new GenLayerClimate(103L, temperature, rainfall);
GenLayerClimate climate = new GenLayerClimate(103L, temperature, rainfall);
// stack = new GenLayerEdge(3L, stack, GenLayerEdge.Mode.SPECIAL);
return climate;
}
public static GenLayer allocateBiomes(long worldSeed, BOPWorldSettings settings, GenLayer mainBranch, GenLayer subBiomesInit, GenLayer climateLayer)
public static GenLayer allocateBiomes(long worldSeed, BOPWorldSettings settings, GenLayer mainBranch, GenLayer subBiomesInit, GenLayerClimate climateLayer)
{
// allocate the basic biomes
GenLayer biomesLayer = new GenLayerBiomeBOP(200L, mainBranch, climateLayer, settings);
@ -180,16 +180,16 @@ public class BiomeProviderBOP extends BiomeProvider
// magnify everything (using the same seed)
biomesLayer = new GenLayerZoom(1000L, biomesLayer);
subBiomesInit = new GenLayerZoom(1000L, subBiomesInit);
climateLayer = new GenLayerZoom(1000L, climateLayer);
GenLayer climateLayerZoomed = new GenLayerZoom(1000L, climateLayer);
// add medium islands
switch(settings.landScheme)
{
case ARCHIPELAGO:
biomesLayer = new GenLayerBiomeIslands(15L, biomesLayer, climateLayer, 4);
biomesLayer = new GenLayerBiomeIslands(15L, biomesLayer, climateLayerZoomed, 4);
break;
case CONTINENTS:
biomesLayer = new GenLayerBiomeIslands(15L, biomesLayer, climateLayer, 60);
biomesLayer = new GenLayerBiomeIslands(15L, biomesLayer, climateLayerZoomed, 60);
break;
case VANILLA: default:
break;
@ -198,7 +198,7 @@ public class BiomeProviderBOP extends BiomeProvider
// magnify everything again (using the same seed)
biomesLayer = new GenLayerZoom(1000L, biomesLayer);
subBiomesInit = new GenLayerZoom(1000L, subBiomesInit);
climateLayer = new GenLayerZoom(1000L, climateLayer);
climateLayerZoomed = new GenLayerZoom(1000L, climateLayerZoomed);
// add edge biomes
biomesLayer = new GenLayerBiomeEdgeBOP(1000L, biomesLayer);
@ -210,13 +210,13 @@ public class BiomeProviderBOP extends BiomeProvider
switch(settings.landScheme)
{
case ARCHIPELAGO:
biomesLayer = new GenLayerBiomeIslands(15L, biomesLayer, climateLayer, 8);
biomesLayer = new GenLayerBiomeIslands(15L, biomesLayer, climateLayerZoomed, 8);
break;
case CONTINENTS:
biomesLayer = new GenLayerBiomeIslands(15L, biomesLayer, climateLayer, 60);
biomesLayer = new GenLayerBiomeIslands(15L, biomesLayer, climateLayerZoomed, 60);
break;
case VANILLA: default:
biomesLayer = new GenLayerBiomeIslands(15L, biomesLayer, climateLayer, 12);
biomesLayer = new GenLayerBiomeIslands(15L, biomesLayer, climateLayerZoomed, 12);
break;
}
@ -242,7 +242,7 @@ public class BiomeProviderBOP extends BiomeProvider
GenLayer riversAndSubBiomesInit = new GenLayerRiverInit(100L, mainBranch);
// create climate layer
GenLayer climateLayer = climateLayer(settings, worldSeed);
GenLayerClimate climateLayer = climateLayer(settings, worldSeed);
// allocate the biomes
mainBranch = allocateBiomes(worldSeed, settings, mainBranch, riversAndSubBiomesInit, climateLayer);

View file

@ -23,9 +23,9 @@ public class GenLayerBiomeBOP extends BOPGenLayer
private BOPWorldSettings settings;
private GenLayer landMassLayer;
private GenLayer climateLayer;
private GenLayerClimate climateLayer;
public GenLayerBiomeBOP(long seed, GenLayer landMassLayer, GenLayer climateLayer, BOPWorldSettings settings)
public GenLayerBiomeBOP(long seed, GenLayer landMassLayer, GenLayerClimate climateLayer, BOPWorldSettings settings)
{
super(seed);
this.landMassLayer = landMassLayer;
@ -51,7 +51,18 @@ public class GenLayerBiomeBOP extends BOPGenLayer
int index = z + x * areaWidth;
this.initChunkSeed((long)(z + areaX), (long)(x + areaY));
int landSeaVal = landSeaValues[index];
BOPClimates climate = BOPClimates.lookup(climateValues[index]);
int climateOrdinal = climateValues[index];
BOPClimates climate;
try {
climate = BOPClimates.lookup(climateOrdinal);
} catch (java.lang.ArrayIndexOutOfBoundsException e) {
// This shouldn't happen - but apparently it (rarely) does (https://github.com/Glitchfiend/BiomesOPlenty/issues/983)
// If it does it means that something weird happened with the climate layer / lookup
// Rethrow with hopefully a more useful message
String msg = "Climate lookup failed climateOrdinal: " + climateOrdinal + " climate layer mapping: " + climateLayer.debugClimateMappingInts();
throw new java.lang.RuntimeException(msg,e);
}
// At this point, oceans and land have been assigned, and so have mushroom islands
if (landSeaVal == Biome.getIdForBiome(Biomes.DEEP_OCEAN))

View file

@ -1,5 +1,7 @@
package biomesoplenty.common.world.layer;
import java.util.Arrays;
import biomesoplenty.api.enums.BOPClimates;
import biomesoplenty.api.generation.BOPGenLayer;
import net.minecraft.util.math.MathHelper;
@ -28,13 +30,20 @@ public class GenLayerClimate extends BOPGenLayer {
for (int i = 0; i < areaWidth * areaHeight; ++i)
{
int index = (temperatureValues[i] * 12) + rainfallValues[i];
// temperature values from 0 (cold) to 8 (hot) and rainfall values from 0 (wet) to 11 (dry), index is (temperatureValue * 12) + rainfallValue
// index is clamped to account for potential rounding errors due to use of doubles/floats
out[i] = this.climateMapping[MathHelper.clamp(index, 0, this.climateMapping.length - 1)];
// clamp as a precaution against potential rounding errors due to use of doubles/floats in noise calculations
// this guarantees index is between 0 and 108 (= 9 * 12), the range of indexes in BOPClimates.getClimateMappingInts()
int index = ( MathHelper.clamp(temperatureValues[i], 0, 8) * 12 ) + MathHelper.clamp(rainfallValues[i], 0, 11);
out[i] = this.climateMapping[index];
}
return out;
}
// debug method added to assist in troubleshooting a specific bug (https://github.com/Glitchfiend/BiomesOPlenty/issues/983)
public String debugClimateMappingInts()
{
return Arrays.toString(this.climateMapping);
}
}

View file

@ -48,7 +48,7 @@ public class GenLayerTemperatureLatitude extends BOPGenLayer
this.initChunkSeed((long)X, (long)Y);
// set value between 1 and 4 which is periodic in Y (with some random variation)
// set value between 0 and 8 which is periodic in Y (with some random variation)
// ocean generally stays as ocean, unless it's ICY when it becomes frozen ocean
double Yoffset = Y + this.offset + ((this.nextInt(1001) - 500) * this.offsetVariation / 500.0D);
out[x + y * areaWidth] = MathHelper.floor(this.amplitude * Math.abs((Math.abs(Yoffset % period) - halfPeriod)));