Resolve block names to the default state, not the first one

blocks.json lists a block's states in getPossibleStates() order -- the property
cartesian product -- and separately marks which one is the default. The parser
declared only id and properties, so the default flag was dropped on the floor
and nameToStateID returned states[0]. Those differ for 642 of the 1168 blocks.

What that produced, measured rather than guessed: every redstone vein in the
world was lit=true and glowing, every sunflower was placed as its own top half
with nothing under it, and oak stairs came out upside down and waterlogged. It
also quietly disagreed with the StateGrass, StateOakLog and StateOakLeaf
constants next door in encode.go, which are the real defaults.

Now it starts from the default state and applies the properties it recognises,
keeping the default's value for an unknown key or an illegal value -- which is
what vanilla does when it reads a palette entry. That matters on the disk path:
a chunk written with a property we no longer know used to decode to a random
corner state instead of something sane.

The signature grows an ok result, because air was doing double duty as both a
real block and "no such name".

Separately, blockPaletteEntry filled the Properties compound by ranging a Go
map. nbt.Compound preserves insertion order precisely so encoding is
deterministic, so saving one chunk twice produced different region-file bytes
for every multi-property block. Keys are sorted now.
This commit is contained in:
Master290 2026-07-27 03:35:39 +03:00
parent 9e91425c5d
commit 113a59e365
14 changed files with 215 additions and 62 deletions

View file

@ -14,8 +14,8 @@ func TestHeightmapsDiffer(t *testing.T) {
c := NewChunk(0, 0, BiomePlains)
const floor = 64
dandelion := nameToStateID("minecraft:dandelion", nil)
if dandelion == StateAir {
dandelion, ok := nameToStateID("minecraft:dandelion", nil)
if !ok {
t.Fatal("dandelion is missing from the block table")
}
for lx := 0; lx < 16; lx++ {
@ -96,8 +96,8 @@ func TestBlockStatePredicates(t *testing.T) {
}
}
// A flower is the case that separates WORLD_SURFACE from MOTION_BLOCKING.
dandelion := nameToStateID("minecraft:dandelion", nil)
if dandelion == StateAir {
dandelion, ok := nameToStateID("minecraft:dandelion", nil)
if !ok {
t.Fatal("dandelion is missing from the block table")
}
if blocksMotionOrFluid(dandelion) {
@ -113,11 +113,9 @@ func TestSectionFluidCount(t *testing.T) {
const y = 20
// One section: stone floor, water above it, and one waterlogged block —
// which counts as fluid even though it is not a fluid block.
stairs := nameToStateID("minecraft:oak_stairs", map[string]string{
"facing": "north", "half": "bottom", "shape": "straight", "waterlogged": "true",
})
if stairs == StateAir {
t.Fatal("waterlogged oak stairs are missing from the block table")
stairs, ok := nameToStateID("minecraft:oak_stairs", map[string]string{"waterlogged": "true"})
if !ok {
t.Fatal("oak stairs are missing from the block table")
}
if stateFlags(stairs)&flagFluid == 0 {
t.Fatal("waterlogged stairs do not carry the fluid flag; the dump is wrong")