Preserve trapezoid height plateaus
This commit is contained in:
parent
4fa0a5e554
commit
2cf6ab4775
2 changed files with 62 additions and 11 deletions
|
|
@ -2,10 +2,35 @@ package worldgen
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTrapezoidPlateauDiagnostic(t *testing.T) {
|
||||
if os.Getenv("REGIONIO_TRAPEZOID_DIAGNOSTIC") != "1" {
|
||||
t.Skip("set REGIONIO_TRAPEZOID_DIAGNOSTIC=1 to list non-zero height plateaus")
|
||||
}
|
||||
set, err := LoadFeatureSet()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for name, placed := range set.Placed {
|
||||
for _, modifier := range placed.Placement {
|
||||
if modifier.Type != "minecraft:height_range" {
|
||||
continue
|
||||
}
|
||||
plan, err := placementHeightPlan(modifier.Raw)
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %v", name, err)
|
||||
}
|
||||
if plan.HeightDistribution == "minecraft:trapezoid" && plan.HeightPlateau != 0 {
|
||||
t.Logf("%s plateau=%d", name, plan.HeightPlateau)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeatureDatapackLoadsAndLinks(t *testing.T) {
|
||||
set, err := LoadFeatureSet()
|
||||
if err != nil {
|
||||
|
|
@ -157,6 +182,27 @@ func TestVeryBiasedToBottomConsumesVanillaDraws(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTrapezoidHeightHonorsPlateau(t *testing.T) {
|
||||
plan := PlacementPlan{
|
||||
HeightDistribution: "minecraft:trapezoid",
|
||||
HeightPlateau: 4,
|
||||
MinY: HeightProvider{Absolute: intPtr(0)},
|
||||
MaxY: HeightProvider{Absolute: intPtr(20)},
|
||||
}
|
||||
gotRandom := NewLegacy(12345)
|
||||
wantRandom := NewLegacy(12345)
|
||||
for sample := 0; sample < 16; sample++ {
|
||||
left := (20 - 4) / 2
|
||||
want := int(wantRandom.NextIntN(int32(20-left+1))) + int(wantRandom.NextIntN(int32(left+1)))
|
||||
if got := plan.SampleY(gotRandom, 0, 21); got != want {
|
||||
t.Fatalf("sample %d = %d, want %d", sample, got, want)
|
||||
}
|
||||
}
|
||||
if got, want := gotRandom.NextLong(), wantRandom.NextLong(); got != want {
|
||||
t.Fatalf("random state after samples = %d, want %d", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlacementPositionsPreservesModifierOrder(t *testing.T) {
|
||||
modifier := func(raw string) PlacementModifier {
|
||||
var value PlacementModifier
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue