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
+21 -3
View File
@@ -4,7 +4,6 @@ import (
"go/ast"
"go/token"
"slices"
"strconv"
"github.com/admin-else/strom/mc/proto_generator/protodef"
util2 "github.com/admin-else/strom/mc/util"
@@ -152,7 +151,16 @@ func BitFieldEncoder(g *Generator, varToSet ast.Expr, dataRaw any, name string)
}
packedVarName := name + "Packed"
packedExpr := Ident(packedVarName)
packedTypeStr := "uint" + strconv.Itoa(totalSize)
packedTypeStr := "uint8"
if totalSize > 8 {
packedTypeStr = "uint16"
}
if totalSize > 16 {
packedTypeStr = "uint32"
}
if totalSize > 32 {
packedTypeStr = "uint64"
}
s = append(s, VarStmt(packedVarName, Ident(packedTypeStr)))
@@ -185,7 +193,17 @@ func BitFieldEncoder(g *Generator, varToSet ast.Expr, dataRaw any, name string)
shiftBy += field.Size
}
encodePacked, err := g.VisitEncoder(packedExpr, "u"+strconv.Itoa(totalSize), name)
packedProtoType := "u8"
if totalSize > 8 {
packedProtoType = "u16"
}
if totalSize > 16 {
packedProtoType = "u32"
}
if totalSize > 32 {
packedProtoType = "u64"
}
encodePacked, err := g.VisitEncoder(packedExpr, packedProtoType, name)
if err != nil {
return
}