This commit is contained in:
adman
2026-03-02 00:14:57 +01:00
parent f7d7a72b7c
commit d8cc9cab48
32 changed files with 79606 additions and 20424 deletions
+4 -5
View File
@@ -15,6 +15,7 @@ type TypesInfo struct {
type PacketInfo struct {
TName, Name, Direction, State, PacketId, ProtocolVersion, MinecraftVersion string
PacketDef any
}
func GeneratePacketInfoFile(versions []string, packetInfos []PacketInfo) (err error) {
@@ -31,10 +32,8 @@ func GeneratePacketInfoFile(versions []string, packetInfos []PacketInfo) (err er
vUnderscore := "v" + strings.ReplaceAll(p.MinecraftVersion, ".", "_")
typeName := p.TName
var typeExpr ast.Expr
if typeName == "struct{}" {
typeExpr = &ast.StructType{Fields: &ast.FieldList{}}
} else if strings.HasPrefix(typeName, "proto_base.") {
typeExpr = Selector("proto_base", strings.TrimPrefix(typeName, "proto_base."))
if p.PacketDef == "void" {
typeExpr = Selector("proto_base", "Void")
} else {
typeExpr = Selector(vUnderscore, typeName)
}
@@ -46,7 +45,7 @@ func GeneratePacketInfoFile(versions []string, packetInfos []PacketInfo) (err er
KeyValueExpr(Ident("Type"), AddrOf(CompLit(typeExpr, nil))),
KeyValueExpr(Ident("Name"), StrLit(p.Name)),
KeyValueExpr(Ident("Direction"), Selector("proto_base", p.Direction)),
KeyValueExpr(Ident("state"), Selector("proto_base", p.State)),
KeyValueExpr(Ident("State"), Selector("proto_base", p.State)),
KeyValueExpr(Ident("PacketId"), NumLit(int(packetId))),
KeyValueExpr(Ident("ProtocolVersion"), NumLit(protocolVersion)),
}))
+2 -1
View File
@@ -293,6 +293,7 @@ func (g *Generator) GenerateProtocol(protocol Protocol, version string) (err err
v2 := v2.(string)
typeName := prefix + CamelCase(v2)
g.packetInfos = append(g.packetInfos, PacketInfo{
PacketDef: v2,
TName: typeName,
Name: k2,
Direction: types.Direction,
@@ -378,7 +379,7 @@ func GenerateVersions(versions []string) (err error) {
}
func main() {
err := GenerateVersions([]string{"1.21.8"})
err := GenerateVersions([]string{"1.21.8", "1.21.9", "1.21.11"})
if err != nil {
panic(err)
}
+1
View File
@@ -532,6 +532,7 @@ func (g *Generator) RegisterDecoderNatives() {
"varlong": VarLongDecoder,
"anonymousNbt": DefaultDecoder,
"anonOptionalNbt": DefaultDecoder, // I have no idea what the difference is between these two
"lpVec3": DefaultDecoder,
"UUID": UUIDDecoder,
"restBuffer": DefaultDecoder,
+1
View File
@@ -359,6 +359,7 @@ func (g *Generator) RegisterEncoderNatives() {
"anonOptionalNbt": DefaultEncoder, // I have no idea what the difference is between these two
"UUID": UUIDEncoder,
"restBuffer": DefaultEncoder,
"lpVec3": DefaultEncoder,
"string": StringEncoder,
"f32": SimpleTypeEncoder,
+1
View File
@@ -194,5 +194,6 @@ func (g *Generator) RegisterNatives() {
"bitflags": VisitBitFlagsType,
"topBitSetTerminatedArray": VisitToDoType,
"todo": VisitToDoType,
"lpVec3": MakeSelectorVisitor("proto_base", "LpVec3d"),
}
}