fix: correct bitfield decoder using mask extraction, fix command_node

- Switch bitfield decoder from shift-based to mask-based extraction (var>>pos & mask)
  fixes non-power-of-2 bitfields like 6-bit command_node flags
- Fix MultiTypeFix to handle CaseExprTypeOnlyNumber/OnlyBool variants
- Update minecraft-data command_node bitfield order for all 1.21.8+ versions
  to LSB-first convention (matches reverse encoder/decoder)
- Implement SwitchDecoder for extraNodeData via compareTo visitor
- DeclareCommands now decodes successfully (was EOF)
- Add 6 regression tests (entity_equipment, metadata, recipes, commands)
This commit is contained in:
OpenCode
2026-08-05 22:29:08 +02:00
parent f4c2762881
commit e58499ed09
17 changed files with 8532 additions and 263 deletions
+6 -8
View File
@@ -225,7 +225,7 @@ func MultiTypeFix(s string, t *CaseExprType) (e ast.Expr) {
*t = ct
return
}
if *t == ct {
if *t == ct || (*t == CaseExprTypeOnlyNumber && ct == CaseExprTypeNumber) || (*t == CaseExprTypeOnlyBool && ct == CaseExprTypeBool) || (*t == CaseExprTypeNumber && ct == CaseExprTypeOnlyNumber) || (*t == CaseExprTypeBool && ct == CaseExprTypeOnlyBool) {
return
}
@@ -400,6 +400,7 @@ func BitFieldDecoder(g *Generator, varToSet ast.Expr, dataRaw any, name string)
}
s = append(s, packedVarStmt)
s = append(s, stmts...)
slices.Reverse(data)
lShiftBy := 0
for _, field := range data {
var fieldTypeProtodef string
@@ -413,16 +414,13 @@ func BitFieldDecoder(g *Generator, varToSet ast.Expr, dataRaw any, name string)
return
}
rShiftBy := totalSize - field.Size
fieldToSet := SelectorExprAndStr(varToSet, util2.CamelCase(field.Name))
mask := (1 << field.Size) - 1
var getDataExpr ast.Expr
getDataExpr = RightShift(
LeftShift(
Ident(packed),
NumLit(lShiftBy)),
NumLit(rShiftBy),
)
getDataExpr = BinAnd(
RightShift(Ident(packed), NumLit(lShiftBy)),
NumLit(mask))
if fieldTypeProtodef == "bool" {
getDataExpr = Equals(getDataExpr, NumLit(1))
} else if fieldTypeProtodef != packedTypeProtodef {