Rework soundIDs and packetIDs generator code to not be platform specific

This commit is contained in:
Scott Binns
2021-01-08 21:27:57 -07:00
parent 8b93d44f86
commit b299065c78
4 changed files with 200 additions and 186 deletions

View File

@ -150,47 +150,54 @@ func main() {
maxLen := pIDs.MaxLen() maxLen := pIDs.MaxLen()
fmt.Println("package data") f, err := os.Create("packetIDs.go")
fmt.Println() if err != nil {
fmt.Println("//go:generate bash -c \"go run gen_packetIDs.go > packetIDs.go\"") fmt.Fprintf(os.Stderr, "Error: %v\n", err)
fmt.Println() os.Exit(1)
fmt.Println("// This file is automatically generated by gen_packetIDs.go. DO NOT EDIT.") }
fmt.Println() defer f.Close()
fmt.Println("// PktID represents a packet ID used in the minecraft protocol.")
fmt.Println("type PktID int32")
fmt.Println()
fmt.Println("// Valid PktID values.")
fmt.Println("const (")
fmt.Println(" // Clientbound packets for connections in the login state.") 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 { for k, v := range pIDs.Login.Clientbound {
fmt.Printf(" %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v) fmt.Fprintf(f, " %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v)
} }
fmt.Println(" // Serverbound packets for connections in the login state.") fmt.Fprintln(f, " // Serverbound packets for connections in the login state.")
for k, v := range pIDs.Login.Serverbound { for k, v := range pIDs.Login.Serverbound {
fmt.Printf(" %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v) fmt.Fprintf(f, " %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v)
} }
fmt.Println() fmt.Fprintln(f)
fmt.Println(" // Clientbound packets for connections in the play state.") fmt.Fprintln(f, " // Clientbound packets for connections in the play state.")
for k, v := range pIDs.Play.Clientbound { for k, v := range pIDs.Play.Clientbound {
fmt.Printf(" %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v) fmt.Fprintf(f, " %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v)
} }
fmt.Println(" // Serverbound packets for connections in the play state.") fmt.Fprintln(f, " // Serverbound packets for connections in the play state.")
for k, v := range pIDs.Play.Serverbound { for k, v := range pIDs.Play.Serverbound {
fmt.Printf(" %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v) fmt.Fprintf(f, " %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v)
} }
fmt.Println() fmt.Fprintln(f)
fmt.Println(" // Clientbound packets used to respond to ping/status requests.") fmt.Fprintln(f, " // Clientbound packets used to respond to ping/status requests.")
for k, v := range pIDs.Status.Clientbound { for k, v := range pIDs.Status.Clientbound {
fmt.Printf(" %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v) fmt.Fprintf(f, " %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v)
} }
fmt.Println(" // Serverbound packets used to ping or read server status.") fmt.Fprintln(f, " // Serverbound packets used to ping or read server status.")
for k, v := range pIDs.Status.Serverbound { for k, v := range pIDs.Status.Serverbound {
fmt.Printf(" %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v) fmt.Fprintf(f, " %s%s PktID = %s\n", k, strings.Repeat(" ", maxLen-len(k)), v)
} }
fmt.Println() fmt.Fprintln(f)
fmt.Println(")") fmt.Fprintln(f, ")")
} }

View File

@ -28,31 +28,38 @@ func main() {
os.Exit(1) os.Exit(1)
} }
fmt.Println("package data") f, err := os.Create("soundIDs.go")
fmt.Println() if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
fmt.Println("//go:generate bash -c \"go run gen_soundIDs.go > soundIDs.go\"") os.Exit(1)
fmt.Println()
fmt.Println("// This file is automatically generated by gen_soundIDs.go. DO NOT EDIT.")
fmt.Println()
fmt.Println("// SoundID represents a sound ID used in the minecraft protocol.")
fmt.Println("type SoundID int32")
fmt.Println()
fmt.Println("// SoundNames - map of ids to names for sounds.")
fmt.Println("var SoundNames map[SoundID]string = map[SoundID]string{")
for _, v := range sounds {
fmt.Printf(` %d: "%s",`, v.ID, v.Name)
fmt.Println()
} }
fmt.Println("}") defer f.Close()
fmt.Println()
fmt.Println("// GetSoundNameByID helper method") fmt.Fprintln(f, "// This file is automatically generated by gen_soundIDs.go. DO NOT EDIT.")
fmt.Println("func GetSoundNameByID(id SoundID) (string,bool) {") fmt.Fprintln(f)
fmt.Println(" name, ok := SoundNames[id]") fmt.Fprintln(f, "package data")
fmt.Println(" return name, ok") fmt.Fprintln(f)
fmt.Println("}")
fmt.Fprintln(f, "//go:generate go run gen_soundIDs.go")
fmt.Fprintln(f)
fmt.Fprintln(f, "// SoundID represents a sound ID used in the minecraft protocol.")
fmt.Fprintln(f, "type SoundID int32")
fmt.Fprintln(f)
fmt.Fprintln(f, "// SoundNames - map of ids to names for sounds.")
fmt.Fprintln(f, "var SoundNames map[SoundID]string = map[SoundID]string{")
for _, v := range sounds {
fmt.Fprintf(f, ` %d: "%s",`, v.ID, v.Name)
fmt.Fprintln(f)
}
fmt.Fprintln(f, "}")
fmt.Fprintln(f)
fmt.Fprintln(f, "// GetSoundNameByID helper method")
fmt.Fprintln(f, "func GetSoundNameByID(id SoundID) (string,bool) {")
fmt.Fprintln(f, " name, ok := SoundNames[id]")
fmt.Fprintln(f, " return name, ok")
fmt.Fprintln(f, "}")
} }
func downloadSoundInfo() ([]sound, error) { func downloadSoundInfo() ([]sound, error) {
@ -72,13 +79,13 @@ func downloadSoundInfo() ([]sound, error) {
out := []sound{} out := []sound{}
for i := range x { for i := range x {
if sounds, ok := x[i]["sounds"]; ok { if sounds, ok := x[i]["sounds"]; ok {
// fmt.Printf("sounds: %#v\n", sounds) // fmt.Fprintf("sounds: %#v\n", sounds)
for _, value := range sounds.(map[string]interface{}) { for _, value := range sounds.(map[string]interface{}) {
// fmt.Printf("%d: %s\n", int64(value.(map[string]interface{})["id"].(float64)), value.(map[string]interface{})["name"]) // fmt.Fprintf("%d: %s\n", int64(value.(map[string]interface{})["id"].(float64)), value.(map[string]interface{})["name"])
out = append(out, sound{ID: int64(value.(map[string]interface{})["id"].(float64)), Name: value.(map[string]interface{})["name"].(string)}) out = append(out, sound{ID: int64(value.(map[string]interface{})["id"].(float64)), Name: value.(map[string]interface{})["name"].(string)})
} }
} else { } else {
// fmt.Printf("NO SOUNDS FOUND IN DATA!") // fmt.Fprintf("NO SOUNDS FOUND IN DATA!")
return nil, fmt.Errorf("No sounds found in data from %s", protocolURL) return nil, fmt.Errorf("No sounds found in data from %s", protocolURL)
} }
} }

View File

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

View File

@ -1,8 +1,8 @@
// This file is automatically generated by gen_soundIDs.go. DO NOT EDIT.
package data package data
//go:generate bash -c "go run gen_soundIDs.go > soundIDs.go" //go:generate go run gen_soundIDs.go
// This file is automatically generated by gen_soundIDs.go. DO NOT EDIT.
// SoundID represents a sound ID used in the minecraft protocol. // SoundID represents a sound ID used in the minecraft protocol.
type SoundID int32 type SoundID int32