Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Loading