Regenerate files, moves packet id from data package

This commit is contained in:
Tnze
2021-02-18 21:29:16 +08:00
parent b4fc573118
commit ea0e0d1cae
19 changed files with 181 additions and 1379 deletions

View File

@ -1,7 +1,6 @@
// gen_blocks.go generates block information.
//+build ignore
// gen_blocks.go generates block information.
package main
import (
@ -131,6 +130,7 @@ func makeBlockDeclaration(blocks []Block) *ast.DeclStmt {
return out
}
//go:generate go run $GOFILE > ./packetid.go
func main() {
blocks, err := downloadInfo()
if err != nil {
@ -138,7 +138,9 @@ func main() {
os.Exit(1)
}
fmt.Println(`// Package block stores information about blocks in Minecraft.
fmt.Println(`// Code generated by gen_blocks.go; DO NOT EDIT.
// Package block stores information about blocks in Minecraft.
package block
import (

View File

@ -1,172 +0,0 @@
// This file is automatically generated by gen_packetIDs.go. DO NOT EDIT.
package data
//go:generate go run gen_packetIDs.go
// PktID represents a packet ID used in the minecraft protocol.
type PktID int32
// Valid PktID values.
const (
// Clientbound packets for connections in the login state.
EncryptionBeginClientbound PktID = 0x01
Success PktID = 0x02
Compress PktID = 0x03
LoginPluginRequest PktID = 0x04
Disconnect PktID = 0x00
// Serverbound packets for connections in the login state.
LoginStart PktID = 0x00
EncryptionBeginServerbound PktID = 0x01
LoginPluginResponse PktID = 0x02
// Clientbound packets for connections in the play state.
KickDisconnect PktID = 0x19
UnlockRecipes PktID = 0x35
Animation PktID = 0x05
WorldEvent PktID = 0x21
ScoreboardDisplayObjective PktID = 0x43
CustomPayloadClientbound PktID = 0x17
NamedSoundEffect PktID = 0x18
HeldItemSlotClientbound PktID = 0x3f
ChatClientbound PktID = 0x0e
AbilitiesClientbound PktID = 0x30
EntityDestroy PktID = 0x36
SetPassengers PktID = 0x4b
KeepAliveClientbound PktID = 0x1f
SpawnEntityExperienceOrb PktID = 0x01
OpenHorseWindow PktID = 0x1e
RemoveEntityEffect PktID = 0x37
RelEntityMove PktID = 0x27
SelectAdvancementTab PktID = 0x3c
OpenSignEntity PktID = 0x2e
Map PktID = 0x25
FacePlayer PktID = 0x33
EntityEquipment PktID = 0x47
ResourcePackSend PktID = 0x38
NbtQueryResponse PktID = 0x54
ScoreboardObjective PktID = 0x4a
StopSound PktID = 0x52
OpenWindow PktID = 0x2d
Camera PktID = 0x3e
Advancements PktID = 0x57
UpdateTime PktID = 0x4e
Login PktID = 0x24
PositionClientbound PktID = 0x34
UpdateViewPosition PktID = 0x40
EntitySoundEffect PktID = 0x50
Respawn PktID = 0x39
BlockChange PktID = 0x0b
BlockBreakAnimation PktID = 0x08
Title PktID = 0x4f
EntityTeleport PktID = 0x56
EntityEffect PktID = 0x59
TileEntityData PktID = 0x09
SpawnPosition PktID = 0x42
WorldBorder PktID = 0x3d
Experience PktID = 0x48
PlayerlistHeader PktID = 0x53
WindowItems PktID = 0x13
EntityUpdateAttributes PktID = 0x58
EntityHeadRotation PktID = 0x3a
VehicleMoveClientbound PktID = 0x2b
MapChunk PktID = 0x20
EntityLook PktID = 0x29
Teams PktID = 0x4c
UpdateViewDistance PktID = 0x41
Explosion PktID = 0x1b
MultiBlockChange PktID = 0x3b
PlayerInfo PktID = 0x32
CraftRecipeResponse PktID = 0x2f
TransactionClientbound PktID = 0x11
TradeList PktID = 0x26
CloseWindowClientbound PktID = 0x12
TabCompleteClientbound PktID = 0x0f
SetCooldown PktID = 0x16
BlockAction PktID = 0x0a
NamedEntitySpawn PktID = 0x04
SpawnEntityPainting PktID = 0x03
UpdateLight PktID = 0x23
CombatEvent PktID = 0x31
SpawnEntityLiving PktID = 0x02
ScoreboardScore PktID = 0x4d
DeclareCommands PktID = 0x10
UpdateHealth PktID = 0x49
EntityMetadata PktID = 0x44
AttachEntity PktID = 0x45
Tags PktID = 0x5b
EntityStatus PktID = 0x1a
AcknowledgePlayerDigging PktID = 0x07
Collect PktID = 0x55
WorldParticles PktID = 0x22
Entity PktID = 0x2a
UnloadChunk PktID = 0x1c
Difficulty PktID = 0x0d
CraftProgressBar PktID = 0x14
BossBar PktID = 0x0c
DeclareRecipes PktID = 0x5a
GameStateChange PktID = 0x1d
Statistics PktID = 0x06
EntityVelocity PktID = 0x46
SetSlot PktID = 0x15
OpenBook PktID = 0x2c
SoundEffect PktID = 0x51
EntityMoveLook PktID = 0x28
SpawnEntity PktID = 0x00
// Serverbound packets for connections in the play state.
EnchantItem PktID = 0x08
CustomPayloadServerbound PktID = 0x0b
SelectTrade PktID = 0x23
SetCreativeSlot PktID = 0x28
UpdateSign PktID = 0x2b
WindowClick PktID = 0x09
PositionLook PktID = 0x13
UpdateCommandBlock PktID = 0x26
QueryBlockNbt PktID = 0x01
Flying PktID = 0x15
KeepAliveServerbound PktID = 0x10
ClientCommand PktID = 0x04
BlockPlace PktID = 0x2e
EntityAction PktID = 0x1c
PositionServerbound PktID = 0x12
ResourcePackReceive PktID = 0x21
Spectate PktID = 0x2d
TeleportConfirm PktID = 0x00
GenerateStructure PktID = 0x0f
SetDifficulty PktID = 0x02
CloseWindowServerbound PktID = 0x0a
Look PktID = 0x14
AdvancementTab PktID = 0x22
SetBeaconEffect PktID = 0x24
AbilitiesServerbound PktID = 0x1a
ChatServerbound PktID = 0x03
DisplayedRecipe PktID = 0x1e
RecipeBook PktID = 0x1f
UpdateJigsawBlock PktID = 0x29
TransactionServerbound PktID = 0x07
SteerVehicle PktID = 0x1d
NameItem PktID = 0x20
PickItem PktID = 0x18
UpdateStructureBlock PktID = 0x2a
TabCompleteServerbound PktID = 0x06
HeldItemSlotServerbound PktID = 0x25
SteerBoat PktID = 0x17
Settings PktID = 0x05
UseItem PktID = 0x2f
CraftRecipeRequest PktID = 0x19
UpdateCommandBlockMinecart PktID = 0x27
BlockDig PktID = 0x1b
EditBook PktID = 0x0c
UseEntity PktID = 0x0e
VehicleMoveServerbound PktID = 0x16
ArmAnimation PktID = 0x2c
LockDifficulty PktID = 0x11
QueryEntityNbt PktID = 0x0d
// Clientbound packets used to respond to ping/status requests.
ServerInfo PktID = 0x00
PingClientbound PktID = 0x01
// Serverbound packets used to ping or read server status.
PingStart PktID = 0x00
PingServerbound PktID = 0x01
)

View File

@ -1,7 +1,6 @@
// gen_packetIDs.go generates the enumeration of packet IDs used on the wire.
//+build ignore
// gen_packetIDs.go generates the enumeration of packet IDs used on the wire.
package main
import (
@ -9,13 +8,39 @@ import (
"fmt"
"net/http"
"os"
"strings"
"text/template"
"github.com/iancoleman/strcase"
)
const (
protocolURL = "https://raw.githubusercontent.com/PrismarineJS/minecraft-data/master/data/pc/1.16.2/protocol.json"
protocolURL = "https://raw.githubusercontent.com/PrismarineJS/minecraft-data/master/data/pc/1.16.2/protocol.json"
packetidTmpl = `// This file is automatically generated by gen_packetIDs.go. DO NOT EDIT.
package packetid
// Valid PktID values.
const (
// Clientbound packets for connections in the login state.
{{range $Name, $ID := .Login.Clientbound}} {{$Name}} = {{$ID}}
{{end}}
// Serverbound packets for connections in the login state
{{range $Name, $ID := .Login.Serverbound}} {{$Name}} = {{$ID}}
{{end}}
// Clientbound packets for connections in the play state.
{{range $Name, $ID := .Play.Clientbound}} {{$Name}} = {{$ID}}
{{end}}
// Serverbound packets for connections in the play state.
{{range $Name, $ID := .Play.Serverbound}} {{$Name}} = {{$ID}}
{{end}}
// Clientbound packets used to respond to ping/status requests.
{{range $Name, $ID := .Status.Clientbound}} {{$Name}} = {{$ID}}
{{end}}
// Serverbound packets used to ping or read server status.
{{range $Name, $ID := .Status.Serverbound}} {{$Name}} = {{$ID}}
{{end}}
)
`
)
// unnest is a utility function to unpack a value from a nested map, given
@ -96,23 +121,6 @@ type protocolIDs struct {
// Handshake state has no packets
}
func (p protocolIDs) MaxLen() int {
var max int
for _, m := range []duplexMappings{p.Login, p.Play, p.Status} {
for k, _ := range m.Clientbound {
if len(k) > max {
max = len(k)
}
}
for k, _ := range m.Serverbound {
if len(k) > max {
max = len(k)
}
}
}
return max
}
func downloadInfo() (*protocolIDs, error) {
resp, err := http.Get(protocolURL)
if err != nil {
@ -141,6 +149,8 @@ func downloadInfo() (*protocolIDs, error) {
return &out, nil
}
//go:generate go run $GOFILE
//go:generate go fmt packetid.go
func main() {
pIDs, err := downloadInfo()
if err != nil {
@ -148,56 +158,16 @@ func main() {
os.Exit(1)
}
maxLen := pIDs.MaxLen()
f, err := os.Create("packetIDs.go")
f, err := os.Create("packetid.go")
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
defer f.Close()
fmt.Fprintln(f, "// This file is automatically generated by gen_packetIDs.go. DO NOT EDIT.")
fmt.Fprintln(f)
fmt.Fprintln(f, "package data")
fmt.Fprintln(f)
fmt.Fprintln(f, "//go:generate go run gen_packetIDs.go")
fmt.Fprintln(f)
fmt.Fprintln(f, "// PktID represents a packet ID used in the minecraft protocol.")
fmt.Fprintln(f, "type PktID int32")
fmt.Fprintln(f)
fmt.Fprintln(f, "// Valid PktID values.")
fmt.Fprintln(f, "const (")
fmt.Fprintln(f, " // Clientbound packets for connections in the login state.")
for k, v := range pIDs.Login.Clientbound {
fmt.Fprintf(f, " %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v)
tmpl := template.Must(template.New("packetIDs").Parse(packetidTmpl))
if err := tmpl.Execute(f, pIDs); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
fmt.Fprintln(f, " // Serverbound packets for connections in the login state.")
for k, v := range pIDs.Login.Serverbound {
fmt.Fprintf(f, " %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v)
}
fmt.Fprintln(f)
fmt.Fprintln(f, " // Clientbound packets for connections in the play state.")
for k, v := range pIDs.Play.Clientbound {
fmt.Fprintf(f, " %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v)
}
fmt.Fprintln(f, " // Serverbound packets for connections in the play state.")
for k, v := range pIDs.Play.Serverbound {
fmt.Fprintf(f, " %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v)
}
fmt.Fprintln(f)
fmt.Fprintln(f, " // Clientbound packets used to respond to ping/status requests.")
for k, v := range pIDs.Status.Clientbound {
fmt.Fprintf(f, " %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v)
}
fmt.Fprintln(f, " // Serverbound packets used to ping or read server status.")
for k, v := range pIDs.Status.Serverbound {
fmt.Fprintf(f, " %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v)
}
fmt.Fprintln(f)
fmt.Fprintln(f, ")")
}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,7 @@
// gen_soundIDs.go generates the enumeration of sound IDs.
//+build ignore
//go:generate go run $GOFILE
// gen_soundIDs.go generates the enumeration of sound IDs.
package main
import (
@ -13,7 +13,7 @@ import (
)
const (
protocolURL = "https://pokechu22.github.io/Burger/1.16.4.json"
protocolURL = "https://pokechu22.github.io/Burger/1.16.5.json"
)
type sound struct {
@ -35,7 +35,7 @@ func main() {
}
defer f.Close()
fmt.Fprintln(f, "// This file is automatically generated by gen_soundIDs.go. DO NOT EDIT.")
fmt.Fprintln(f, "// Code generated by gen_soundIDs.go. DO NOT EDIT.")
fmt.Fprintln(f)
fmt.Fprintln(f, "package data")
fmt.Fprintln(f)