diff --git a/src/main/java/world/bentobox/boxed/generators/biomes/AbstractSeedBiomeProvider.java b/src/main/java/world/bentobox/boxed/generators/biomes/AbstractSeedBiomeProvider.java index 18697d0..1e536ba 100644 --- a/src/main/java/world/bentobox/boxed/generators/biomes/AbstractSeedBiomeProvider.java +++ b/src/main/java/world/bentobox/boxed/generators/biomes/AbstractSeedBiomeProvider.java @@ -264,16 +264,17 @@ public static Biome getBiome(int h, int t, double we) { } /** - * Continental location by continentalness + * Continental location by continentalness. The outer bands are open-ended because + * vanilla noise can fall outside the nominal [-1.2, 1.0] range. */ - private enum ContLoc { - MUSHROOM_FIELDS(-1.2, -1.05), + enum ContLoc { + MUSHROOM_FIELDS(Double.NEGATIVE_INFINITY, -1.05), DEEP_OCEAN(-1.05, -0.455), OCEAN(-0.455, -0.19), COAST(-0.19, -0.11), NEAR_INLAND(-0.11, 0.03), MID_INLAND(0.03, 0.3), - FAR_INLAND(0.3, 10.0); + FAR_INLAND(0.3, Double.POSITIVE_INFINITY); private double min; private double max; @@ -283,7 +284,7 @@ private enum ContLoc { this.max = max; } - public static ContLoc getCont(double continentalness) { + static ContLoc getCont(double continentalness) { for (ContLoc c : ContLoc.values()) { if (continentalness >= c.min && continentalness < c.max) { return c; diff --git a/src/test/java/world/bentobox/boxed/generators/biomes/ContLocTest.java b/src/test/java/world/bentobox/boxed/generators/biomes/ContLocTest.java new file mode 100644 index 0000000..88a8187 --- /dev/null +++ b/src/test/java/world/bentobox/boxed/generators/biomes/ContLocTest.java @@ -0,0 +1,38 @@ +package world.bentobox.boxed.generators.biomes; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +import world.bentobox.boxed.generators.biomes.AbstractSeedBiomeProvider.ContLoc; + +/** + * Tests {@link ContLoc#getCont(double)} band lookup, including values outside the nominal + * continentalness range that vanilla noise can produce. + */ +class ContLocTest { + + @Test + void testBelowNominalRangeIsMushroomFields() { + // Value seen in the wild that used to throw "contloc out of spec" + assertEquals(ContLoc.MUSHROOM_FIELDS, ContLoc.getCont(-1.2687000036239624)); + assertEquals(ContLoc.MUSHROOM_FIELDS, ContLoc.getCont(-100D)); + } + + @Test + void testAboveNominalRangeIsFarInland() { + assertEquals(ContLoc.FAR_INLAND, ContLoc.getCont(10D)); + assertEquals(ContLoc.FAR_INLAND, ContLoc.getCont(100D)); + } + + @Test + void testBandBoundaries() { + assertEquals(ContLoc.MUSHROOM_FIELDS, ContLoc.getCont(-1.2)); + assertEquals(ContLoc.DEEP_OCEAN, ContLoc.getCont(-1.05)); + assertEquals(ContLoc.OCEAN, ContLoc.getCont(-0.455)); + assertEquals(ContLoc.COAST, ContLoc.getCont(-0.19)); + assertEquals(ContLoc.NEAR_INLAND, ContLoc.getCont(-0.11)); + assertEquals(ContLoc.MID_INLAND, ContLoc.getCont(0.03)); + assertEquals(ContLoc.FAR_INLAND, ContLoc.getCont(0.3)); + } +}