Merge branch 'spbinns-master' into master
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
# Go-MC
|
||||

|
||||

|
||||

|
||||

|
||||
[](https://godoc.org/github.com/Tnze/go-mc)
|
||||
[](https://goreportcard.com/report/github.com/Tnze/go-mc)
|
||||
[](https://travis-ci.org/Tnze/go-mc)
|
||||
|
@ -322,14 +322,14 @@ func handleSoundEffect(c *Client, p pk.Packet) error {
|
||||
}
|
||||
|
||||
if c.Events.SoundPlay != nil {
|
||||
if int(s.Sound) < len(data.SoundNames) {
|
||||
if soundName, ok := data.GetSoundNameByID(data.SoundID(s.Sound)); ok {
|
||||
return c.Events.SoundPlay(
|
||||
data.SoundNames[s.Sound], int(s.Category),
|
||||
soundName, int(s.Category),
|
||||
float64(s.X)/8, float64(s.Y)/8, float64(s.Z)/8,
|
||||
float32(s.Volume), float32(s.Pitch))
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "WARN: Unknown sound name. is data.SoundNames out of date?\n")
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "WARN: Unknown sound name (%v). is data.SoundNames out of date?\n", s.Sound)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
// ProtocolVersion , the protocol version number of minecraft net protocol
|
||||
const ProtocolVersion = 753
|
||||
const ProtocolVersion = 754
|
||||
|
||||
// JoinServer connect a Minecraft server for playing the game.
|
||||
func (c *Client) JoinServer(addr string, port int) (err error) {
|
||||
|
@ -33,7 +33,7 @@ type jsonChat struct {
|
||||
|
||||
Translate string `json:"translate,omitempty"`
|
||||
With []json.RawMessage `json:"with,omitempty"` // How can go handle an JSON array with Object and String?
|
||||
Extra []jsonChat `json:"extra,omitempty"`
|
||||
Extra []Message `json:"extra,omitempty"`
|
||||
}
|
||||
|
||||
//UnmarshalJSON decode json to Message
|
||||
@ -73,12 +73,12 @@ func (m *Message) Append(extraMsg ...Message) {
|
||||
finalLen := origLen + len(extraMsg)
|
||||
if cap(m.Extra) < len(m.Extra)+len(extraMsg) {
|
||||
// pre expansion
|
||||
extra := make([]jsonChat, finalLen)
|
||||
extra := make([]Message, finalLen)
|
||||
copy(extra, m.Extra)
|
||||
m.Extra = extra
|
||||
}
|
||||
for _, v := range extraMsg {
|
||||
m.Extra = append(m.Extra, jsonChat(v))
|
||||
m.Extra = append(m.Extra, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,8 @@ var jsons = []string{
|
||||
`"Tnze"`,
|
||||
`"§0Tnze"`,
|
||||
`"§list"`,
|
||||
|
||||
`{"extra":[" "],"text":""}`,
|
||||
}
|
||||
|
||||
var texts = []string{
|
||||
@ -49,6 +51,8 @@ var texts = []string{
|
||||
"Tnze",
|
||||
"\033[30mTnze\033[0m",
|
||||
"\033[1mist\033[0m",
|
||||
|
||||
" ",
|
||||
}
|
||||
|
||||
var ctexts = []string{
|
||||
@ -64,6 +68,8 @@ var ctexts = []string{
|
||||
"Tnze",
|
||||
"Tnze",
|
||||
"ist",
|
||||
|
||||
" ",
|
||||
}
|
||||
|
||||
func TestChatMsgFormatString(t *testing.T) {
|
||||
|
@ -150,47 +150,54 @@ func main() {
|
||||
|
||||
maxLen := pIDs.MaxLen()
|
||||
|
||||
fmt.Println("package data")
|
||||
fmt.Println()
|
||||
fmt.Println("//go:generate bash -c \"go run gen_packetIDs.go > packetIDs.go\"")
|
||||
fmt.Println()
|
||||
fmt.Println("// This file is automatically generated by gen_packetIDs.go. DO NOT EDIT.")
|
||||
fmt.Println()
|
||||
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 (")
|
||||
f, err := os.Create("packetIDs.go")
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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 {
|
||||
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, ")")
|
||||
}
|
||||
|
98
data/gen_soundIDs.go
Normal file
98
data/gen_soundIDs.go
Normal file
@ -0,0 +1,98 @@
|
||||
// gen_soundIDs.go generates the enumeration of sound IDs.
|
||||
|
||||
//+build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"sort"
|
||||
)
|
||||
|
||||
const (
|
||||
protocolURL = "https://pokechu22.github.io/Burger/1.16.4.json"
|
||||
)
|
||||
|
||||
type sound struct {
|
||||
ID int64
|
||||
Name string
|
||||
}
|
||||
|
||||
func main() {
|
||||
sounds, err := downloadSoundInfo()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
f, err := os.Create("soundIDs.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_soundIDs.go. DO NOT EDIT.")
|
||||
fmt.Fprintln(f)
|
||||
fmt.Fprintln(f, "package data")
|
||||
fmt.Fprintln(f)
|
||||
|
||||
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) {
|
||||
resp, err := http.Get(protocolURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
x := []map[string]interface{}{}
|
||||
|
||||
// if err := json.Unmarshal([]byte(data), &x); err != nil {
|
||||
if err := json.NewDecoder(resp.Body).Decode(&x); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
out := []sound{}
|
||||
for i := range x {
|
||||
if sounds, ok := x[i]["sounds"]; ok {
|
||||
// fmt.Fprintf("sounds: %#v\n", sounds)
|
||||
for _, value := range sounds.(map[string]interface{}) {
|
||||
// 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)})
|
||||
}
|
||||
} else {
|
||||
// fmt.Fprintf("NO SOUNDS FOUND IN DATA!")
|
||||
return nil, fmt.Errorf("No sounds found in data from %s", protocolURL)
|
||||
}
|
||||
}
|
||||
|
||||
sort.SliceStable(out, func(i, j int) bool {
|
||||
return out[i].ID < out[j].ID
|
||||
})
|
||||
|
||||
return out, nil
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
// This file is automatically generated by gen_packetIDs.go. DO NOT EDIT.
|
||||
|
||||
package data
|
||||
|
||||
//go:generate bash -c "go run gen_packetIDs.go > packetIDs.go"
|
||||
|
||||
// This file is automatically generated by gen_packetIDs.go. DO NOT EDIT.
|
||||
//go:generate go run gen_packetIDs.go
|
||||
|
||||
// PktID represents a packet ID used in the minecraft protocol.
|
||||
type PktID int32
|
||||
@ -16,152 +16,152 @@ const (
|
||||
LoginPluginRequest PktID = 0x04
|
||||
Disconnect PktID = 0x00
|
||||
// Serverbound packets for connections in the login state.
|
||||
LoginStart PktID = 0x00
|
||||
EncryptionBeginServerbound PktID = 0x01
|
||||
LoginPluginResponse PktID = 0x02
|
||||
LoginStart PktID = 0x00
|
||||
|
||||
// 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
|
||||
UnlockRecipes PktID = 0x35
|
||||
Animation PktID = 0x05
|
||||
WorldEvent PktID = 0x21
|
||||
ScoreboardDisplayObjective PktID = 0x43
|
||||
CustomPayloadClientbound PktID = 0x17
|
||||
SpawnPosition PktID = 0x42
|
||||
EntityStatus PktID = 0x1a
|
||||
SpawnEntity PktID = 0x00
|
||||
NamedSoundEffect PktID = 0x18
|
||||
HeldItemSlotClientbound PktID = 0x3f
|
||||
ChatClientbound PktID = 0x0e
|
||||
AbilitiesClientbound PktID = 0x30
|
||||
EntityDestroy PktID = 0x36
|
||||
SetPassengers PktID = 0x4b
|
||||
FacePlayer PktID = 0x33
|
||||
TransactionClientbound PktID = 0x11
|
||||
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
|
||||
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
|
||||
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
|
||||
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.
|
||||
SetBeaconEffect PktID = 0x24
|
||||
UpdateStructureBlock PktID = 0x2a
|
||||
EnchantItem PktID = 0x08
|
||||
Spectate PktID = 0x2d
|
||||
ArmAnimation PktID = 0x2c
|
||||
QueryEntityNbt PktID = 0x0d
|
||||
Flying PktID = 0x15
|
||||
ResourcePackReceive PktID = 0x21
|
||||
BlockDig PktID = 0x1b
|
||||
AbilitiesServerbound PktID = 0x1a
|
||||
CustomPayloadServerbound PktID = 0x0b
|
||||
SelectTrade PktID = 0x23
|
||||
UpdateJigsawBlock PktID = 0x29
|
||||
SteerVehicle PktID = 0x1d
|
||||
Settings PktID = 0x05
|
||||
SteerBoat PktID = 0x17
|
||||
UseItem PktID = 0x2f
|
||||
TeleportConfirm PktID = 0x00
|
||||
PickItem PktID = 0x18
|
||||
CraftRecipeRequest PktID = 0x19
|
||||
Look PktID = 0x14
|
||||
TabCompleteServerbound PktID = 0x06
|
||||
AdvancementTab PktID = 0x22
|
||||
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
|
||||
TransactionServerbound PktID = 0x07
|
||||
UpdateSign PktID = 0x2b
|
||||
QueryBlockNbt PktID = 0x01
|
||||
PositionLook PktID = 0x13
|
||||
HeldItemSlotServerbound PktID = 0x25
|
||||
EditBook PktID = 0x0c
|
||||
UpdateCommandBlock PktID = 0x26
|
||||
UseEntity PktID = 0x0e
|
||||
ResourcePackReceive PktID = 0x21
|
||||
Spectate PktID = 0x2d
|
||||
TeleportConfirm PktID = 0x00
|
||||
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
|
||||
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
|
||||
|
1993
data/soundIDs.go
1993
data/soundIDs.go
File diff suppressed because it is too large
Load Diff
51
net/packet/util.go
Normal file
51
net/packet/util.go
Normal file
@ -0,0 +1,51 @@
|
||||
package packet
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
type Ary struct {
|
||||
Len Field
|
||||
Ary interface{}
|
||||
}
|
||||
|
||||
func (a Ary) Encode() (data []byte) {
|
||||
length := int(reflect.ValueOf(a.Len).Int())
|
||||
array := reflect.ValueOf(a.Ary).Elem()
|
||||
for i := 0; i < length; i++ {
|
||||
elem := array.Index(i)
|
||||
data = append(data, elem.Interface().(FieldEncoder).Encode()...)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (a Ary) Decode(r DecodeReader) error {
|
||||
length := int(reflect.ValueOf(a.Len).Int())
|
||||
array := reflect.ValueOf(a.Ary).Elem()
|
||||
for i := 0; i < length; i++ {
|
||||
elem := array.Index(i)
|
||||
if err := elem.Interface().(FieldDecoder).Decode(r); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Opt struct {
|
||||
Has func() bool
|
||||
Field interface{}
|
||||
}
|
||||
|
||||
func (o Opt) Encode() []byte {
|
||||
if o.Has() {
|
||||
return nil
|
||||
}
|
||||
return o.Field.(FieldEncoder).Encode()
|
||||
}
|
||||
|
||||
func (o Opt) Decode(r DecodeReader) error {
|
||||
if o.Has() {
|
||||
return nil
|
||||
}
|
||||
return o.Field.(FieldDecoder).Decode(r)
|
||||
}
|
Reference in New Issue
Block a user