diff --git a/chunk.go b/chunk.go index 77f6d07..8474dfe 100644 --- a/chunk.go +++ b/chunk.go @@ -17,7 +17,6 @@ package steven import ( "bytes" "encoding/binary" - "fmt" "math" "sort" "sync" @@ -573,16 +572,22 @@ func loadChunk(x, z int, data *bytes.Reader, mask int32, sky, isNew bool) { } cs := c.Sections[i] - count, _ := protocol.ReadVarInt(data) + bitSize, err := data.ReadByte() + if err != nil { + panic(err) + } + blockMap := map[int]int{} - for i := 0; i < int(count); i++ { - bID, _ := protocol.ReadVarInt(data) - blockMap[i] = int(bID) + if bitSize <= 8 { + count, _ := protocol.ReadVarInt(data) + for i := 0; i < int(count); i++ { + bID, _ := protocol.ReadVarInt(data) + blockMap[i] = int(bID) + } } - bitSize, _ := protocol.ReadVarInt(data) - length, _ := protocol.ReadVarInt(data) - bits := make([]uint64, length) + len, _ := protocol.ReadVarInt(data) + bits := make([]uint64, len) binary.Read(data, binary.BigEndian, &bits) m := bit.NewMapFromRaw(bits, int(bitSize)) @@ -590,7 +595,7 @@ func loadChunk(x, z int, data *bytes.Reader, mask int32, sky, isNew bool) { val := m.Get(i) bID, ok := blockMap[val] if !ok { - panic(fmt.Sprintf("Missing block %d", val)) + bID = val } block := GetBlockByCombinedID(uint16(bID)) pos := Position{X: i & 0xF, Z: (i >> 4) & 0xF, Y: i >> 8} diff --git a/protocol/play_clientbound.go b/protocol/play_clientbound.go index b067f57..32579ec 100644 --- a/protocol/play_clientbound.go +++ b/protocol/play_clientbound.go @@ -21,159 +21,11 @@ import ( "github.com/thinkofdeath/steven/format" ) -// KeepAliveClientbound is sent by a server to check if the -// client is still responding and keep the connection open. -// The client should reply with the KeepAliveServerbound -// packet setting ID to the same as this one. -// -// This is a Minecraft packet -type KeepAliveClientbound struct { - ID VarInt -} - -// JoinGame is sent after completing the login process. This -// sets the initial state for the client. -// -// This is a Minecraft packet -type JoinGame struct { - // The entity id the client will be referenced by - EntityID int32 - // The starting gamemode of the client - Gamemode byte - // The dimension the client is starting in - Dimension int8 - // The difficuilty setting for the server - Difficulty byte - // The max number of players on the server - MaxPlayers byte - // The level type of the server - LevelType string - // Whether the client should reduce the amount of debug - // information it displays in F3 mode - ReducedDebugInfo bool -} - -// ServerMessage is a message sent by the server. It could be from a player -// or just a system message. The Type field controls the location the -// message is displayed at and when the message is displayed. -// -// This is a Minecraft packet -type ServerMessage struct { - Message format.AnyComponent `as:"json"` - // 0 - Chat message, 1 - System message, 2 - Action bar message - Type byte -} - -// TimeUpdate is sent to sync the world's time to the client, the client -// will manually tick the time itself so this doesn't need to sent repeatedly -// but if the server or client has issues keeping up this can fall out of sync -// so it is a good idea to sent this now and again -// -// This is a Minecraft packet -type TimeUpdate struct { - WorldAge int64 - TimeOfDay int64 -} - -// EntityEquipment is sent to display an item on an entity, like a sword -// or armor. Slot 0 is the held item and slots 1 to 4 are boots, leggings -// chestplate and helmet respectively. -// -// This is a Minecraft packet -type EntityEquipment struct { - EntityID VarInt - Slot VarInt - Item ItemStack `as:"raw"` -} - -// SpawnPosition is sent to change the player's current spawn point. Currently -// only used by the client for the compass. -// -// This is a Minecraft packet -type SpawnPosition struct { - Location Position -} - -// UpdateHealth is sent by the server to update the player's health and food. -// -// This is a Minecraft packet -type UpdateHealth struct { - Health float32 - Food VarInt - FoodSaturation float32 -} - -// Respawn is sent to respawn the player after death or when they move worlds. -// -// This is a Minecraft packet -type Respawn struct { - Dimension int32 - Difficulty byte - Gamemode byte - LevelType string -} - -// TeleportPlayer is sent to change the player's position. The client is expected -// to reply to the server with the same positions as contained in this packet -// otherwise will reject future packets. -// -// This is a Minecraft packet -type TeleportPlayer struct { - X, Y, Z float64 - Yaw, Pitch float32 - Flags byte -} - -// SetCurrentHotbarSlot changes the player's currently selected hotbar item. -// -// This is a Minecraft packet -type SetCurrentHotbarSlot struct { - Slot byte -} - -// EntityUsedBed is sent by the server when a player goes to bed. -// -// This is a Minecraft packetA -type EntityUsedBed struct { - EntityID VarInt - Location Position -} - -// Animation is sent by the server to play an animation on a specific entity. -// -// This is a Minecraft packetB -type Animation struct { - EntityID VarInt - AnimationID byte -} - -// SpawnPlayer is used to spawn a player when they are in range of the client. -// This packet alone isn't enough to display the player as the skin and username -// information is in the player information packet. -// -// This is a Minecraft packetC -type SpawnPlayer struct { - EntityID VarInt - UUID UUID `as:"raw"` - X, Y, Z int32 - Yaw, Pitch int8 - Metadata Metadata -} - -// CollectItem causes the collected item to fly towards the collector. This -// does not destroy the entity. -// -// This is a Minecraft packetD -type CollectItem struct { - CollectedEntityID VarInt - CollectorEntityID VarInt -} - // SpawnObject is used to spawn an object or vehicle into the world when it // is in range of the client. Velocity is only sent if the Data field is // non-zero. // -// This is a Minecraft packetE +// This is a Minecraft packet type SpawnObject struct { EntityID VarInt UUID UUID `as:"raw"` @@ -184,10 +36,31 @@ type SpawnObject struct { VelocityX, VelocityY, VelocityZ int16 } +// SpawnExperienceOrb spawns a single experience orb into the world when +// it is in range of the client. The count controls the amount of experience +// gained when collected. +// +// This is a Minecraft packet +type SpawnExperienceOrb struct { + EntityID VarInt + X, Y, Z int32 + Count int16 +} + +// SpawnGlobalEntity spawns an entity which is visible from anywhere in the +// world. Currently only used for lightning. +// +// This is a Minecraft packet +type SpawnGlobalEntity struct { + EntityID VarInt + Type byte + X, Y, Z int32 +} + // SpawnMob is used to spawn a living entity into the world when it is in // range of the client. // -// This is a Minecraft packetF +// This is a Minecraft packet type SpawnMob struct { EntityID VarInt UUID UUID `as:"raw"` @@ -210,227 +83,226 @@ type SpawnPainting struct { Direction byte } -// SpawnExperienceOrb spawns a single experience orb into the world when -// it is in range of the client. The count controls the amount of experience -// gained when collected. +// SpawnPlayer is used to spawn a player when they are in range of the client. +// This packet alone isn't enough to display the player as the skin and username +// information is in the player information packet. // // This is a Minecraft packet -type SpawnExperienceOrb struct { - EntityID VarInt - X, Y, Z int32 - Count int16 +type SpawnPlayer struct { + EntityID VarInt + UUID UUID `as:"raw"` + X, Y, Z int32 + Yaw, Pitch int8 + Metadata Metadata } -// EntityVelocity sets the velocity of an entity in 1/8000 of a block -// per a tick. +// Animation is sent by the server to play an animation on a specific entity. // // This is a Minecraft packet -type EntityVelocity struct { - EntityID VarInt - VelocityX, VelocityY, VelocityZ int16 +type Animation struct { + EntityID VarInt + AnimationID byte } -// EntityDestroy destroys the entities with the ids in the provided slice. +// Statistics is used to update the statistics screen for the client. // // This is a Minecraft packet -type EntityDestroy struct { - EntityIDs []VarInt `length:"VarInt"` +type Statistics struct { + Statistics []Statistic `length:"VarInt"` } -// Entity does nothing. It is a result of subclassing used in Minecraft. -// -// This is a Minecraft packet -type Entity struct { - EntityID VarInt +// Statistic is used by Statistics +type Statistic struct { + Name string + Value VarInt } -// EntityMove moves the entity with the id by the offsets provided. +// BlockBreakAnimation is used to create and update the block breaking +// animation played when a player starts digging a block. // // This is a Minecraft packet -type EntityMove struct { - EntityID VarInt - DeltaX, DeltaY, DeltaZ int8 - OnGround bool +type BlockBreakAnimation struct { + EntityID VarInt + Location Position + Stage int8 } -// EntityLook rotates the entity to the new angles provided. +// UpdateBlockEntity updates the nbt tag of a block entity in the +// world. // // This is a Minecraft packet -type EntityLook struct { - EntityID VarInt - Yaw, Pitch int8 - OnGround bool +type UpdateBlockEntity struct { + Location Position + Action byte + NBT *nbt.Compound } -// EntityLookAndMove is a combination of EntityMove and EntityLook. +// BlockAction triggers different actions depending on the target block. // // This is a Minecraft packet -type EntityLookAndMove struct { - EntityID VarInt - DeltaX, DeltaY, DeltaZ int8 - Yaw, Pitch int8 - OnGround bool +type BlockAction struct { + Location Position + Byte1 byte + Byte2 byte + BlockType VarInt } -// EntityTeleport teleports the entity to the target location. This is -// sent if the entity moves further than EntityMove allows. +// BlockChange is used to update a single block on the client. // // This is a Minecraft packet -type EntityTeleport struct { - EntityID VarInt - X, Y, Z int32 - Yaw, Pitch int8 - OnGround bool +type BlockChange struct { + Location Position + BlockID VarInt } -// EntityHeadLook rotates an entity's head to the new angle. +// BossBar displays and/or changes a boss bar that is displayed on the +// top of the client's screen. This is normally used for bosses such as +// the ender dragon or the wither. // // This is a Minecraft packet -type EntityHeadLook struct { - EntityID VarInt - HeadYaw int8 +type BossBar struct { + UUID UUID `as:"raw"` + Action VarInt + Title format.AnyComponent `as:"json" if:".Action == 0 .Action == 3"` + Health float32 `if:".Action == 0 .Action == 2"` + Color VarInt `if:".Action == 0 .Action == 4"` + Style VarInt `if:".Action == 0 .Action == 4"` + Flags byte `if:".Action == 0 .Action == 5"` } -// EntityAction causes an entity to preform an action based on the passed -// id. +// ServerDifficulty changes the displayed difficulty in the client's menu +// as well as some ui changes for hardcore. // -// This is a Minecraft packetA -type EntityAction struct { - EntityID int32 - ActionID byte +// This is a Minecraft packet +type ServerDifficulty struct { + Difficulty byte } -// EntityAttach attaches to entities together, either by mounting or leashing. -// -1 can be used at the EntityID to deattach. +// TabCompleteReply is sent as a reply to a tab completion request. +// The matches should be possible completions for the command/chat the +// player sent. // -// This is a Minecraft packetB -type EntityAttach struct { - EntityID int32 - Vehicle int32 - Leash bool +// This is a Minecraft packet +type TabCompleteReply struct { + Matches []string `length:"VarInt"` } -// EntityMetadata updates the metadata for an entity. +// ServerMessage is a message sent by the server. It could be from a player +// or just a system message. The Type field controls the location the +// message is displayed at and when the message is displayed. // -// This is a Minecraft packetC -type EntityMetadata struct { - EntityID VarInt - Metadata Metadata +// This is a Minecraft packet +type ServerMessage struct { + Message format.AnyComponent `as:"json"` + // 0 - Chat message, 1 - System message, 2 - Action bar message + Type byte } -// EntityEffect applies a status effect to an entity for a given duration. +// MultiBlockChange is used to update a batch of blocks in a single packet. // -// This is a Minecraft packetD -type EntityEffect struct { - EntityID VarInt - EffectID int8 - Amplifier int8 - Duration VarInt - HideParticles bool +// This is a Minecraft packet +type MultiBlockChange struct { + ChunkX, ChunkZ int32 + Records []BlockChangeRecord `length:"VarInt"` } -// EntityRemoveEffect removes an effect from an entity. -// -// This is a Minecraft packetE -type EntityRemoveEffect struct { - EntityID VarInt - EffectID int8 +// BlockChangeRecord is a location/id record of a block to be updated +type BlockChangeRecord struct { + XZ byte + Y byte + BlockID VarInt } -// SetExperience updates the experience bar on the client. +// ConfirmTransaction notifies the client whether a transaction was successful +// or failed (e.g. due to lag). // -// This is a Minecraft packetF -type SetExperience struct { - ExperienceBar float32 - Level VarInt - TotalExperience VarInt +// This is a Minecraft packet +type ConfirmTransaction struct { + ID byte + ActionNumber int16 + Accepted bool } -// EntityProperties updates the properties for an entity. +// WindowClose forces the client to close the window with the given id, +// e.g. a chest getting destroyed. // // This is a Minecraft packet -type EntityProperties struct { - EntityID VarInt - Properties []EntityProperty `length:"int32"` -} - -// EntityProperty is a key/value pair with optional modifiers. -// Used by EntityProperties. -type EntityProperty struct { - Key string - Value float64 - Modifiers []PropertyModifier `length:"VarInt"` +type WindowClose struct { + ID byte } -// PropertyModifier is a modifier on a property. -// Used by EntityProperty. -type PropertyModifier struct { - UUID UUID `as:"raw"` - Amount float64 - Operation int8 +// WindowOpen tells the client to open the inventory window of the given +// type. The ID is used to reference the instance of the window in +// other packets. +// +// This is a Minecraft packet +type WindowOpen struct { + ID byte + Type string + Title format.AnyComponent `as:"json"` + SlotCount byte + EntityID int32 `if:".Type == \"EntityHorse\""` } -// ChunkData sends or updates a single chunk on the client. If New is set -// then biome data should be sent too. +// WindowItems sets every item in a window. // // This is a Minecraft packet -type ChunkData struct { - ChunkX, ChunkZ int32 - New bool - BitMask int32 - Data []byte `length:"VarInt" nolimit:"true"` +type WindowItems struct { + ID byte + Items []ItemStack `length:"int16" as:"raw"` } -// ChunkUnload tells the client to unload the chunk at the specified -// position. +// WindowProperty changes the value of a property of a window. Properties +// vary depending on the window type. // // This is a Minecraft packet -type ChunkUnload struct { - X int32 - Z int32 +type WindowProperty struct { + ID byte + Property int16 + Value int16 } -// MultiBlockChange is used to update a batch of blocks in a single packet. +// WindowSetSlot changes an itemstack in one of the slots in a window. // // This is a Minecraft packet -type MultiBlockChange struct { - ChunkX, ChunkZ int32 - Records []BlockChangeRecord `length:"VarInt"` +type WindowSetSlot struct { + ID byte + Slot int16 + ItemStack ItemStack `as:"raw"` } -// BlockChangeRecord is a location/id record of a block to be updated -type BlockChangeRecord struct { - XZ byte - Y byte - BlockID VarInt +// SetCooldown disables a set item (by id) for the set number of ticks +// +// This is a Minecraft packet +type SetCooldown struct { + ItemID VarInt + Ticks VarInt } -// BlockChange is used to update a single block on the client. +// PluginMessageClientbound is used for custom messages between the client +// and server. This is mainly for plugins/mods but vanilla has a few channels +// registered too. // // This is a Minecraft packet -type BlockChange struct { - Location Position - BlockID VarInt +type PluginMessageClientbound struct { + Channel string + Data []byte `length:"remaining"` } -// BlockAction triggers different actions depending on the target block. +// Disconnect causes the client to disconnect displaying the passed reason. // // This is a Minecraft packet -type BlockAction struct { - Location Position - Byte1 byte - Byte2 byte - BlockType VarInt +type Disconnect struct { + Reason format.AnyComponent `as:"json"` } -// BlockBreakAnimation is used to create and update the block breaking -// animation played when a player starts digging a block. +// EntityAction causes an entity to preform an action based on the passed +// id. // // This is a Minecraft packet -type BlockBreakAnimation struct { - EntityID VarInt - Location Position - Stage int8 +type EntityAction struct { + EntityID int32 + ActionID byte } // Explosion is sent when an explosion is triggered (tnt, creeper etc). @@ -449,6 +321,52 @@ type ExplosionRecord struct { X, Y, Z int8 } +// ChunkUnload tells the client to unload the chunk at the specified +// position. +// +// This is a Minecraft packet +type ChunkUnload struct { + X int32 + Z int32 +} + +// SetCompression updates the compression threshold. +// +// This is a Minecraft packet +type SetCompression struct { + Threshold VarInt +} + +// ChangeGameState is used to modify the game's state like gamemode or +// weather. +// +// This is a Minecraft packet +type ChangeGameState struct { + Reason byte + Value float32 +} + +// KeepAliveClientbound is sent by a server to check if the +// client is still responding and keep the connection open. +// The client should reply with the KeepAliveServerbound +// packet setting ID to the same as this one. +// +// This is a Minecraft packet +type KeepAliveClientbound struct { + ID VarInt +} + +// ChunkData sends or updates a single chunk on the client. If New is set +// then biome data should be sent too. +// +// This is a Minecraft packet +type ChunkData struct { + ChunkX, ChunkZ int32 + New bool + BitMask int32 + Data []byte `length:"VarInt" nolimit:"true"` +} + // Effect plays a sound effect or particle at the target location with the // volume (of sounds) being relative to the player's position unless // DisableRelative is set to true. @@ -461,20 +379,10 @@ type Effect struct { DisableRelative bool } -// SoundEffect plays the named sound at the target location. -// -// This is a Minecraft packet -type SoundEffect struct { - Name string - X, Y, Z int32 - Volume float32 - Pitch byte -} - // Particle spawns particles at the target location with the various // modifiers. Data's length depends on the particle ID. // -// This is a Minecraft packetA +// This is a Minecraft packet type Particle struct { ParticleID int32 LongDistance bool @@ -495,196 +403,310 @@ func particleDataLength(p *Particle) int { return 0 } -// ChangeGameState is used to modify the game's state like gamemode or -// weather. +// SoundEffect plays the named sound at the target location. // -// This is a Minecraft packetB -type ChangeGameState struct { - Reason byte - Value float32 +// This is a Minecraft packet +type SoundEffect struct { + Name string + X, Y, Z int32 + Volume float32 + Pitch byte } -// SpawnGlobalEntity spawns an entity which is visible from anywhere in the -// world. Currently only used for lightning. +// JoinGame is sent after completing the login process. This +// sets the initial state for the client. // -// This is a Minecraft packetC -type SpawnGlobalEntity struct { - EntityID VarInt - Type byte - X, Y, Z int32 +// This is a Minecraft packet +type JoinGame struct { + // The entity id the client will be referenced by + EntityID int32 + // The starting gamemode of the client + Gamemode byte + // The dimension the client is starting in + Dimension int8 + // The difficuilty setting for the server + Difficulty byte + // The max number of players on the server + MaxPlayers byte + // The level type of the server + LevelType string + // Whether the client should reduce the amount of debug + // information it displays in F3 mode + ReducedDebugInfo bool } -// WindowOpen tells the client to open the inventory window of the given -// type. The ID is used to reference the instance of the window in -// other packets. +// Maps updates a single map's contents // -// This is a Minecraft packetD -type WindowOpen struct { - ID byte - Type string - Title format.AnyComponent `as:"json"` - SlotCount byte - EntityID int32 `if:".Type == \"EntityHorse\""` +// This is a Minecraft packet +type Maps struct { + ItemDamage VarInt + Scale int8 + TrackingPosition bool + Icons []MapIcon `length:"VarInt"` + Columns byte + Rows byte `if:".Columns>0"` + X byte `if:".Columns>0"` + Z byte `if:".Columns>0"` + Data []byte `if:".Columns>0" length:"VarInt"` } -// WindowClose forces the client to close the window with the given id, -// e.g. a chest getting destroyed. +// MapIcon is used by Maps +type MapIcon struct { + DirectionType int8 + X, Z int8 +} + +// EntityMove moves the entity with the id by the offsets provided. // -// This is a Minecraft packetE -type WindowClose struct { - ID byte +// This is a Minecraft packet +type EntityMove struct { + EntityID VarInt + DeltaX, DeltaY, DeltaZ int8 + OnGround bool } -// WindowSetSlot changes an itemstack in one of the slots in a window. +// EntityLookAndMove is a combination of EntityMove and EntityLook. // -// This is a Minecraft packetF -type WindowSetSlot struct { - ID byte - Slot int16 - ItemStack ItemStack `as:"raw"` +// This is a Minecraft packet +type EntityLookAndMove struct { + EntityID VarInt + DeltaX, DeltaY, DeltaZ int8 + Yaw, Pitch int8 + OnGround bool } -// WindowItems sets every item in a window. +// EntityLook rotates the entity to the new angles provided. // // This is a Minecraft packet -type WindowItems struct { - ID byte - Items []ItemStack `length:"int16" as:"raw"` +type EntityLook struct { + EntityID VarInt + Yaw, Pitch int8 + OnGround bool } -// WindowProperty changes the value of a property of a window. Properties -// vary depending on the window type. +// Entity does nothing. It is a result of subclassing used in Minecraft. // // This is a Minecraft packet -type WindowProperty struct { - ID byte - Property int16 - Value int16 +type Entity struct { + EntityID VarInt } -// ConfirmTransaction notifies the client whether a transaction was successful -// or failed (e.g. due to lag). +// SignEditorOpen causes the client to open the editor for a sign so that +// it can write to it. Only sent in vanilla when the player places a sign. // // This is a Minecraft packet -type ConfirmTransaction struct { - ID byte - ActionNumber int16 - Accepted bool +type SignEditorOpen struct { + Location Position } -// UpdateSign sets or changes the text on a sign. +// PlayerAbilities is used to modify the players current abilities. Flying, +// creative, god mode etc. // // This is a Minecraft packet -type UpdateSign struct { +type PlayerAbilities struct { + Flags byte + FlyingSpeed float32 + WalkingSpeed float32 +} + +// CombatEvent is used for... you know, I never checked. I have no +// clue. +// +// This is a Minecraft packet +type CombatEvent struct { + Event VarInt + Duration VarInt `if:".Event == 1"` + PlayerID VarInt `if:".Event == 2"` + EntityID int32 `if:".Event == 1 .Event == 2"` + Message format.AnyComponent `as:"json" if:".Event == 2"` +} + +// PlayerInfo is sent by the server for every player connected to the server +// to provide skin and username information as well as ping and gamemode info. +// +// This is a Minecraft packet +type PlayerInfo struct { + Action VarInt + Players []PlayerDetail `length:"VarInt"` +} + +// PlayerDetail is used by PlayerInfo +type PlayerDetail struct { + UUID UUID `as:"raw"` + Name string `if:"..Action==0"` + Properties []PlayerProperty `length:"VarInt" if:"..Action==0"` + GameMode VarInt `if:"..Action==0 ..Action == 1"` + Ping VarInt `if:"..Action==0 ..Action == 2"` + HasDisplay bool `if:"..Action==0 ..Action == 3"` + DisplayName format.AnyComponent `as:"json" if:".HasDisplay==true"` +} + +// PlayerProperty is used by PlayerDetail +type PlayerProperty struct { + Name string + Value string + IsSigned bool + Signature string `if:".IsSigned==true"` +} + +// TeleportPlayer is sent to change the player's position. The client is expected +// to reply to the server with the same positions as contained in this packet +// otherwise will reject future packets. +// +// This is a Minecraft packet +type TeleportPlayer struct { + X, Y, Z float64 + Yaw, Pitch float32 + Flags byte +} + +// EntityUsedBed is sent by the server when a player goes to bed. +// +// This is a Minecraft packet +type EntityUsedBed struct { + EntityID VarInt Location Position - Line1 format.AnyComponent `as:"json"` - Line2 format.AnyComponent `as:"json"` - Line3 format.AnyComponent `as:"json"` - Line4 format.AnyComponent `as:"json"` } -// Maps updates a single map's contents +// EntityDestroy destroys the entities with the ids in the provided slice. // // This is a Minecraft packet -type Maps struct { - ItemDamage VarInt - Scale int8 - TrackingPosition bool - Icons []MapIcon `length:"VarInt"` - Columns byte - Rows byte `if:".Columns>0"` - X byte `if:".Columns>0"` - Z byte `if:".Columns>0"` - Data []byte `if:".Columns>0" length:"VarInt"` +type EntityDestroy struct { + EntityIDs []VarInt `length:"VarInt"` } -// MapIcon is used by Maps -type MapIcon struct { - DirectionType int8 - X, Z int8 +// EntityRemoveEffect removes an effect from an entity. +// +// This is a Minecraft packet +type EntityRemoveEffect struct { + EntityID VarInt + EffectID int8 +} + +// ResourcePackSend causes the client to check its cache for the requested +// resource packet and download it if its missing. Once the resource pack +// is obtained the client will use it. +// +// This is a Minecraft packet +type ResourcePackSend struct { + URL string + Hash string +} + +// Respawn is sent to respawn the player after death or when they move worlds. +// +// This is a Minecraft packet +type Respawn struct { + Dimension int32 + Difficulty byte + Gamemode byte + LevelType string +} + +// EntityHeadLook rotates an entity's head to the new angle. +// +// This is a Minecraft packet +type EntityHeadLook struct { + EntityID VarInt + HeadYaw int8 +} + +// WorldBorder configures the world's border. +// +// This is a Minecraft packet +type WorldBorder struct { + Action VarInt + OldRadius float64 `if:".Action == 3 .Action == 1"` + NewRadius float64 `if:".Action == 3 .Action == 1 .Action == 0"` + Speed VarLong `if:".Action == 3 .Action == 1"` + X, Z float64 `if:".Action == 3 .Action == 2"` + PortalBoundary VarInt `if:".Action == 3"` + WarningTime VarInt `if:".Action == 3 .Action == 4"` + WarningBlocks VarInt `if:".Action == 3 .Action == 5"` } -// UpdateBlockEntity updates the nbt tag of a block entity in the -// world. +// Camera causes the client to spectate the entity with the passed id. +// Use the player's id to de-spectate. // // This is a Minecraft packet -type UpdateBlockEntity struct { - Location Position - Action byte - NBT *nbt.Compound +type Camera struct { + TargetID VarInt } -// SignEditorOpen causes the client to open the editor for a sign so that -// it can write to it. Only sent in vanilla when the player places a sign. +// SetCurrentHotbarSlot changes the player's currently selected hotbar item. // // This is a Minecraft packet -type SignEditorOpen struct { - Location Position +type SetCurrentHotbarSlot struct { + Slot byte } -// Statistics is used to update the statistics screen for the client. +// ScoreboardDisplay is used to set the display position of a scoreboard. // // This is a Minecraft packet -type Statistics struct { - Statistics []Statistic `length:"VarInt"` +type ScoreboardDisplay struct { + Position byte + Name string } -// Statistic is used by Statistics -type Statistic struct { - Name string - Value VarInt +// EntityMetadata updates the metadata for an entity. +// +// This is a Minecraft packet +type EntityMetadata struct { + EntityID VarInt + Metadata Metadata } -// PlayerInfo is sent by the server for every player connected to the server -// to provide skin and username information as well as ping and gamemode info. +// EntityAttach attaches to entities together, either by mounting or leashing. +// -1 can be used at the EntityID to deattach. // // This is a Minecraft packet -type PlayerInfo struct { - Action VarInt - Players []PlayerDetail `length:"VarInt"` +type EntityAttach struct { + EntityID int32 + Vehicle int32 + Leash bool } -// PlayerDetail is used by PlayerInfo -type PlayerDetail struct { - UUID UUID `as:"raw"` - Name string `if:"..Action==0"` - Properties []PlayerProperty `length:"VarInt" if:"..Action==0"` - GameMode VarInt `if:"..Action==0 ..Action == 1"` - Ping VarInt `if:"..Action==0 ..Action == 2"` - HasDisplay bool `if:"..Action==0 ..Action == 3"` - DisplayName format.AnyComponent `as:"json" if:".HasDisplay==true"` +// EntityVelocity sets the velocity of an entity in 1/8000 of a block +// per a tick. +// +// This is a Minecraft packet +type EntityVelocity struct { + EntityID VarInt + VelocityX, VelocityY, VelocityZ int16 } -// PlayerProperty is used by PlayerDetail -type PlayerProperty struct { - Name string - Value string - IsSigned bool - Signature string `if:".IsSigned==true"` +// EntityEquipment is sent to display an item on an entity, like a sword +// or armor. Slot 0 is the held item and slots 1 to 4 are boots, leggings +// chestplate and helmet respectively. +// +// This is a Minecraft packet +type EntityEquipment struct { + EntityID VarInt + Slot VarInt + Item ItemStack `as:"raw"` } -// PlayerAbilities is used to modify the players current abilities. Flying, -// creative, god mode etc. +// SetExperience updates the experience bar on the client. // // This is a Minecraft packet -type PlayerAbilities struct { - Flags byte - FlyingSpeed float32 - WalkingSpeed float32 +type SetExperience struct { + ExperienceBar float32 + Level VarInt + TotalExperience VarInt } -// TabCompleteReply is sent as a reply to a tab completion request. -// The matches should be possible completions for the command/chat the -// player sent. +// UpdateHealth is sent by the server to update the player's health and food. // -// This is a Minecraft packetA -type TabCompleteReply struct { - Matches []string `length:"VarInt"` +// This is a Minecraft packet +type UpdateHealth struct { + Health float32 + Food VarInt + FoodSaturation float32 } // ScoreboardObjective creates/updates a scoreboard objective. // -// This is a Minecraft packetB +// This is a Minecraft packet type ScoreboardObjective struct { Name string Mode byte @@ -692,28 +714,9 @@ type ScoreboardObjective struct { Type string `if:".Mode == 0 .Mode == 2"` } -// UpdateScore is used to update or remove an item from a scoreboard -// objective. -// -// This is a Minecraft packetC -type UpdateScore struct { - Name string - Action byte - ObjectName string - Value VarInt `if:".Action != 1"` -} - -// ScoreboardDisplay is used to set the display position of a scoreboard. -// -// This is a Minecraft packetD -type ScoreboardDisplay struct { - Position byte - Name string -} - // Teams creates and updates teams // -// This is a Minecraft packetE +// This is a Minecraft packet type Teams struct { Name string Mode byte @@ -722,67 +725,39 @@ type Teams struct { Suffix string `if:".Mode == 0 .Mode == 2"` Flags byte `if:".Mode == 0 .Mode == 2"` NameTagVisibility string `if:".Mode == 0 .Mode == 2"` + CollisionRule string `if:".Mode == 0 .Mode == 2"` Color byte `if:".Mode == 0 .Mode == 2"` Players []string `length:"VarInt" if:".Mode == 0 .Mode == 3 .Mode == 4"` } -// PluginMessageClientbound is used for custom messages between the client -// and server. This is mainly for plugins/mods but vanilla has a few channels -// registered too. -// -// This is a Minecraft packetF -type PluginMessageClientbound struct { - Channel string - Data []byte `length:"remaining"` -} - -// Disconnect causes the client to disconnect displaying the passed reason. -// -// This is a Minecraft packet -type Disconnect struct { - Reason format.AnyComponent `as:"json"` -} - -// ServerDifficulty changes the displayed difficulty in the client's menu -// as well as some ui changes for hardcore. -// -// This is a Minecraft packet -type ServerDifficulty struct { - Difficulty byte -} - -// CombatEvent is used for... you know, I never checked. I have no -// clue. +// UpdateScore is used to update or remove an item from a scoreboard +// objective. // // This is a Minecraft packet -type CombatEvent struct { - Event VarInt - Duration VarInt `if:".Event == 1"` - PlayerID VarInt `if:".Event == 2"` - EntityID int32 `if:".Event == 1 .Event == 2"` - Message format.AnyComponent `as:"json" if:".Event == 2"` +type UpdateScore struct { + Name string + Action byte + ObjectName string + Value VarInt `if:".Action != 1"` } -// Camera causes the client to spectate the entity with the passed id. -// Use the player's id to de-spectate. +// SpawnPosition is sent to change the player's current spawn point. Currently +// only used by the client for the compass. // // This is a Minecraft packet -type Camera struct { - TargetID VarInt +type SpawnPosition struct { + Location Position } -// WorldBorder configures the world's border. +// TimeUpdate is sent to sync the world's time to the client, the client +// will manually tick the time itself so this doesn't need to sent repeatedly +// but if the server or client has issues keeping up this can fall out of sync +// so it is a good idea to sent this now and again // // This is a Minecraft packet -type WorldBorder struct { - Action VarInt - OldRadius float64 `if:".Action == 3 .Action == 1"` - NewRadius float64 `if:".Action == 3 .Action == 1 .Action == 0"` - Speed VarLong `if:".Action == 3 .Action == 1"` - X, Z float64 `if:".Action == 3 .Action == 2"` - PortalBoundary VarInt `if:".Action == 3"` - WarningTime VarInt `if:".Action == 3 .Action == 4"` - WarningBlocks VarInt `if:".Action == 3 .Action == 5"` +type TimeUpdate struct { + WorldAge int64 + TimeOfDay int64 } // Title configures an on-screen title. @@ -797,11 +772,15 @@ type Title struct { FadeOut int32 `if:".Action == 2"` } -// SetCompression updates the compression threshold. +// UpdateSign sets or changes the text on a sign. // // This is a Minecraft packet -type SetCompression struct { - Threshold VarInt +type UpdateSign struct { + Location Position + Line1 format.AnyComponent `as:"json"` + Line2 format.AnyComponent `as:"json"` + Line3 format.AnyComponent `as:"json"` + Line4 format.AnyComponent `as:"json"` } // PlayerListHeaderFooter updates the header/footer of the player list. @@ -812,35 +791,57 @@ type PlayerListHeaderFooter struct { Footer format.AnyComponent `as:"json"` } -// ResourcePackSend causes the client to check its cache for the requested -// resource packet and download it if its missing. Once the resource pack -// is obtained the client will use it. +// CollectItem causes the collected item to fly towards the collector. This +// does not destroy the entity. // // This is a Minecraft packet -type ResourcePackSend struct { - URL string - Hash string +type CollectItem struct { + CollectedEntityID VarInt + CollectorEntityID VarInt } -// BossBar displays and/or changes a boss bar that is displayed on the -// top of the client's screen. This is normally used for bosses such as -// the ender dragon or the wither. +// EntityTeleport teleports the entity to the target location. This is +// sent if the entity moves further than EntityMove allows. // // This is a Minecraft packet -type BossBar struct { - UUID UUID `as:"raw"` - Action VarInt - Title format.AnyComponent `as:"json" if:".Action == 0 .Action == 3"` - Health float32 `if:".Action == 0 .Action == 2"` - Color VarInt `if:".Action == 0 .Action == 4"` - Style VarInt `if:".Action == 0 .Action == 4"` - Flags byte `if:".Action == 0 .Action == 5"` +type EntityTeleport struct { + EntityID VarInt + X, Y, Z int32 + Yaw, Pitch int8 + OnGround bool } -// SetCooldown disables a set item (by id) for the set number of ticks +// EntityProperties updates the properties for an entity. // // This is a Minecraft packet -type SetCooldown struct { - ItemID VarInt - Ticks VarInt +type EntityProperties struct { + EntityID VarInt + Properties []EntityProperty `length:"int32"` +} + +// EntityProperty is a key/value pair with optional modifiers. +// Used by EntityProperties. +type EntityProperty struct { + Key string + Value float64 + Modifiers []PropertyModifier `length:"VarInt"` +} + +// PropertyModifier is a modifier on a property. +// Used by EntityProperty. +type PropertyModifier struct { + UUID UUID `as:"raw"` + Amount float64 + Operation int8 +} + +// EntityEffect applies a status effect to an entity for a given duration. +// +// This is a Minecraft packet +type EntityEffect struct { + EntityID VarInt + EffectID int8 + Amplifier int8 + Duration VarInt + HideParticles bool } diff --git a/protocol/play_clientbound_proto.go b/protocol/play_clientbound_proto.go index e4356af..6415bcd 100644 --- a/protocol/play_clientbound_proto.go +++ b/protocol/play_clientbound_proto.go @@ -11,470 +11,404 @@ import ( "math" ) -func (k *KeepAliveClientbound) id() int { return 0 } -func (k *KeepAliveClientbound) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, k.ID); err != nil { +func (s *SpawnObject) id() int { return 0 } +func (s *SpawnObject) write(ww io.Writer) (err error) { + var tmp [4]byte + if err = WriteVarInt(ww, s.EntityID); err != nil { return } - return -} -func (k *KeepAliveClientbound) read(rr io.Reader) (err error) { - if k.ID, err = ReadVarInt(rr); err != nil { + if err = s.UUID.Serialize(ww); err != nil { return } - return -} - -func (j *JoinGame) id() int { return 1 } -func (j *JoinGame) write(ww io.Writer) (err error) { - var tmp [4]byte - tmp[0] = byte(j.EntityID >> 24) - tmp[1] = byte(j.EntityID >> 16) - tmp[2] = byte(j.EntityID >> 8) - tmp[3] = byte(j.EntityID >> 0) + tmp[0] = byte(s.Type >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp[0] = byte(s.X >> 24) + tmp[1] = byte(s.X >> 16) + tmp[2] = byte(s.X >> 8) + tmp[3] = byte(s.X >> 0) if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp[0] = byte(j.Gamemode >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + tmp[0] = byte(s.Y >> 24) + tmp[1] = byte(s.Y >> 16) + tmp[2] = byte(s.Y >> 8) + tmp[3] = byte(s.Y >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp[0] = byte(j.Dimension >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + tmp[0] = byte(s.Z >> 24) + tmp[1] = byte(s.Z >> 16) + tmp[2] = byte(s.Z >> 8) + tmp[3] = byte(s.Z >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp[0] = byte(j.Difficulty >> 0) + tmp[0] = byte(s.Pitch >> 0) if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp[0] = byte(j.MaxPlayers >> 0) + tmp[0] = byte(s.Yaw >> 0) if _, err = ww.Write(tmp[:1]); err != nil { return } - if err = WriteString(ww, j.LevelType); err != nil { + tmp[0] = byte(s.Data >> 24) + tmp[1] = byte(s.Data >> 16) + tmp[2] = byte(s.Data >> 8) + tmp[3] = byte(s.Data >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - if err = WriteBool(ww, j.ReducedDebugInfo); err != nil { + tmp[0] = byte(s.VelocityX >> 8) + tmp[1] = byte(s.VelocityX >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { + return + } + tmp[0] = byte(s.VelocityY >> 8) + tmp[1] = byte(s.VelocityY >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { + return + } + tmp[0] = byte(s.VelocityZ >> 8) + tmp[1] = byte(s.VelocityZ >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { return } return } -func (j *JoinGame) read(rr io.Reader) (err error) { +func (s *SpawnObject) read(rr io.Reader) (err error) { var tmp [4]byte - if _, err = rr.Read(tmp[:4]); err != nil { + if s.EntityID, err = ReadVarInt(rr); err != nil { return } - j.EntityID = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:1]); err != nil { + if err = s.UUID.Deserialize(rr); err != nil { return } - j.Gamemode = (byte(tmp[0]) << 0) if _, err = rr.Read(tmp[:1]); err != nil { return } - j.Dimension = int8((uint8(tmp[0]) << 0)) - if _, err = rr.Read(tmp[:1]); err != nil { + s.Type = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:4]); err != nil { return } - j.Difficulty = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:1]); err != nil { + s.X = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:4]); err != nil { return } - j.MaxPlayers = (byte(tmp[0]) << 0) - if j.LevelType, err = ReadString(rr); err != nil { + s.Y = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:4]); err != nil { return } - if j.ReducedDebugInfo, err = ReadBool(rr); err != nil { + s.Z = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:1]); err != nil { return } - return -} - -func (s *ServerMessage) id() int { return 2 } -func (s *ServerMessage) write(ww io.Writer) (err error) { - var tmp [1]byte - var tmp0 []byte - if tmp0, err = json.Marshal(&s.Message); err != nil { + s.Pitch = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:1]); err != nil { return } - tmp1 := string(tmp0) - if err = WriteString(ww, tmp1); err != nil { + s.Yaw = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:4]); err != nil { return } - tmp[0] = byte(s.Type >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + s.Data = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:2]); err != nil { return } - return -} -func (s *ServerMessage) read(rr io.Reader) (err error) { - var tmp [1]byte - var tmp0 string - if tmp0, err = ReadString(rr); err != nil { - return err - } - if err = json.Unmarshal([]byte(tmp0), &s.Message); err != nil { + s.VelocityX = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + if _, err = rr.Read(tmp[:2]); err != nil { return } - if _, err = rr.Read(tmp[:1]); err != nil { + s.VelocityY = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + if _, err = rr.Read(tmp[:2]); err != nil { return } - s.Type = (byte(tmp[0]) << 0) + s.VelocityZ = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) return } -func (t *TimeUpdate) id() int { return 3 } -func (t *TimeUpdate) write(ww io.Writer) (err error) { - var tmp [8]byte - tmp[0] = byte(t.WorldAge >> 56) - tmp[1] = byte(t.WorldAge >> 48) - tmp[2] = byte(t.WorldAge >> 40) - tmp[3] = byte(t.WorldAge >> 32) - tmp[4] = byte(t.WorldAge >> 24) - tmp[5] = byte(t.WorldAge >> 16) - tmp[6] = byte(t.WorldAge >> 8) - tmp[7] = byte(t.WorldAge >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { +func (s *SpawnExperienceOrb) id() int { return 1 } +func (s *SpawnExperienceOrb) write(ww io.Writer) (err error) { + var tmp [4]byte + if err = WriteVarInt(ww, s.EntityID); err != nil { return } - tmp[0] = byte(t.TimeOfDay >> 56) - tmp[1] = byte(t.TimeOfDay >> 48) - tmp[2] = byte(t.TimeOfDay >> 40) - tmp[3] = byte(t.TimeOfDay >> 32) - tmp[4] = byte(t.TimeOfDay >> 24) - tmp[5] = byte(t.TimeOfDay >> 16) - tmp[6] = byte(t.TimeOfDay >> 8) - tmp[7] = byte(t.TimeOfDay >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + tmp[0] = byte(s.X >> 24) + tmp[1] = byte(s.X >> 16) + tmp[2] = byte(s.X >> 8) + tmp[3] = byte(s.X >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - return -} -func (t *TimeUpdate) read(rr io.Reader) (err error) { - var tmp [8]byte - if _, err = rr.Read(tmp[:8]); err != nil { + tmp[0] = byte(s.Y >> 24) + tmp[1] = byte(s.Y >> 16) + tmp[2] = byte(s.Y >> 8) + tmp[3] = byte(s.Y >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - t.WorldAge = int64((uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56)) - if _, err = rr.Read(tmp[:8]); err != nil { + tmp[0] = byte(s.Z >> 24) + tmp[1] = byte(s.Z >> 16) + tmp[2] = byte(s.Z >> 8) + tmp[3] = byte(s.Z >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - t.TimeOfDay = int64((uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56)) - return -} - -func (e *EntityEquipment) id() int { return 4 } -func (e *EntityEquipment) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, e.EntityID); err != nil { + tmp[0] = byte(s.Count >> 8) + tmp[1] = byte(s.Count >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { return } - if err = WriteVarInt(ww, e.Slot); err != nil { + return +} +func (s *SpawnExperienceOrb) read(rr io.Reader) (err error) { + var tmp [4]byte + if s.EntityID, err = ReadVarInt(rr); err != nil { return } - if err = e.Item.Serialize(ww); err != nil { + if _, err = rr.Read(tmp[:4]); err != nil { return } - return -} -func (e *EntityEquipment) read(rr io.Reader) (err error) { - if e.EntityID, err = ReadVarInt(rr); err != nil { + s.X = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:4]); err != nil { return } - if e.Slot, err = ReadVarInt(rr); err != nil { + s.Y = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:4]); err != nil { return } - if err = e.Item.Deserialize(rr); err != nil { + s.Z = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:2]); err != nil { return } + s.Count = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) return } -func (s *SpawnPosition) id() int { return 5 } -func (s *SpawnPosition) write(ww io.Writer) (err error) { - var tmp [8]byte - tmp[0] = byte(s.Location >> 56) - tmp[1] = byte(s.Location >> 48) - tmp[2] = byte(s.Location >> 40) - tmp[3] = byte(s.Location >> 32) - tmp[4] = byte(s.Location >> 24) - tmp[5] = byte(s.Location >> 16) - tmp[6] = byte(s.Location >> 8) - tmp[7] = byte(s.Location >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { +func (s *SpawnGlobalEntity) id() int { return 2 } +func (s *SpawnGlobalEntity) write(ww io.Writer) (err error) { + var tmp [4]byte + if err = WriteVarInt(ww, s.EntityID); err != nil { return } - return -} -func (s *SpawnPosition) read(rr io.Reader) (err error) { - var tmp [8]byte - if _, err = rr.Read(tmp[:8]); err != nil { + tmp[0] = byte(s.Type >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - s.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) - return -} - -func (u *UpdateHealth) id() int { return 6 } -func (u *UpdateHealth) write(ww io.Writer) (err error) { - var tmp [4]byte - tmp0 := math.Float32bits(u.Health) - tmp[0] = byte(tmp0 >> 24) - tmp[1] = byte(tmp0 >> 16) - tmp[2] = byte(tmp0 >> 8) - tmp[3] = byte(tmp0 >> 0) + tmp[0] = byte(s.X >> 24) + tmp[1] = byte(s.X >> 16) + tmp[2] = byte(s.X >> 8) + tmp[3] = byte(s.X >> 0) if _, err = ww.Write(tmp[:4]); err != nil { return } - if err = WriteVarInt(ww, u.Food); err != nil { + tmp[0] = byte(s.Y >> 24) + tmp[1] = byte(s.Y >> 16) + tmp[2] = byte(s.Y >> 8) + tmp[3] = byte(s.Y >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp1 := math.Float32bits(u.FoodSaturation) - tmp[0] = byte(tmp1 >> 24) - tmp[1] = byte(tmp1 >> 16) - tmp[2] = byte(tmp1 >> 8) - tmp[3] = byte(tmp1 >> 0) + tmp[0] = byte(s.Z >> 24) + tmp[1] = byte(s.Z >> 16) + tmp[2] = byte(s.Z >> 8) + tmp[3] = byte(s.Z >> 0) if _, err = ww.Write(tmp[:4]); err != nil { return } return } -func (u *UpdateHealth) read(rr io.Reader) (err error) { +func (s *SpawnGlobalEntity) read(rr io.Reader) (err error) { var tmp [4]byte - var tmp0 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + if s.EntityID, err = ReadVarInt(rr); err != nil { return } - tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - u.Health = math.Float32frombits(tmp0) - if u.Food, err = ReadVarInt(rr); err != nil { + if _, err = rr.Read(tmp[:1]); err != nil { return } - var tmp1 uint32 + s.Type = (byte(tmp[0]) << 0) if _, err = rr.Read(tmp[:4]); err != nil { return } - tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - u.FoodSaturation = math.Float32frombits(tmp1) + s.X = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:4]); err != nil { + return + } + s.Y = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:4]); err != nil { + return + } + s.Z = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) return } -func (r *Respawn) id() int { return 7 } -func (r *Respawn) write(ww io.Writer) (err error) { +func (s *SpawnMob) id() int { return 3 } +func (s *SpawnMob) write(ww io.Writer) (err error) { var tmp [4]byte - tmp[0] = byte(r.Dimension >> 24) - tmp[1] = byte(r.Dimension >> 16) - tmp[2] = byte(r.Dimension >> 8) - tmp[3] = byte(r.Dimension >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + if err = WriteVarInt(ww, s.EntityID); err != nil { return } - tmp[0] = byte(r.Difficulty >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + if err = s.UUID.Serialize(ww); err != nil { return } - tmp[0] = byte(r.Gamemode >> 0) + tmp[0] = byte(s.Type >> 0) if _, err = ww.Write(tmp[:1]); err != nil { return } - if err = WriteString(ww, r.LevelType); err != nil { - return - } - return -} -func (r *Respawn) read(rr io.Reader) (err error) { - var tmp [4]byte - if _, err = rr.Read(tmp[:4]); err != nil { + tmp[0] = byte(s.X >> 24) + tmp[1] = byte(s.X >> 16) + tmp[2] = byte(s.X >> 8) + tmp[3] = byte(s.X >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - r.Dimension = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:1]); err != nil { + tmp[0] = byte(s.Y >> 24) + tmp[1] = byte(s.Y >> 16) + tmp[2] = byte(s.Y >> 8) + tmp[3] = byte(s.Y >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - r.Difficulty = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:1]); err != nil { + tmp[0] = byte(s.Z >> 24) + tmp[1] = byte(s.Z >> 16) + tmp[2] = byte(s.Z >> 8) + tmp[3] = byte(s.Z >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - r.Gamemode = (byte(tmp[0]) << 0) - if r.LevelType, err = ReadString(rr); err != nil { + tmp[0] = byte(s.Yaw >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - return -} - -func (t *TeleportPlayer) id() int { return 8 } -func (t *TeleportPlayer) write(ww io.Writer) (err error) { - var tmp [8]byte - tmp0 := math.Float64bits(t.X) - tmp[0] = byte(tmp0 >> 56) - tmp[1] = byte(tmp0 >> 48) - tmp[2] = byte(tmp0 >> 40) - tmp[3] = byte(tmp0 >> 32) - tmp[4] = byte(tmp0 >> 24) - tmp[5] = byte(tmp0 >> 16) - tmp[6] = byte(tmp0 >> 8) - tmp[7] = byte(tmp0 >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + tmp[0] = byte(s.Pitch >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp1 := math.Float64bits(t.Y) - tmp[0] = byte(tmp1 >> 56) - tmp[1] = byte(tmp1 >> 48) - tmp[2] = byte(tmp1 >> 40) - tmp[3] = byte(tmp1 >> 32) - tmp[4] = byte(tmp1 >> 24) - tmp[5] = byte(tmp1 >> 16) - tmp[6] = byte(tmp1 >> 8) - tmp[7] = byte(tmp1 >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + tmp[0] = byte(s.HeadPitch >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp2 := math.Float64bits(t.Z) - tmp[0] = byte(tmp2 >> 56) - tmp[1] = byte(tmp2 >> 48) - tmp[2] = byte(tmp2 >> 40) - tmp[3] = byte(tmp2 >> 32) - tmp[4] = byte(tmp2 >> 24) - tmp[5] = byte(tmp2 >> 16) - tmp[6] = byte(tmp2 >> 8) - tmp[7] = byte(tmp2 >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + tmp[0] = byte(s.VelocityX >> 8) + tmp[1] = byte(s.VelocityX >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { return } - tmp3 := math.Float32bits(t.Yaw) - tmp[0] = byte(tmp3 >> 24) - tmp[1] = byte(tmp3 >> 16) - tmp[2] = byte(tmp3 >> 8) - tmp[3] = byte(tmp3 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + tmp[0] = byte(s.VelocityY >> 8) + tmp[1] = byte(s.VelocityY >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { return } - tmp4 := math.Float32bits(t.Pitch) - tmp[0] = byte(tmp4 >> 24) - tmp[1] = byte(tmp4 >> 16) - tmp[2] = byte(tmp4 >> 8) - tmp[3] = byte(tmp4 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + tmp[0] = byte(s.VelocityZ >> 8) + tmp[1] = byte(s.VelocityZ >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { return } - tmp[0] = byte(t.Flags >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + if err = writeMetadata(ww, s.Metadata); err != nil { return } return } -func (t *TeleportPlayer) read(rr io.Reader) (err error) { - var tmp [8]byte - var tmp0 uint64 - if _, err = rr.Read(tmp[:8]); err != nil { +func (s *SpawnMob) read(rr io.Reader) (err error) { + var tmp [4]byte + if s.EntityID, err = ReadVarInt(rr); err != nil { return } - tmp0 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) - t.X = math.Float64frombits(tmp0) - var tmp1 uint64 - if _, err = rr.Read(tmp[:8]); err != nil { + if err = s.UUID.Deserialize(rr); err != nil { return } - tmp1 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) - t.Y = math.Float64frombits(tmp1) - var tmp2 uint64 - if _, err = rr.Read(tmp[:8]); err != nil { + if _, err = rr.Read(tmp[:1]); err != nil { return } - tmp2 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) - t.Z = math.Float64frombits(tmp2) - var tmp3 uint32 + s.Type = (byte(tmp[0]) << 0) if _, err = rr.Read(tmp[:4]); err != nil { return } - tmp3 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - t.Yaw = math.Float32frombits(tmp3) - var tmp4 uint32 + s.X = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) if _, err = rr.Read(tmp[:4]); err != nil { return } - tmp4 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - t.Pitch = math.Float32frombits(tmp4) + s.Y = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:4]); err != nil { + return + } + s.Z = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) if _, err = rr.Read(tmp[:1]); err != nil { return } - t.Flags = (byte(tmp[0]) << 0) - return -} - -func (s *SetCurrentHotbarSlot) id() int { return 9 } -func (s *SetCurrentHotbarSlot) write(ww io.Writer) (err error) { - var tmp [1]byte - tmp[0] = byte(s.Slot >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + s.Yaw = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:1]); err != nil { return } - return -} -func (s *SetCurrentHotbarSlot) read(rr io.Reader) (err error) { - var tmp [1]byte + s.Pitch = int8((uint8(tmp[0]) << 0)) if _, err = rr.Read(tmp[:1]); err != nil { return } - s.Slot = (byte(tmp[0]) << 0) - return -} - -func (e *EntityUsedBed) id() int { return 10 } -func (e *EntityUsedBed) write(ww io.Writer) (err error) { - var tmp [8]byte - if err = WriteVarInt(ww, e.EntityID); err != nil { + s.HeadPitch = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:2]); err != nil { return } - tmp[0] = byte(e.Location >> 56) - tmp[1] = byte(e.Location >> 48) - tmp[2] = byte(e.Location >> 40) - tmp[3] = byte(e.Location >> 32) - tmp[4] = byte(e.Location >> 24) - tmp[5] = byte(e.Location >> 16) - tmp[6] = byte(e.Location >> 8) - tmp[7] = byte(e.Location >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + s.VelocityX = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + if _, err = rr.Read(tmp[:2]); err != nil { return } - return -} -func (e *EntityUsedBed) read(rr io.Reader) (err error) { - var tmp [8]byte - if e.EntityID, err = ReadVarInt(rr); err != nil { + s.VelocityY = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + if _, err = rr.Read(tmp[:2]); err != nil { return } - if _, err = rr.Read(tmp[:8]); err != nil { + s.VelocityZ = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + if s.Metadata, err = readMetadata(rr); err != nil { return } - e.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) return } -func (a *Animation) id() int { return 11 } -func (a *Animation) write(ww io.Writer) (err error) { - var tmp [1]byte - if err = WriteVarInt(ww, a.EntityID); err != nil { +func (s *SpawnPainting) id() int { return 4 } +func (s *SpawnPainting) write(ww io.Writer) (err error) { + var tmp [8]byte + if err = WriteVarInt(ww, s.EntityID); err != nil { return } - tmp[0] = byte(a.AnimationID >> 0) + if err = WriteString(ww, s.Title); err != nil { + return + } + tmp[0] = byte(s.Location >> 56) + tmp[1] = byte(s.Location >> 48) + tmp[2] = byte(s.Location >> 40) + tmp[3] = byte(s.Location >> 32) + tmp[4] = byte(s.Location >> 24) + tmp[5] = byte(s.Location >> 16) + tmp[6] = byte(s.Location >> 8) + tmp[7] = byte(s.Location >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { + return + } + tmp[0] = byte(s.Direction >> 0) if _, err = ww.Write(tmp[:1]); err != nil { return } return } -func (a *Animation) read(rr io.Reader) (err error) { - var tmp [1]byte - if a.EntityID, err = ReadVarInt(rr); err != nil { +func (s *SpawnPainting) read(rr io.Reader) (err error) { + var tmp [8]byte + if s.EntityID, err = ReadVarInt(rr); err != nil { + return + } + if s.Title, err = ReadString(rr); err != nil { + return + } + if _, err = rr.Read(tmp[:8]); err != nil { return } + s.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) if _, err = rr.Read(tmp[:1]); err != nil { return } - a.AnimationID = (byte(tmp[0]) << 0) + s.Direction = (byte(tmp[0]) << 0) return } -func (s *SpawnPlayer) id() int { return 12 } +func (s *SpawnPlayer) id() int { return 5 } func (s *SpawnPlayer) write(ww io.Writer) (err error) { var tmp [4]byte if err = WriteVarInt(ww, s.EntityID); err != nil { @@ -551,693 +485,753 @@ func (s *SpawnPlayer) read(rr io.Reader) (err error) { return } -func (c *CollectItem) id() int { return 13 } -func (c *CollectItem) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, c.CollectedEntityID); err != nil { +func (a *Animation) id() int { return 6 } +func (a *Animation) write(ww io.Writer) (err error) { + var tmp [1]byte + if err = WriteVarInt(ww, a.EntityID); err != nil { return } - if err = WriteVarInt(ww, c.CollectorEntityID); err != nil { + tmp[0] = byte(a.AnimationID >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } return } -func (c *CollectItem) read(rr io.Reader) (err error) { - if c.CollectedEntityID, err = ReadVarInt(rr); err != nil { +func (a *Animation) read(rr io.Reader) (err error) { + var tmp [1]byte + if a.EntityID, err = ReadVarInt(rr); err != nil { return } - if c.CollectorEntityID, err = ReadVarInt(rr); err != nil { + if _, err = rr.Read(tmp[:1]); err != nil { return } + a.AnimationID = (byte(tmp[0]) << 0) return } -func (s *SpawnObject) id() int { return 14 } -func (s *SpawnObject) write(ww io.Writer) (err error) { - var tmp [4]byte - if err = WriteVarInt(ww, s.EntityID); err != nil { +func (s *Statistics) id() int { return 7 } +func (s *Statistics) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, VarInt(len(s.Statistics))); err != nil { return } - if err = s.UUID.Serialize(ww); err != nil { - return - } - tmp[0] = byte(s.Type >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp[0] = byte(s.X >> 24) - tmp[1] = byte(s.X >> 16) - tmp[2] = byte(s.X >> 8) - tmp[3] = byte(s.X >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - tmp[0] = byte(s.Y >> 24) - tmp[1] = byte(s.Y >> 16) - tmp[2] = byte(s.Y >> 8) - tmp[3] = byte(s.Y >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return + for tmp0 := range s.Statistics { + if err = WriteString(ww, s.Statistics[tmp0].Name); err != nil { + return + } + if err = WriteVarInt(ww, s.Statistics[tmp0].Value); err != nil { + return + } } - tmp[0] = byte(s.Z >> 24) - tmp[1] = byte(s.Z >> 16) - tmp[2] = byte(s.Z >> 8) - tmp[3] = byte(s.Z >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + return +} +func (s *Statistics) read(rr io.Reader) (err error) { + var tmp0 VarInt + if tmp0, err = ReadVarInt(rr); err != nil { return } - tmp[0] = byte(s.Pitch >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return + if tmp0 > math.MaxInt16 { + return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) } - tmp[0] = byte(s.Yaw >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return + if tmp0 < 0 { + return fmt.Errorf("negative array size: %d < 0", tmp0) } - tmp[0] = byte(s.Data >> 24) - tmp[1] = byte(s.Data >> 16) - tmp[2] = byte(s.Data >> 8) - tmp[3] = byte(s.Data >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return + s.Statistics = make([]Statistic, tmp0) + for tmp1 := range s.Statistics { + if s.Statistics[tmp1].Name, err = ReadString(rr); err != nil { + return + } + if s.Statistics[tmp1].Value, err = ReadVarInt(rr); err != nil { + return + } } - tmp[0] = byte(s.VelocityX >> 8) - tmp[1] = byte(s.VelocityX >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { + return +} + +func (b *BlockBreakAnimation) id() int { return 8 } +func (b *BlockBreakAnimation) write(ww io.Writer) (err error) { + var tmp [8]byte + if err = WriteVarInt(ww, b.EntityID); err != nil { return } - tmp[0] = byte(s.VelocityY >> 8) - tmp[1] = byte(s.VelocityY >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { + tmp[0] = byte(b.Location >> 56) + tmp[1] = byte(b.Location >> 48) + tmp[2] = byte(b.Location >> 40) + tmp[3] = byte(b.Location >> 32) + tmp[4] = byte(b.Location >> 24) + tmp[5] = byte(b.Location >> 16) + tmp[6] = byte(b.Location >> 8) + tmp[7] = byte(b.Location >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } - tmp[0] = byte(s.VelocityZ >> 8) - tmp[1] = byte(s.VelocityZ >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { + tmp[0] = byte(b.Stage >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } return } -func (s *SpawnObject) read(rr io.Reader) (err error) { - var tmp [4]byte - if s.EntityID, err = ReadVarInt(rr); err != nil { +func (b *BlockBreakAnimation) read(rr io.Reader) (err error) { + var tmp [8]byte + if b.EntityID, err = ReadVarInt(rr); err != nil { return } - if err = s.UUID.Deserialize(rr); err != nil { + if _, err = rr.Read(tmp[:8]); err != nil { return } + b.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) if _, err = rr.Read(tmp[:1]); err != nil { return } - s.Type = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:4]); err != nil { + b.Stage = int8((uint8(tmp[0]) << 0)) + return +} + +func (u *UpdateBlockEntity) id() int { return 9 } +func (u *UpdateBlockEntity) write(ww io.Writer) (err error) { + var tmp [8]byte + tmp[0] = byte(u.Location >> 56) + tmp[1] = byte(u.Location >> 48) + tmp[2] = byte(u.Location >> 40) + tmp[3] = byte(u.Location >> 32) + tmp[4] = byte(u.Location >> 24) + tmp[5] = byte(u.Location >> 16) + tmp[6] = byte(u.Location >> 8) + tmp[7] = byte(u.Location >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } - s.X = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:4]); err != nil { + tmp[0] = byte(u.Action >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - s.Y = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:4]); err != nil { + if err = WriteNBT(ww, u.NBT); err != nil { return } - s.Z = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:1]); err != nil { + return +} +func (u *UpdateBlockEntity) read(rr io.Reader) (err error) { + var tmp [8]byte + if _, err = rr.Read(tmp[:8]); err != nil { return } - s.Pitch = int8((uint8(tmp[0]) << 0)) + u.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) if _, err = rr.Read(tmp[:1]); err != nil { return } - s.Yaw = int8((uint8(tmp[0]) << 0)) - if _, err = rr.Read(tmp[:4]); err != nil { - return - } - s.Data = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:2]); err != nil { - return - } - s.VelocityX = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) - if _, err = rr.Read(tmp[:2]); err != nil { - return - } - s.VelocityY = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) - if _, err = rr.Read(tmp[:2]); err != nil { + u.Action = (byte(tmp[0]) << 0) + if u.NBT, err = ReadNBT(rr); err != nil { return } - s.VelocityZ = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) return } -func (s *SpawnMob) id() int { return 15 } -func (s *SpawnMob) write(ww io.Writer) (err error) { - var tmp [4]byte - if err = WriteVarInt(ww, s.EntityID); err != nil { - return - } - if err = s.UUID.Serialize(ww); err != nil { +func (b *BlockAction) id() int { return 10 } +func (b *BlockAction) write(ww io.Writer) (err error) { + var tmp [8]byte + tmp[0] = byte(b.Location >> 56) + tmp[1] = byte(b.Location >> 48) + tmp[2] = byte(b.Location >> 40) + tmp[3] = byte(b.Location >> 32) + tmp[4] = byte(b.Location >> 24) + tmp[5] = byte(b.Location >> 16) + tmp[6] = byte(b.Location >> 8) + tmp[7] = byte(b.Location >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } - tmp[0] = byte(s.Type >> 0) + tmp[0] = byte(b.Byte1 >> 0) if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp[0] = byte(s.X >> 24) - tmp[1] = byte(s.X >> 16) - tmp[2] = byte(s.X >> 8) - tmp[3] = byte(s.X >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + tmp[0] = byte(b.Byte2 >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp[0] = byte(s.Y >> 24) - tmp[1] = byte(s.Y >> 16) - tmp[2] = byte(s.Y >> 8) - tmp[3] = byte(s.Y >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + if err = WriteVarInt(ww, b.BlockType); err != nil { return } - tmp[0] = byte(s.Z >> 24) - tmp[1] = byte(s.Z >> 16) - tmp[2] = byte(s.Z >> 8) - tmp[3] = byte(s.Z >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + return +} +func (b *BlockAction) read(rr io.Reader) (err error) { + var tmp [8]byte + if _, err = rr.Read(tmp[:8]); err != nil { return } - tmp[0] = byte(s.Yaw >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + b.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) + if _, err = rr.Read(tmp[:1]); err != nil { return } - tmp[0] = byte(s.Pitch >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + b.Byte1 = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:1]); err != nil { return } - tmp[0] = byte(s.HeadPitch >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + b.Byte2 = (byte(tmp[0]) << 0) + if b.BlockType, err = ReadVarInt(rr); err != nil { return } - tmp[0] = byte(s.VelocityX >> 8) - tmp[1] = byte(s.VelocityX >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { + return +} + +func (b *BlockChange) id() int { return 11 } +func (b *BlockChange) write(ww io.Writer) (err error) { + var tmp [8]byte + tmp[0] = byte(b.Location >> 56) + tmp[1] = byte(b.Location >> 48) + tmp[2] = byte(b.Location >> 40) + tmp[3] = byte(b.Location >> 32) + tmp[4] = byte(b.Location >> 24) + tmp[5] = byte(b.Location >> 16) + tmp[6] = byte(b.Location >> 8) + tmp[7] = byte(b.Location >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } - tmp[0] = byte(s.VelocityY >> 8) - tmp[1] = byte(s.VelocityY >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { + if err = WriteVarInt(ww, b.BlockID); err != nil { return } - tmp[0] = byte(s.VelocityZ >> 8) - tmp[1] = byte(s.VelocityZ >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { + return +} +func (b *BlockChange) read(rr io.Reader) (err error) { + var tmp [8]byte + if _, err = rr.Read(tmp[:8]); err != nil { return } - if err = writeMetadata(ww, s.Metadata); err != nil { + b.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) + if b.BlockID, err = ReadVarInt(rr); err != nil { return } return } -func (s *SpawnMob) read(rr io.Reader) (err error) { + +func (b *BossBar) id() int { return 12 } +func (b *BossBar) write(ww io.Writer) (err error) { var tmp [4]byte - if s.EntityID, err = ReadVarInt(rr); err != nil { - return - } - if err = s.UUID.Deserialize(rr); err != nil { + if err = b.UUID.Serialize(ww); err != nil { return } - if _, err = rr.Read(tmp[:1]); err != nil { + if err = WriteVarInt(ww, b.Action); err != nil { return } - s.Type = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:4]); err != nil { - return + if b.Action == 0 || b.Action == 3 { + var tmp0 []byte + if tmp0, err = json.Marshal(&b.Title); err != nil { + return + } + tmp1 := string(tmp0) + if err = WriteString(ww, tmp1); err != nil { + return + } } - s.X = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:4]); err != nil { - return + if b.Action == 0 || b.Action == 2 { + tmp2 := math.Float32bits(b.Health) + tmp[0] = byte(tmp2 >> 24) + tmp[1] = byte(tmp2 >> 16) + tmp[2] = byte(tmp2 >> 8) + tmp[3] = byte(tmp2 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { + return + } } - s.Y = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:4]); err != nil { + if b.Action == 0 || b.Action == 4 { + if err = WriteVarInt(ww, b.Color); err != nil { + return + } + if err = WriteVarInt(ww, b.Style); err != nil { + return + } + } + if b.Action == 0 || b.Action == 5 { + tmp[0] = byte(b.Flags >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + } + return +} +func (b *BossBar) read(rr io.Reader) (err error) { + var tmp [4]byte + if err = b.UUID.Deserialize(rr); err != nil { return } - s.Z = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:1]); err != nil { + if b.Action, err = ReadVarInt(rr); err != nil { return } - s.Yaw = int8((uint8(tmp[0]) << 0)) - if _, err = rr.Read(tmp[:1]); err != nil { + if b.Action == 0 || b.Action == 3 { + var tmp0 string + if tmp0, err = ReadString(rr); err != nil { + return err + } + if err = json.Unmarshal([]byte(tmp0), &b.Title); err != nil { + return + } + } + if b.Action == 0 || b.Action == 2 { + var tmp1 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { + return + } + tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + b.Health = math.Float32frombits(tmp1) + } + if b.Action == 0 || b.Action == 4 { + if b.Color, err = ReadVarInt(rr); err != nil { + return + } + if b.Style, err = ReadVarInt(rr); err != nil { + return + } + } + if b.Action == 0 || b.Action == 5 { + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + b.Flags = (byte(tmp[0]) << 0) + } + return +} + +func (s *ServerDifficulty) id() int { return 13 } +func (s *ServerDifficulty) write(ww io.Writer) (err error) { + var tmp [1]byte + tmp[0] = byte(s.Difficulty >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - s.Pitch = int8((uint8(tmp[0]) << 0)) + return +} +func (s *ServerDifficulty) read(rr io.Reader) (err error) { + var tmp [1]byte if _, err = rr.Read(tmp[:1]); err != nil { return } - s.HeadPitch = int8((uint8(tmp[0]) << 0)) - if _, err = rr.Read(tmp[:2]); err != nil { + s.Difficulty = (byte(tmp[0]) << 0) + return +} + +func (t *TabCompleteReply) id() int { return 14 } +func (t *TabCompleteReply) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, VarInt(len(t.Matches))); err != nil { return } - s.VelocityX = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) - if _, err = rr.Read(tmp[:2]); err != nil { - return + for tmp0 := range t.Matches { + if err = WriteString(ww, t.Matches[tmp0]); err != nil { + return + } } - s.VelocityY = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) - if _, err = rr.Read(tmp[:2]); err != nil { + return +} +func (t *TabCompleteReply) read(rr io.Reader) (err error) { + var tmp0 VarInt + if tmp0, err = ReadVarInt(rr); err != nil { return } - s.VelocityZ = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) - if s.Metadata, err = readMetadata(rr); err != nil { - return + if tmp0 > math.MaxInt16 { + return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) + } + if tmp0 < 0 { + return fmt.Errorf("negative array size: %d < 0", tmp0) + } + t.Matches = make([]string, tmp0) + for tmp1 := range t.Matches { + if t.Matches[tmp1], err = ReadString(rr); err != nil { + return + } } return } -func (s *SpawnPainting) id() int { return 16 } -func (s *SpawnPainting) write(ww io.Writer) (err error) { - var tmp [8]byte - if err = WriteVarInt(ww, s.EntityID); err != nil { - return - } - if err = WriteString(ww, s.Title); err != nil { +func (s *ServerMessage) id() int { return 15 } +func (s *ServerMessage) write(ww io.Writer) (err error) { + var tmp [1]byte + var tmp0 []byte + if tmp0, err = json.Marshal(&s.Message); err != nil { return } - tmp[0] = byte(s.Location >> 56) - tmp[1] = byte(s.Location >> 48) - tmp[2] = byte(s.Location >> 40) - tmp[3] = byte(s.Location >> 32) - tmp[4] = byte(s.Location >> 24) - tmp[5] = byte(s.Location >> 16) - tmp[6] = byte(s.Location >> 8) - tmp[7] = byte(s.Location >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + tmp1 := string(tmp0) + if err = WriteString(ww, tmp1); err != nil { return } - tmp[0] = byte(s.Direction >> 0) + tmp[0] = byte(s.Type >> 0) if _, err = ww.Write(tmp[:1]); err != nil { return } return } -func (s *SpawnPainting) read(rr io.Reader) (err error) { - var tmp [8]byte - if s.EntityID, err = ReadVarInt(rr); err != nil { - return - } - if s.Title, err = ReadString(rr); err != nil { - return +func (s *ServerMessage) read(rr io.Reader) (err error) { + var tmp [1]byte + var tmp0 string + if tmp0, err = ReadString(rr); err != nil { + return err } - if _, err = rr.Read(tmp[:8]); err != nil { + if err = json.Unmarshal([]byte(tmp0), &s.Message); err != nil { return } - s.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) if _, err = rr.Read(tmp[:1]); err != nil { return } - s.Direction = (byte(tmp[0]) << 0) + s.Type = (byte(tmp[0]) << 0) return } -func (s *SpawnExperienceOrb) id() int { return 17 } -func (s *SpawnExperienceOrb) write(ww io.Writer) (err error) { +func (m *MultiBlockChange) id() int { return 16 } +func (m *MultiBlockChange) write(ww io.Writer) (err error) { var tmp [4]byte - if err = WriteVarInt(ww, s.EntityID); err != nil { - return - } - tmp[0] = byte(s.X >> 24) - tmp[1] = byte(s.X >> 16) - tmp[2] = byte(s.X >> 8) - tmp[3] = byte(s.X >> 0) + tmp[0] = byte(m.ChunkX >> 24) + tmp[1] = byte(m.ChunkX >> 16) + tmp[2] = byte(m.ChunkX >> 8) + tmp[3] = byte(m.ChunkX >> 0) if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp[0] = byte(s.Y >> 24) - tmp[1] = byte(s.Y >> 16) - tmp[2] = byte(s.Y >> 8) - tmp[3] = byte(s.Y >> 0) + tmp[0] = byte(m.ChunkZ >> 24) + tmp[1] = byte(m.ChunkZ >> 16) + tmp[2] = byte(m.ChunkZ >> 8) + tmp[3] = byte(m.ChunkZ >> 0) if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp[0] = byte(s.Z >> 24) - tmp[1] = byte(s.Z >> 16) - tmp[2] = byte(s.Z >> 8) - tmp[3] = byte(s.Z >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + if err = WriteVarInt(ww, VarInt(len(m.Records))); err != nil { return } - tmp[0] = byte(s.Count >> 8) - tmp[1] = byte(s.Count >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { - return + for tmp0 := range m.Records { + tmp[0] = byte(m.Records[tmp0].XZ >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp[0] = byte(m.Records[tmp0].Y >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + if err = WriteVarInt(ww, m.Records[tmp0].BlockID); err != nil { + return + } } return } -func (s *SpawnExperienceOrb) read(rr io.Reader) (err error) { +func (m *MultiBlockChange) read(rr io.Reader) (err error) { var tmp [4]byte - if s.EntityID, err = ReadVarInt(rr); err != nil { - return - } if _, err = rr.Read(tmp[:4]); err != nil { return } - s.X = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + m.ChunkX = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) if _, err = rr.Read(tmp[:4]); err != nil { return } - s.Y = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:4]); err != nil { + m.ChunkZ = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + var tmp0 VarInt + if tmp0, err = ReadVarInt(rr); err != nil { return } - s.Z = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:2]); err != nil { - return + if tmp0 > math.MaxInt16 { + return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) + } + if tmp0 < 0 { + return fmt.Errorf("negative array size: %d < 0", tmp0) + } + m.Records = make([]BlockChangeRecord, tmp0) + for tmp1 := range m.Records { + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + m.Records[tmp1].XZ = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + m.Records[tmp1].Y = (byte(tmp[0]) << 0) + if m.Records[tmp1].BlockID, err = ReadVarInt(rr); err != nil { + return + } } - s.Count = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) return } -func (e *EntityVelocity) id() int { return 18 } -func (e *EntityVelocity) write(ww io.Writer) (err error) { +func (c *ConfirmTransaction) id() int { return 17 } +func (c *ConfirmTransaction) write(ww io.Writer) (err error) { var tmp [2]byte - if err = WriteVarInt(ww, e.EntityID); err != nil { - return - } - tmp[0] = byte(e.VelocityX >> 8) - tmp[1] = byte(e.VelocityX >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { + tmp[0] = byte(c.ID >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp[0] = byte(e.VelocityY >> 8) - tmp[1] = byte(e.VelocityY >> 0) + tmp[0] = byte(c.ActionNumber >> 8) + tmp[1] = byte(c.ActionNumber >> 0) if _, err = ww.Write(tmp[:2]); err != nil { return } - tmp[0] = byte(e.VelocityZ >> 8) - tmp[1] = byte(e.VelocityZ >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { + if err = WriteBool(ww, c.Accepted); err != nil { return } return } -func (e *EntityVelocity) read(rr io.Reader) (err error) { +func (c *ConfirmTransaction) read(rr io.Reader) (err error) { var tmp [2]byte - if e.EntityID, err = ReadVarInt(rr); err != nil { + if _, err = rr.Read(tmp[:1]); err != nil { return } + c.ID = (byte(tmp[0]) << 0) if _, err = rr.Read(tmp[:2]); err != nil { return } - e.VelocityX = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) - if _, err = rr.Read(tmp[:2]); err != nil { - return - } - e.VelocityY = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) - if _, err = rr.Read(tmp[:2]); err != nil { + c.ActionNumber = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + if c.Accepted, err = ReadBool(rr); err != nil { return } - e.VelocityZ = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) return } -func (e *EntityDestroy) id() int { return 19 } -func (e *EntityDestroy) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, VarInt(len(e.EntityIDs))); err != nil { +func (w *WindowClose) id() int { return 18 } +func (w *WindowClose) write(ww io.Writer) (err error) { + var tmp [1]byte + tmp[0] = byte(w.ID >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - for tmp0 := range e.EntityIDs { - if err = WriteVarInt(ww, e.EntityIDs[tmp0]); err != nil { - return - } - } return } -func (e *EntityDestroy) read(rr io.Reader) (err error) { - var tmp0 VarInt - if tmp0, err = ReadVarInt(rr); err != nil { +func (w *WindowClose) read(rr io.Reader) (err error) { + var tmp [1]byte + if _, err = rr.Read(tmp[:1]); err != nil { return } - if tmp0 > math.MaxInt16 { - return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) - } - if tmp0 < 0 { - return fmt.Errorf("negative array size: %d < 0", tmp0) - } - e.EntityIDs = make([]VarInt, tmp0) - for tmp1 := range e.EntityIDs { - if e.EntityIDs[tmp1], err = ReadVarInt(rr); err != nil { - return - } - } + w.ID = (byte(tmp[0]) << 0) return } -func (e *Entity) id() int { return 20 } -func (e *Entity) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, e.EntityID); err != nil { - return - } - return -} -func (e *Entity) read(rr io.Reader) (err error) { - if e.EntityID, err = ReadVarInt(rr); err != nil { +func (w *WindowOpen) id() int { return 19 } +func (w *WindowOpen) write(ww io.Writer) (err error) { + var tmp [4]byte + tmp[0] = byte(w.ID >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - return -} - -func (e *EntityMove) id() int { return 21 } -func (e *EntityMove) write(ww io.Writer) (err error) { - var tmp [1]byte - if err = WriteVarInt(ww, e.EntityID); err != nil { + if err = WriteString(ww, w.Type); err != nil { return } - tmp[0] = byte(e.DeltaX >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + var tmp0 []byte + if tmp0, err = json.Marshal(&w.Title); err != nil { return } - tmp[0] = byte(e.DeltaY >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + tmp1 := string(tmp0) + if err = WriteString(ww, tmp1); err != nil { return } - tmp[0] = byte(e.DeltaZ >> 0) + tmp[0] = byte(w.SlotCount >> 0) if _, err = ww.Write(tmp[:1]); err != nil { return } - if err = WriteBool(ww, e.OnGround); err != nil { - return + if w.Type == "EntityHorse" { + tmp[0] = byte(w.EntityID >> 24) + tmp[1] = byte(w.EntityID >> 16) + tmp[2] = byte(w.EntityID >> 8) + tmp[3] = byte(w.EntityID >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { + return + } } return } -func (e *EntityMove) read(rr io.Reader) (err error) { - var tmp [1]byte - if e.EntityID, err = ReadVarInt(rr); err != nil { +func (w *WindowOpen) read(rr io.Reader) (err error) { + var tmp [4]byte + if _, err = rr.Read(tmp[:1]); err != nil { return } - if _, err = rr.Read(tmp[:1]); err != nil { + w.ID = (byte(tmp[0]) << 0) + if w.Type, err = ReadString(rr); err != nil { return } - e.DeltaX = int8((uint8(tmp[0]) << 0)) - if _, err = rr.Read(tmp[:1]); err != nil { + var tmp0 string + if tmp0, err = ReadString(rr); err != nil { + return err + } + if err = json.Unmarshal([]byte(tmp0), &w.Title); err != nil { return } - e.DeltaY = int8((uint8(tmp[0]) << 0)) if _, err = rr.Read(tmp[:1]); err != nil { return } - e.DeltaZ = int8((uint8(tmp[0]) << 0)) - if e.OnGround, err = ReadBool(rr); err != nil { - return + w.SlotCount = (byte(tmp[0]) << 0) + if w.Type == "EntityHorse" { + if _, err = rr.Read(tmp[:4]); err != nil { + return + } + w.EntityID = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) } return } -func (e *EntityLook) id() int { return 22 } -func (e *EntityLook) write(ww io.Writer) (err error) { - var tmp [1]byte - if err = WriteVarInt(ww, e.EntityID); err != nil { - return - } - tmp[0] = byte(e.Yaw >> 0) +func (w *WindowItems) id() int { return 20 } +func (w *WindowItems) write(ww io.Writer) (err error) { + var tmp [2]byte + tmp[0] = byte(w.ID >> 0) if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp[0] = byte(e.Pitch >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + tmp[0] = byte(int16(len(w.Items)) >> 8) + tmp[1] = byte(int16(len(w.Items)) >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { return } - if err = WriteBool(ww, e.OnGround); err != nil { - return + for tmp0 := range w.Items { + if err = w.Items[tmp0].Serialize(ww); err != nil { + return + } } return } -func (e *EntityLook) read(rr io.Reader) (err error) { - var tmp [1]byte - if e.EntityID, err = ReadVarInt(rr); err != nil { - return - } +func (w *WindowItems) read(rr io.Reader) (err error) { + var tmp [2]byte if _, err = rr.Read(tmp[:1]); err != nil { return } - e.Yaw = int8((uint8(tmp[0]) << 0)) - if _, err = rr.Read(tmp[:1]); err != nil { + w.ID = (byte(tmp[0]) << 0) + var tmp0 int16 + if _, err = rr.Read(tmp[:2]); err != nil { return } - e.Pitch = int8((uint8(tmp[0]) << 0)) - if e.OnGround, err = ReadBool(rr); err != nil { - return + tmp0 = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + if tmp0 > math.MaxInt16 { + return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) + } + if tmp0 < 0 { + return fmt.Errorf("negative array size: %d < 0", tmp0) + } + w.Items = make([]ItemStack, tmp0) + for tmp1 := range w.Items { + if err = w.Items[tmp1].Deserialize(rr); err != nil { + return + } } return } -func (e *EntityLookAndMove) id() int { return 23 } -func (e *EntityLookAndMove) write(ww io.Writer) (err error) { - var tmp [1]byte - if err = WriteVarInt(ww, e.EntityID); err != nil { - return - } - tmp[0] = byte(e.DeltaX >> 0) +func (w *WindowProperty) id() int { return 21 } +func (w *WindowProperty) write(ww io.Writer) (err error) { + var tmp [2]byte + tmp[0] = byte(w.ID >> 0) if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp[0] = byte(e.DeltaY >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + tmp[0] = byte(w.Property >> 8) + tmp[1] = byte(w.Property >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { return } - tmp[0] = byte(e.DeltaZ >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + tmp[0] = byte(w.Value >> 8) + tmp[1] = byte(w.Value >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { return } - tmp[0] = byte(e.Yaw >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + return +} +func (w *WindowProperty) read(rr io.Reader) (err error) { + var tmp [2]byte + if _, err = rr.Read(tmp[:1]); err != nil { return } - tmp[0] = byte(e.Pitch >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + w.ID = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:2]); err != nil { return } - if err = WriteBool(ww, e.OnGround); err != nil { + w.Property = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + if _, err = rr.Read(tmp[:2]); err != nil { return } + w.Value = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) return } -func (e *EntityLookAndMove) read(rr io.Reader) (err error) { - var tmp [1]byte - if e.EntityID, err = ReadVarInt(rr); err != nil { - return - } - if _, err = rr.Read(tmp[:1]); err != nil { + +func (w *WindowSetSlot) id() int { return 22 } +func (w *WindowSetSlot) write(ww io.Writer) (err error) { + var tmp [2]byte + tmp[0] = byte(w.ID >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - e.DeltaX = int8((uint8(tmp[0]) << 0)) - if _, err = rr.Read(tmp[:1]); err != nil { + tmp[0] = byte(w.Slot >> 8) + tmp[1] = byte(w.Slot >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { return } - e.DeltaY = int8((uint8(tmp[0]) << 0)) - if _, err = rr.Read(tmp[:1]); err != nil { + if err = w.ItemStack.Serialize(ww); err != nil { return } - e.DeltaZ = int8((uint8(tmp[0]) << 0)) + return +} +func (w *WindowSetSlot) read(rr io.Reader) (err error) { + var tmp [2]byte if _, err = rr.Read(tmp[:1]); err != nil { return } - e.Yaw = int8((uint8(tmp[0]) << 0)) - if _, err = rr.Read(tmp[:1]); err != nil { + w.ID = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:2]); err != nil { return } - e.Pitch = int8((uint8(tmp[0]) << 0)) - if e.OnGround, err = ReadBool(rr); err != nil { + w.Slot = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + if err = w.ItemStack.Deserialize(rr); err != nil { return } return } -func (e *EntityTeleport) id() int { return 24 } -func (e *EntityTeleport) write(ww io.Writer) (err error) { - var tmp [4]byte - if err = WriteVarInt(ww, e.EntityID); err != nil { - return - } - tmp[0] = byte(e.X >> 24) - tmp[1] = byte(e.X >> 16) - tmp[2] = byte(e.X >> 8) - tmp[3] = byte(e.X >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { +func (s *SetCooldown) id() int { return 23 } +func (s *SetCooldown) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, s.ItemID); err != nil { return } - tmp[0] = byte(e.Y >> 24) - tmp[1] = byte(e.Y >> 16) - tmp[2] = byte(e.Y >> 8) - tmp[3] = byte(e.Y >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + if err = WriteVarInt(ww, s.Ticks); err != nil { return } - tmp[0] = byte(e.Z >> 24) - tmp[1] = byte(e.Z >> 16) - tmp[2] = byte(e.Z >> 8) - tmp[3] = byte(e.Z >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + return +} +func (s *SetCooldown) read(rr io.Reader) (err error) { + if s.ItemID, err = ReadVarInt(rr); err != nil { return } - tmp[0] = byte(e.Yaw >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + if s.Ticks, err = ReadVarInt(rr); err != nil { return } - tmp[0] = byte(e.Pitch >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + return +} + +func (p *PluginMessageClientbound) id() int { return 24 } +func (p *PluginMessageClientbound) write(ww io.Writer) (err error) { + if err = WriteString(ww, p.Channel); err != nil { return } - if err = WriteBool(ww, e.OnGround); err != nil { + if _, err = ww.Write(p.Data); err != nil { return } return } -func (e *EntityTeleport) read(rr io.Reader) (err error) { - var tmp [4]byte - if e.EntityID, err = ReadVarInt(rr); err != nil { - return - } - if _, err = rr.Read(tmp[:4]); err != nil { - return - } - e.X = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:4]); err != nil { - return - } - e.Y = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:4]); err != nil { - return - } - e.Z = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - e.Yaw = int8((uint8(tmp[0]) << 0)) - if _, err = rr.Read(tmp[:1]); err != nil { +func (p *PluginMessageClientbound) read(rr io.Reader) (err error) { + if p.Channel, err = ReadString(rr); err != nil { return } - e.Pitch = int8((uint8(tmp[0]) << 0)) - if e.OnGround, err = ReadBool(rr); err != nil { + if p.Data, err = ioutil.ReadAll(rr); err != nil { return } return } -func (e *EntityHeadLook) id() int { return 25 } -func (e *EntityHeadLook) write(ww io.Writer) (err error) { - var tmp [1]byte - if err = WriteVarInt(ww, e.EntityID); err != nil { +func (d *Disconnect) id() int { return 25 } +func (d *Disconnect) write(ww io.Writer) (err error) { + var tmp0 []byte + if tmp0, err = json.Marshal(&d.Reason); err != nil { return } - tmp[0] = byte(e.HeadYaw >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + tmp1 := string(tmp0) + if err = WriteString(ww, tmp1); err != nil { return } return } -func (e *EntityHeadLook) read(rr io.Reader) (err error) { - var tmp [1]byte - if e.EntityID, err = ReadVarInt(rr); err != nil { - return +func (d *Disconnect) read(rr io.Reader) (err error) { + var tmp0 string + if tmp0, err = ReadString(rr); err != nil { + return err } - if _, err = rr.Read(tmp[:1]); err != nil { + if err = json.Unmarshal([]byte(tmp0), &d.Reason); err != nil { return } - e.HeadYaw = int8((uint8(tmp[0]) << 0)) return } @@ -1270,282 +1264,254 @@ func (e *EntityAction) read(rr io.Reader) (err error) { return } -func (e *EntityAttach) id() int { return 27 } -func (e *EntityAttach) write(ww io.Writer) (err error) { +func (e *Explosion) id() int { return 27 } +func (e *Explosion) write(ww io.Writer) (err error) { var tmp [4]byte - tmp[0] = byte(e.EntityID >> 24) - tmp[1] = byte(e.EntityID >> 16) - tmp[2] = byte(e.EntityID >> 8) - tmp[3] = byte(e.EntityID >> 0) + tmp0 := math.Float32bits(e.X) + tmp[0] = byte(tmp0 >> 24) + tmp[1] = byte(tmp0 >> 16) + tmp[2] = byte(tmp0 >> 8) + tmp[3] = byte(tmp0 >> 0) if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp[0] = byte(e.Vehicle >> 24) - tmp[1] = byte(e.Vehicle >> 16) - tmp[2] = byte(e.Vehicle >> 8) - tmp[3] = byte(e.Vehicle >> 0) + tmp1 := math.Float32bits(e.Y) + tmp[0] = byte(tmp1 >> 24) + tmp[1] = byte(tmp1 >> 16) + tmp[2] = byte(tmp1 >> 8) + tmp[3] = byte(tmp1 >> 0) if _, err = ww.Write(tmp[:4]); err != nil { return } - if err = WriteBool(ww, e.Leash); err != nil { + tmp2 := math.Float32bits(e.Z) + tmp[0] = byte(tmp2 >> 24) + tmp[1] = byte(tmp2 >> 16) + tmp[2] = byte(tmp2 >> 8) + tmp[3] = byte(tmp2 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - return -} -func (e *EntityAttach) read(rr io.Reader) (err error) { - var tmp [4]byte - if _, err = rr.Read(tmp[:4]); err != nil { + tmp3 := math.Float32bits(e.Radius) + tmp[0] = byte(tmp3 >> 24) + tmp[1] = byte(tmp3 >> 16) + tmp[2] = byte(tmp3 >> 8) + tmp[3] = byte(tmp3 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - e.EntityID = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:4]); err != nil { + tmp[0] = byte(int32(len(e.Records)) >> 24) + tmp[1] = byte(int32(len(e.Records)) >> 16) + tmp[2] = byte(int32(len(e.Records)) >> 8) + tmp[3] = byte(int32(len(e.Records)) >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - e.Vehicle = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if e.Leash, err = ReadBool(rr); err != nil { + for tmp4 := range e.Records { + tmp[0] = byte(e.Records[tmp4].X >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp[0] = byte(e.Records[tmp4].Y >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp[0] = byte(e.Records[tmp4].Z >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + } + tmp5 := math.Float32bits(e.VelocityX) + tmp[0] = byte(tmp5 >> 24) + tmp[1] = byte(tmp5 >> 16) + tmp[2] = byte(tmp5 >> 8) + tmp[3] = byte(tmp5 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - return -} - -func (e *EntityMetadata) id() int { return 28 } -func (e *EntityMetadata) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, e.EntityID); err != nil { + tmp6 := math.Float32bits(e.VelocityY) + tmp[0] = byte(tmp6 >> 24) + tmp[1] = byte(tmp6 >> 16) + tmp[2] = byte(tmp6 >> 8) + tmp[3] = byte(tmp6 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - if err = writeMetadata(ww, e.Metadata); err != nil { + tmp7 := math.Float32bits(e.VelocityZ) + tmp[0] = byte(tmp7 >> 24) + tmp[1] = byte(tmp7 >> 16) + tmp[2] = byte(tmp7 >> 8) + tmp[3] = byte(tmp7 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } return } -func (e *EntityMetadata) read(rr io.Reader) (err error) { - if e.EntityID, err = ReadVarInt(rr); err != nil { +func (e *Explosion) read(rr io.Reader) (err error) { + var tmp [4]byte + var tmp0 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - if e.Metadata, err = readMetadata(rr); err != nil { + tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + e.X = math.Float32frombits(tmp0) + var tmp1 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - return -} - -func (e *EntityEffect) id() int { return 29 } -func (e *EntityEffect) write(ww io.Writer) (err error) { - var tmp [1]byte - if err = WriteVarInt(ww, e.EntityID); err != nil { + tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + e.Y = math.Float32frombits(tmp1) + var tmp2 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - tmp[0] = byte(e.EffectID >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + tmp2 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + e.Z = math.Float32frombits(tmp2) + var tmp3 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - tmp[0] = byte(e.Amplifier >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + tmp3 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + e.Radius = math.Float32frombits(tmp3) + var tmp4 int32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - if err = WriteVarInt(ww, e.Duration); err != nil { - return + tmp4 = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if tmp4 > math.MaxInt16 { + return fmt.Errorf("array larger than max value: %d > %d", tmp4, math.MaxInt16) } - if err = WriteBool(ww, e.HideParticles); err != nil { - return + if tmp4 < 0 { + return fmt.Errorf("negative array size: %d < 0", tmp4) } - return -} -func (e *EntityEffect) read(rr io.Reader) (err error) { - var tmp [1]byte - if e.EntityID, err = ReadVarInt(rr); err != nil { + e.Records = make([]ExplosionRecord, tmp4) + for tmp5 := range e.Records { + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + e.Records[tmp5].X = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + e.Records[tmp5].Y = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + e.Records[tmp5].Z = int8((uint8(tmp[0]) << 0)) + } + var tmp6 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - if _, err = rr.Read(tmp[:1]); err != nil { + tmp6 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + e.VelocityX = math.Float32frombits(tmp6) + var tmp7 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - e.EffectID = int8((uint8(tmp[0]) << 0)) - if _, err = rr.Read(tmp[:1]); err != nil { + tmp7 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + e.VelocityY = math.Float32frombits(tmp7) + var tmp8 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - e.Amplifier = int8((uint8(tmp[0]) << 0)) - if e.Duration, err = ReadVarInt(rr); err != nil { + tmp8 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + e.VelocityZ = math.Float32frombits(tmp8) + return +} + +func (c *ChunkUnload) id() int { return 28 } +func (c *ChunkUnload) write(ww io.Writer) (err error) { + var tmp [4]byte + tmp[0] = byte(c.X >> 24) + tmp[1] = byte(c.X >> 16) + tmp[2] = byte(c.X >> 8) + tmp[3] = byte(c.X >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - if e.HideParticles, err = ReadBool(rr); err != nil { + tmp[0] = byte(c.Z >> 24) + tmp[1] = byte(c.Z >> 16) + tmp[2] = byte(c.Z >> 8) + tmp[3] = byte(c.Z >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } return } - -func (e *EntityRemoveEffect) id() int { return 30 } -func (e *EntityRemoveEffect) write(ww io.Writer) (err error) { - var tmp [1]byte - if err = WriteVarInt(ww, e.EntityID); err != nil { +func (c *ChunkUnload) read(rr io.Reader) (err error) { + var tmp [4]byte + if _, err = rr.Read(tmp[:4]); err != nil { return } - tmp[0] = byte(e.EffectID >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + c.X = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:4]); err != nil { return } + c.Z = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) return } -func (e *EntityRemoveEffect) read(rr io.Reader) (err error) { - var tmp [1]byte - if e.EntityID, err = ReadVarInt(rr); err != nil { + +func (s *SetCompression) id() int { return 29 } +func (s *SetCompression) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, s.Threshold); err != nil { return } - if _, err = rr.Read(tmp[:1]); err != nil { + return +} +func (s *SetCompression) read(rr io.Reader) (err error) { + if s.Threshold, err = ReadVarInt(rr); err != nil { return } - e.EffectID = int8((uint8(tmp[0]) << 0)) return } -func (s *SetExperience) id() int { return 31 } -func (s *SetExperience) write(ww io.Writer) (err error) { +func (c *ChangeGameState) id() int { return 30 } +func (c *ChangeGameState) write(ww io.Writer) (err error) { var tmp [4]byte - tmp0 := math.Float32bits(s.ExperienceBar) - tmp[0] = byte(tmp0 >> 24) + tmp[0] = byte(c.Reason >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp0 := math.Float32bits(c.Value) + tmp[0] = byte(tmp0 >> 24) tmp[1] = byte(tmp0 >> 16) tmp[2] = byte(tmp0 >> 8) tmp[3] = byte(tmp0 >> 0) if _, err = ww.Write(tmp[:4]); err != nil { return } - if err = WriteVarInt(ww, s.Level); err != nil { - return - } - if err = WriteVarInt(ww, s.TotalExperience); err != nil { - return - } return } -func (s *SetExperience) read(rr io.Reader) (err error) { +func (c *ChangeGameState) read(rr io.Reader) (err error) { var tmp [4]byte + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + c.Reason = (byte(tmp[0]) << 0) var tmp0 uint32 if _, err = rr.Read(tmp[:4]); err != nil { return } tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - s.ExperienceBar = math.Float32frombits(tmp0) - if s.Level, err = ReadVarInt(rr); err != nil { - return - } - if s.TotalExperience, err = ReadVarInt(rr); err != nil { - return - } + c.Value = math.Float32frombits(tmp0) return } -func (e *EntityProperties) id() int { return 32 } -func (e *EntityProperties) write(ww io.Writer) (err error) { - var tmp [8]byte - if err = WriteVarInt(ww, e.EntityID); err != nil { - return - } - tmp[0] = byte(int32(len(e.Properties)) >> 24) - tmp[1] = byte(int32(len(e.Properties)) >> 16) - tmp[2] = byte(int32(len(e.Properties)) >> 8) - tmp[3] = byte(int32(len(e.Properties)) >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { +func (k *KeepAliveClientbound) id() int { return 31 } +func (k *KeepAliveClientbound) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, k.ID); err != nil { return } - for tmp0 := range e.Properties { - if err = WriteString(ww, e.Properties[tmp0].Key); err != nil { - return - } - tmp1 := math.Float64bits(e.Properties[tmp0].Value) - tmp[0] = byte(tmp1 >> 56) - tmp[1] = byte(tmp1 >> 48) - tmp[2] = byte(tmp1 >> 40) - tmp[3] = byte(tmp1 >> 32) - tmp[4] = byte(tmp1 >> 24) - tmp[5] = byte(tmp1 >> 16) - tmp[6] = byte(tmp1 >> 8) - tmp[7] = byte(tmp1 >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { - return - } - if err = WriteVarInt(ww, VarInt(len(e.Properties[tmp0].Modifiers))); err != nil { - return - } - for tmp2 := range e.Properties[tmp0].Modifiers { - if err = e.Properties[tmp0].Modifiers[tmp2].UUID.Serialize(ww); err != nil { - return - } - tmp3 := math.Float64bits(e.Properties[tmp0].Modifiers[tmp2].Amount) - tmp[0] = byte(tmp3 >> 56) - tmp[1] = byte(tmp3 >> 48) - tmp[2] = byte(tmp3 >> 40) - tmp[3] = byte(tmp3 >> 32) - tmp[4] = byte(tmp3 >> 24) - tmp[5] = byte(tmp3 >> 16) - tmp[6] = byte(tmp3 >> 8) - tmp[7] = byte(tmp3 >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { - return - } - tmp[0] = byte(e.Properties[tmp0].Modifiers[tmp2].Operation >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - } - } return } -func (e *EntityProperties) read(rr io.Reader) (err error) { - var tmp [8]byte - if e.EntityID, err = ReadVarInt(rr); err != nil { - return - } - var tmp0 int32 - if _, err = rr.Read(tmp[:4]); err != nil { +func (k *KeepAliveClientbound) read(rr io.Reader) (err error) { + if k.ID, err = ReadVarInt(rr); err != nil { return } - tmp0 = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if tmp0 > math.MaxInt16 { - return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) - } - if tmp0 < 0 { - return fmt.Errorf("negative array size: %d < 0", tmp0) - } - e.Properties = make([]EntityProperty, tmp0) - for tmp1 := range e.Properties { - if e.Properties[tmp1].Key, err = ReadString(rr); err != nil { - return - } - var tmp2 uint64 - if _, err = rr.Read(tmp[:8]); err != nil { - return - } - tmp2 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) - e.Properties[tmp1].Value = math.Float64frombits(tmp2) - var tmp3 VarInt - if tmp3, err = ReadVarInt(rr); err != nil { - return - } - if tmp3 > math.MaxInt16 { - return fmt.Errorf("array larger than max value: %d > %d", tmp3, math.MaxInt16) - } - if tmp3 < 0 { - return fmt.Errorf("negative array size: %d < 0", tmp3) - } - e.Properties[tmp1].Modifiers = make([]PropertyModifier, tmp3) - for tmp4 := range e.Properties[tmp1].Modifiers { - if err = e.Properties[tmp1].Modifiers[tmp4].UUID.Deserialize(rr); err != nil { - return - } - var tmp5 uint64 - if _, err = rr.Read(tmp[:8]); err != nil { - return - } - tmp5 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) - e.Properties[tmp1].Modifiers[tmp4].Amount = math.Float64frombits(tmp5) - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - e.Properties[tmp1].Modifiers[tmp4].Operation = int8((uint8(tmp[0]) << 0)) - } - } return } -func (c *ChunkData) id() int { return 33 } +func (c *ChunkData) id() int { return 32 } func (c *ChunkData) write(ww io.Writer) (err error) { var tmp [4]byte tmp[0] = byte(c.ChunkX >> 24) @@ -1611,668 +1577,670 @@ func (c *ChunkData) read(rr io.Reader) (err error) { return } -func (c *ChunkUnload) id() int { return 34 } -func (c *ChunkUnload) write(ww io.Writer) (err error) { - var tmp [4]byte - tmp[0] = byte(c.X >> 24) - tmp[1] = byte(c.X >> 16) - tmp[2] = byte(c.X >> 8) - tmp[3] = byte(c.X >> 0) +func (e *Effect) id() int { return 33 } +func (e *Effect) write(ww io.Writer) (err error) { + var tmp [8]byte + tmp[0] = byte(e.EffectID >> 24) + tmp[1] = byte(e.EffectID >> 16) + tmp[2] = byte(e.EffectID >> 8) + tmp[3] = byte(e.EffectID >> 0) if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp[0] = byte(c.Z >> 24) - tmp[1] = byte(c.Z >> 16) - tmp[2] = byte(c.Z >> 8) - tmp[3] = byte(c.Z >> 0) + tmp[0] = byte(e.Location >> 56) + tmp[1] = byte(e.Location >> 48) + tmp[2] = byte(e.Location >> 40) + tmp[3] = byte(e.Location >> 32) + tmp[4] = byte(e.Location >> 24) + tmp[5] = byte(e.Location >> 16) + tmp[6] = byte(e.Location >> 8) + tmp[7] = byte(e.Location >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { + return + } + tmp[0] = byte(e.Data >> 24) + tmp[1] = byte(e.Data >> 16) + tmp[2] = byte(e.Data >> 8) + tmp[3] = byte(e.Data >> 0) if _, err = ww.Write(tmp[:4]); err != nil { return } + if err = WriteBool(ww, e.DisableRelative); err != nil { + return + } return } -func (c *ChunkUnload) read(rr io.Reader) (err error) { - var tmp [4]byte +func (e *Effect) read(rr io.Reader) (err error) { + var tmp [8]byte if _, err = rr.Read(tmp[:4]); err != nil { return } - c.X = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + e.EffectID = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:8]); err != nil { + return + } + e.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) if _, err = rr.Read(tmp[:4]); err != nil { return } - c.Z = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + e.Data = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if e.DisableRelative, err = ReadBool(rr); err != nil { + return + } return } -func (m *MultiBlockChange) id() int { return 35 } -func (m *MultiBlockChange) write(ww io.Writer) (err error) { +func (p *Particle) id() int { return 34 } +func (p *Particle) write(ww io.Writer) (err error) { var tmp [4]byte - tmp[0] = byte(m.ChunkX >> 24) - tmp[1] = byte(m.ChunkX >> 16) - tmp[2] = byte(m.ChunkX >> 8) - tmp[3] = byte(m.ChunkX >> 0) + tmp[0] = byte(p.ParticleID >> 24) + tmp[1] = byte(p.ParticleID >> 16) + tmp[2] = byte(p.ParticleID >> 8) + tmp[3] = byte(p.ParticleID >> 0) if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp[0] = byte(m.ChunkZ >> 24) - tmp[1] = byte(m.ChunkZ >> 16) - tmp[2] = byte(m.ChunkZ >> 8) - tmp[3] = byte(m.ChunkZ >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + if err = WriteBool(ww, p.LongDistance); err != nil { return } - if err = WriteVarInt(ww, VarInt(len(m.Records))); err != nil { + tmp0 := math.Float32bits(p.X) + tmp[0] = byte(tmp0 >> 24) + tmp[1] = byte(tmp0 >> 16) + tmp[2] = byte(tmp0 >> 8) + tmp[3] = byte(tmp0 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - for tmp0 := range m.Records { - tmp[0] = byte(m.Records[tmp0].XZ >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp[0] = byte(m.Records[tmp0].Y >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - if err = WriteVarInt(ww, m.Records[tmp0].BlockID); err != nil { - return - } - } - return -} -func (m *MultiBlockChange) read(rr io.Reader) (err error) { - var tmp [4]byte - if _, err = rr.Read(tmp[:4]); err != nil { + tmp1 := math.Float32bits(p.Y) + tmp[0] = byte(tmp1 >> 24) + tmp[1] = byte(tmp1 >> 16) + tmp[2] = byte(tmp1 >> 8) + tmp[3] = byte(tmp1 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - m.ChunkX = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:4]); err != nil { + tmp2 := math.Float32bits(p.Z) + tmp[0] = byte(tmp2 >> 24) + tmp[1] = byte(tmp2 >> 16) + tmp[2] = byte(tmp2 >> 8) + tmp[3] = byte(tmp2 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - m.ChunkZ = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - var tmp0 VarInt - if tmp0, err = ReadVarInt(rr); err != nil { + tmp3 := math.Float32bits(p.OffsetX) + tmp[0] = byte(tmp3 >> 24) + tmp[1] = byte(tmp3 >> 16) + tmp[2] = byte(tmp3 >> 8) + tmp[3] = byte(tmp3 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - if tmp0 > math.MaxInt16 { - return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) + tmp4 := math.Float32bits(p.OffsetY) + tmp[0] = byte(tmp4 >> 24) + tmp[1] = byte(tmp4 >> 16) + tmp[2] = byte(tmp4 >> 8) + tmp[3] = byte(tmp4 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { + return } - if tmp0 < 0 { - return fmt.Errorf("negative array size: %d < 0", tmp0) + tmp5 := math.Float32bits(p.OffsetZ) + tmp[0] = byte(tmp5 >> 24) + tmp[1] = byte(tmp5 >> 16) + tmp[2] = byte(tmp5 >> 8) + tmp[3] = byte(tmp5 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { + return } - m.Records = make([]BlockChangeRecord, tmp0) - for tmp1 := range m.Records { - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - m.Records[tmp1].XZ = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - m.Records[tmp1].Y = (byte(tmp[0]) << 0) - if m.Records[tmp1].BlockID, err = ReadVarInt(rr); err != nil { + tmp6 := math.Float32bits(p.Speed) + tmp[0] = byte(tmp6 >> 24) + tmp[1] = byte(tmp6 >> 16) + tmp[2] = byte(tmp6 >> 8) + tmp[3] = byte(tmp6 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { + return + } + tmp[0] = byte(p.Count >> 24) + tmp[1] = byte(p.Count >> 16) + tmp[2] = byte(p.Count >> 8) + tmp[3] = byte(p.Count >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { + return + } + for tmp7 := range p.Data { + if err = WriteVarInt(ww, p.Data[tmp7]); err != nil { return } } return } - -func (b *BlockChange) id() int { return 36 } -func (b *BlockChange) write(ww io.Writer) (err error) { - var tmp [8]byte - tmp[0] = byte(b.Location >> 56) - tmp[1] = byte(b.Location >> 48) - tmp[2] = byte(b.Location >> 40) - tmp[3] = byte(b.Location >> 32) - tmp[4] = byte(b.Location >> 24) - tmp[5] = byte(b.Location >> 16) - tmp[6] = byte(b.Location >> 8) - tmp[7] = byte(b.Location >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { +func (p *Particle) read(rr io.Reader) (err error) { + var tmp [4]byte + if _, err = rr.Read(tmp[:4]); err != nil { return } - if err = WriteVarInt(ww, b.BlockID); err != nil { + p.ParticleID = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if p.LongDistance, err = ReadBool(rr); err != nil { return } - return -} -func (b *BlockChange) read(rr io.Reader) (err error) { - var tmp [8]byte - if _, err = rr.Read(tmp[:8]); err != nil { + var tmp0 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - b.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) - if b.BlockID, err = ReadVarInt(rr); err != nil { + tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + p.X = math.Float32frombits(tmp0) + var tmp1 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - return -} - -func (b *BlockAction) id() int { return 37 } -func (b *BlockAction) write(ww io.Writer) (err error) { - var tmp [8]byte - tmp[0] = byte(b.Location >> 56) - tmp[1] = byte(b.Location >> 48) - tmp[2] = byte(b.Location >> 40) - tmp[3] = byte(b.Location >> 32) - tmp[4] = byte(b.Location >> 24) - tmp[5] = byte(b.Location >> 16) - tmp[6] = byte(b.Location >> 8) - tmp[7] = byte(b.Location >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + p.Y = math.Float32frombits(tmp1) + var tmp2 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - tmp[0] = byte(b.Byte1 >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + tmp2 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + p.Z = math.Float32frombits(tmp2) + var tmp3 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - tmp[0] = byte(b.Byte2 >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + tmp3 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + p.OffsetX = math.Float32frombits(tmp3) + var tmp4 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - if err = WriteVarInt(ww, b.BlockType); err != nil { + tmp4 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + p.OffsetY = math.Float32frombits(tmp4) + var tmp5 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - return -} -func (b *BlockAction) read(rr io.Reader) (err error) { - var tmp [8]byte - if _, err = rr.Read(tmp[:8]); err != nil { + tmp5 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + p.OffsetZ = math.Float32frombits(tmp5) + var tmp6 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - b.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) - if _, err = rr.Read(tmp[:1]); err != nil { + tmp6 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + p.Speed = math.Float32frombits(tmp6) + if _, err = rr.Read(tmp[:4]); err != nil { return } - b.Byte1 = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:1]); err != nil { - return + p.Count = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + tmp7 := particleDataLength(p) + if tmp7 > math.MaxInt16 { + return fmt.Errorf("array larger than max value: %d > %d", tmp7, math.MaxInt16) } - b.Byte2 = (byte(tmp[0]) << 0) - if b.BlockType, err = ReadVarInt(rr); err != nil { - return + if tmp7 < 0 { + return fmt.Errorf("negative array size: %d < 0", tmp7) + } + p.Data = make([]VarInt, tmp7) + for tmp8 := range p.Data { + if p.Data[tmp8], err = ReadVarInt(rr); err != nil { + return + } } return } -func (b *BlockBreakAnimation) id() int { return 38 } -func (b *BlockBreakAnimation) write(ww io.Writer) (err error) { - var tmp [8]byte - if err = WriteVarInt(ww, b.EntityID); err != nil { +func (s *SoundEffect) id() int { return 35 } +func (s *SoundEffect) write(ww io.Writer) (err error) { + var tmp [4]byte + if err = WriteString(ww, s.Name); err != nil { return } - tmp[0] = byte(b.Location >> 56) - tmp[1] = byte(b.Location >> 48) - tmp[2] = byte(b.Location >> 40) - tmp[3] = byte(b.Location >> 32) - tmp[4] = byte(b.Location >> 24) - tmp[5] = byte(b.Location >> 16) - tmp[6] = byte(b.Location >> 8) - tmp[7] = byte(b.Location >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + tmp[0] = byte(s.X >> 24) + tmp[1] = byte(s.X >> 16) + tmp[2] = byte(s.X >> 8) + tmp[3] = byte(s.X >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp[0] = byte(b.Stage >> 0) + tmp[0] = byte(s.Y >> 24) + tmp[1] = byte(s.Y >> 16) + tmp[2] = byte(s.Y >> 8) + tmp[3] = byte(s.Y >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { + return + } + tmp[0] = byte(s.Z >> 24) + tmp[1] = byte(s.Z >> 16) + tmp[2] = byte(s.Z >> 8) + tmp[3] = byte(s.Z >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { + return + } + tmp0 := math.Float32bits(s.Volume) + tmp[0] = byte(tmp0 >> 24) + tmp[1] = byte(tmp0 >> 16) + tmp[2] = byte(tmp0 >> 8) + tmp[3] = byte(tmp0 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { + return + } + tmp[0] = byte(s.Pitch >> 0) if _, err = ww.Write(tmp[:1]); err != nil { return } return } -func (b *BlockBreakAnimation) read(rr io.Reader) (err error) { - var tmp [8]byte - if b.EntityID, err = ReadVarInt(rr); err != nil { +func (s *SoundEffect) read(rr io.Reader) (err error) { + var tmp [4]byte + if s.Name, err = ReadString(rr); err != nil { return } - if _, err = rr.Read(tmp[:8]); err != nil { + if _, err = rr.Read(tmp[:4]); err != nil { return } - b.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) + s.X = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:4]); err != nil { + return + } + s.Y = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:4]); err != nil { + return + } + s.Z = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + var tmp0 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { + return + } + tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + s.Volume = math.Float32frombits(tmp0) if _, err = rr.Read(tmp[:1]); err != nil { return } - b.Stage = int8((uint8(tmp[0]) << 0)) + s.Pitch = (byte(tmp[0]) << 0) return } -func (e *Explosion) id() int { return 39 } -func (e *Explosion) write(ww io.Writer) (err error) { +func (j *JoinGame) id() int { return 36 } +func (j *JoinGame) write(ww io.Writer) (err error) { var tmp [4]byte - tmp0 := math.Float32bits(e.X) - tmp[0] = byte(tmp0 >> 24) - tmp[1] = byte(tmp0 >> 16) - tmp[2] = byte(tmp0 >> 8) - tmp[3] = byte(tmp0 >> 0) + tmp[0] = byte(j.EntityID >> 24) + tmp[1] = byte(j.EntityID >> 16) + tmp[2] = byte(j.EntityID >> 8) + tmp[3] = byte(j.EntityID >> 0) if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp1 := math.Float32bits(e.Y) - tmp[0] = byte(tmp1 >> 24) - tmp[1] = byte(tmp1 >> 16) - tmp[2] = byte(tmp1 >> 8) - tmp[3] = byte(tmp1 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + tmp[0] = byte(j.Gamemode >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp2 := math.Float32bits(e.Z) - tmp[0] = byte(tmp2 >> 24) - tmp[1] = byte(tmp2 >> 16) - tmp[2] = byte(tmp2 >> 8) - tmp[3] = byte(tmp2 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + tmp[0] = byte(j.Dimension >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp3 := math.Float32bits(e.Radius) - tmp[0] = byte(tmp3 >> 24) - tmp[1] = byte(tmp3 >> 16) - tmp[2] = byte(tmp3 >> 8) - tmp[3] = byte(tmp3 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + tmp[0] = byte(j.Difficulty >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp[0] = byte(int32(len(e.Records)) >> 24) - tmp[1] = byte(int32(len(e.Records)) >> 16) - tmp[2] = byte(int32(len(e.Records)) >> 8) - tmp[3] = byte(int32(len(e.Records)) >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + tmp[0] = byte(j.MaxPlayers >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - for tmp4 := range e.Records { - tmp[0] = byte(e.Records[tmp4].X >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp[0] = byte(e.Records[tmp4].Y >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp[0] = byte(e.Records[tmp4].Z >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } + if err = WriteString(ww, j.LevelType); err != nil { + return } - tmp5 := math.Float32bits(e.VelocityX) - tmp[0] = byte(tmp5 >> 24) - tmp[1] = byte(tmp5 >> 16) - tmp[2] = byte(tmp5 >> 8) - tmp[3] = byte(tmp5 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + if err = WriteBool(ww, j.ReducedDebugInfo); err != nil { return } - tmp6 := math.Float32bits(e.VelocityY) - tmp[0] = byte(tmp6 >> 24) - tmp[1] = byte(tmp6 >> 16) - tmp[2] = byte(tmp6 >> 8) - tmp[3] = byte(tmp6 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + return +} +func (j *JoinGame) read(rr io.Reader) (err error) { + var tmp [4]byte + if _, err = rr.Read(tmp[:4]); err != nil { return } - tmp7 := math.Float32bits(e.VelocityZ) - tmp[0] = byte(tmp7 >> 24) - tmp[1] = byte(tmp7 >> 16) - tmp[2] = byte(tmp7 >> 8) - tmp[3] = byte(tmp7 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + j.EntityID = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + j.Gamemode = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + j.Dimension = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + j.Difficulty = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + j.MaxPlayers = (byte(tmp[0]) << 0) + if j.LevelType, err = ReadString(rr); err != nil { + return + } + if j.ReducedDebugInfo, err = ReadBool(rr); err != nil { return } return } -func (e *Explosion) read(rr io.Reader) (err error) { - var tmp [4]byte - var tmp0 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + +func (m *Maps) id() int { return 37 } +func (m *Maps) write(ww io.Writer) (err error) { + var tmp [1]byte + if err = WriteVarInt(ww, m.ItemDamage); err != nil { return } - tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - e.X = math.Float32frombits(tmp0) - var tmp1 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + tmp[0] = byte(m.Scale >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - e.Y = math.Float32frombits(tmp1) - var tmp2 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + if err = WriteBool(ww, m.TrackingPosition); err != nil { return } - tmp2 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - e.Z = math.Float32frombits(tmp2) - var tmp3 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + if err = WriteVarInt(ww, VarInt(len(m.Icons))); err != nil { return } - tmp3 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - e.Radius = math.Float32frombits(tmp3) - var tmp4 int32 - if _, err = rr.Read(tmp[:4]); err != nil { + for tmp0 := range m.Icons { + tmp[0] = byte(m.Icons[tmp0].DirectionType >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp[0] = byte(m.Icons[tmp0].X >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp[0] = byte(m.Icons[tmp0].Z >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + } + tmp[0] = byte(m.Columns >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp4 = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if tmp4 > math.MaxInt16 { - return fmt.Errorf("array larger than max value: %d > %d", tmp4, math.MaxInt16) + if m.Columns > 0 { + tmp[0] = byte(m.Rows >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp[0] = byte(m.X >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp[0] = byte(m.Z >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + if err = WriteVarInt(ww, VarInt(len(m.Data))); err != nil { + return + } + if _, err = ww.Write(m.Data); err != nil { + return + } } - if tmp4 < 0 { - return fmt.Errorf("negative array size: %d < 0", tmp4) + return +} +func (m *Maps) read(rr io.Reader) (err error) { + var tmp [1]byte + if m.ItemDamage, err = ReadVarInt(rr); err != nil { + return } - e.Records = make([]ExplosionRecord, tmp4) - for tmp5 := range e.Records { + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + m.Scale = int8((uint8(tmp[0]) << 0)) + if m.TrackingPosition, err = ReadBool(rr); err != nil { + return + } + var tmp0 VarInt + if tmp0, err = ReadVarInt(rr); err != nil { + return + } + if tmp0 > math.MaxInt16 { + return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) + } + if tmp0 < 0 { + return fmt.Errorf("negative array size: %d < 0", tmp0) + } + m.Icons = make([]MapIcon, tmp0) + for tmp1 := range m.Icons { if _, err = rr.Read(tmp[:1]); err != nil { return } - e.Records[tmp5].X = int8((uint8(tmp[0]) << 0)) + m.Icons[tmp1].DirectionType = int8((uint8(tmp[0]) << 0)) if _, err = rr.Read(tmp[:1]); err != nil { return } - e.Records[tmp5].Y = int8((uint8(tmp[0]) << 0)) + m.Icons[tmp1].X = int8((uint8(tmp[0]) << 0)) if _, err = rr.Read(tmp[:1]); err != nil { return } - e.Records[tmp5].Z = int8((uint8(tmp[0]) << 0)) - } - var tmp6 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { - return + m.Icons[tmp1].Z = int8((uint8(tmp[0]) << 0)) } - tmp6 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - e.VelocityX = math.Float32frombits(tmp6) - var tmp7 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + if _, err = rr.Read(tmp[:1]); err != nil { return } - tmp7 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - e.VelocityY = math.Float32frombits(tmp7) - var tmp8 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { - return + m.Columns = (byte(tmp[0]) << 0) + if m.Columns > 0 { + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + m.Rows = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + m.X = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + m.Z = (byte(tmp[0]) << 0) + var tmp2 VarInt + if tmp2, err = ReadVarInt(rr); err != nil { + return + } + if tmp2 > math.MaxInt16 { + return fmt.Errorf("array larger than max value: %d > %d", tmp2, math.MaxInt16) + } + if tmp2 < 0 { + return fmt.Errorf("negative array size: %d < 0", tmp2) + } + m.Data = make([]byte, tmp2) + if _, err = rr.Read(m.Data); err != nil { + return + } } - tmp8 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - e.VelocityZ = math.Float32frombits(tmp8) return } -func (e *Effect) id() int { return 40 } -func (e *Effect) write(ww io.Writer) (err error) { - var tmp [8]byte - tmp[0] = byte(e.EffectID >> 24) - tmp[1] = byte(e.EffectID >> 16) - tmp[2] = byte(e.EffectID >> 8) - tmp[3] = byte(e.EffectID >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { +func (e *EntityMove) id() int { return 38 } +func (e *EntityMove) write(ww io.Writer) (err error) { + var tmp [1]byte + if err = WriteVarInt(ww, e.EntityID); err != nil { return } - tmp[0] = byte(e.Location >> 56) - tmp[1] = byte(e.Location >> 48) - tmp[2] = byte(e.Location >> 40) - tmp[3] = byte(e.Location >> 32) - tmp[4] = byte(e.Location >> 24) - tmp[5] = byte(e.Location >> 16) - tmp[6] = byte(e.Location >> 8) - tmp[7] = byte(e.Location >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + tmp[0] = byte(e.DeltaX >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp[0] = byte(e.Data >> 24) - tmp[1] = byte(e.Data >> 16) - tmp[2] = byte(e.Data >> 8) - tmp[3] = byte(e.Data >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + tmp[0] = byte(e.DeltaY >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - if err = WriteBool(ww, e.DisableRelative); err != nil { + tmp[0] = byte(e.DeltaZ >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + if err = WriteBool(ww, e.OnGround); err != nil { return } return } -func (e *Effect) read(rr io.Reader) (err error) { - var tmp [8]byte - if _, err = rr.Read(tmp[:4]); err != nil { +func (e *EntityMove) read(rr io.Reader) (err error) { + var tmp [1]byte + if e.EntityID, err = ReadVarInt(rr); err != nil { return } - e.EffectID = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:8]); err != nil { + if _, err = rr.Read(tmp[:1]); err != nil { return } - e.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) - if _, err = rr.Read(tmp[:4]); err != nil { + e.DeltaX = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:1]); err != nil { return } - e.Data = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if e.DisableRelative, err = ReadBool(rr); err != nil { + e.DeltaY = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + e.DeltaZ = int8((uint8(tmp[0]) << 0)) + if e.OnGround, err = ReadBool(rr); err != nil { return } return } -func (s *SoundEffect) id() int { return 41 } -func (s *SoundEffect) write(ww io.Writer) (err error) { - var tmp [4]byte - if err = WriteString(ww, s.Name); err != nil { +func (e *EntityLookAndMove) id() int { return 39 } +func (e *EntityLookAndMove) write(ww io.Writer) (err error) { + var tmp [1]byte + if err = WriteVarInt(ww, e.EntityID); err != nil { return } - tmp[0] = byte(s.X >> 24) - tmp[1] = byte(s.X >> 16) - tmp[2] = byte(s.X >> 8) - tmp[3] = byte(s.X >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + tmp[0] = byte(e.DeltaX >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp[0] = byte(s.Y >> 24) - tmp[1] = byte(s.Y >> 16) - tmp[2] = byte(s.Y >> 8) - tmp[3] = byte(s.Y >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + tmp[0] = byte(e.DeltaY >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp[0] = byte(s.Z >> 24) - tmp[1] = byte(s.Z >> 16) - tmp[2] = byte(s.Z >> 8) - tmp[3] = byte(s.Z >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + tmp[0] = byte(e.DeltaZ >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp0 := math.Float32bits(s.Volume) - tmp[0] = byte(tmp0 >> 24) - tmp[1] = byte(tmp0 >> 16) - tmp[2] = byte(tmp0 >> 8) - tmp[3] = byte(tmp0 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + tmp[0] = byte(e.Yaw >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp[0] = byte(s.Pitch >> 0) + tmp[0] = byte(e.Pitch >> 0) if _, err = ww.Write(tmp[:1]); err != nil { return } + if err = WriteBool(ww, e.OnGround); err != nil { + return + } return } -func (s *SoundEffect) read(rr io.Reader) (err error) { - var tmp [4]byte - if s.Name, err = ReadString(rr); err != nil { +func (e *EntityLookAndMove) read(rr io.Reader) (err error) { + var tmp [1]byte + if e.EntityID, err = ReadVarInt(rr); err != nil { return } - if _, err = rr.Read(tmp[:4]); err != nil { + if _, err = rr.Read(tmp[:1]); err != nil { return } - s.X = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:4]); err != nil { + e.DeltaX = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:1]); err != nil { return } - s.Y = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:4]); err != nil { + e.DeltaY = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:1]); err != nil { return } - s.Z = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - var tmp0 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + e.DeltaZ = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:1]); err != nil { return } - tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - s.Volume = math.Float32frombits(tmp0) + e.Yaw = int8((uint8(tmp[0]) << 0)) if _, err = rr.Read(tmp[:1]); err != nil { return } - s.Pitch = (byte(tmp[0]) << 0) + e.Pitch = int8((uint8(tmp[0]) << 0)) + if e.OnGround, err = ReadBool(rr); err != nil { + return + } return } -func (p *Particle) id() int { return 42 } -func (p *Particle) write(ww io.Writer) (err error) { - var tmp [4]byte - tmp[0] = byte(p.ParticleID >> 24) - tmp[1] = byte(p.ParticleID >> 16) - tmp[2] = byte(p.ParticleID >> 8) - tmp[3] = byte(p.ParticleID >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - if err = WriteBool(ww, p.LongDistance); err != nil { - return - } - tmp0 := math.Float32bits(p.X) - tmp[0] = byte(tmp0 >> 24) - tmp[1] = byte(tmp0 >> 16) - tmp[2] = byte(tmp0 >> 8) - tmp[3] = byte(tmp0 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - tmp1 := math.Float32bits(p.Y) - tmp[0] = byte(tmp1 >> 24) - tmp[1] = byte(tmp1 >> 16) - tmp[2] = byte(tmp1 >> 8) - tmp[3] = byte(tmp1 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - tmp2 := math.Float32bits(p.Z) - tmp[0] = byte(tmp2 >> 24) - tmp[1] = byte(tmp2 >> 16) - tmp[2] = byte(tmp2 >> 8) - tmp[3] = byte(tmp2 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - tmp3 := math.Float32bits(p.OffsetX) - tmp[0] = byte(tmp3 >> 24) - tmp[1] = byte(tmp3 >> 16) - tmp[2] = byte(tmp3 >> 8) - tmp[3] = byte(tmp3 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - tmp4 := math.Float32bits(p.OffsetY) - tmp[0] = byte(tmp4 >> 24) - tmp[1] = byte(tmp4 >> 16) - tmp[2] = byte(tmp4 >> 8) - tmp[3] = byte(tmp4 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { +func (e *EntityLook) id() int { return 40 } +func (e *EntityLook) write(ww io.Writer) (err error) { + var tmp [1]byte + if err = WriteVarInt(ww, e.EntityID); err != nil { return } - tmp5 := math.Float32bits(p.OffsetZ) - tmp[0] = byte(tmp5 >> 24) - tmp[1] = byte(tmp5 >> 16) - tmp[2] = byte(tmp5 >> 8) - tmp[3] = byte(tmp5 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + tmp[0] = byte(e.Yaw >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp6 := math.Float32bits(p.Speed) - tmp[0] = byte(tmp6 >> 24) - tmp[1] = byte(tmp6 >> 16) - tmp[2] = byte(tmp6 >> 8) - tmp[3] = byte(tmp6 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + tmp[0] = byte(e.Pitch >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp[0] = byte(p.Count >> 24) - tmp[1] = byte(p.Count >> 16) - tmp[2] = byte(p.Count >> 8) - tmp[3] = byte(p.Count >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { + if err = WriteBool(ww, e.OnGround); err != nil { return } - for tmp7 := range p.Data { - if err = WriteVarInt(ww, p.Data[tmp7]); err != nil { - return - } - } return } -func (p *Particle) read(rr io.Reader) (err error) { - var tmp [4]byte - if _, err = rr.Read(tmp[:4]); err != nil { - return - } - p.ParticleID = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if p.LongDistance, err = ReadBool(rr); err != nil { - return - } - var tmp0 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { +func (e *EntityLook) read(rr io.Reader) (err error) { + var tmp [1]byte + if e.EntityID, err = ReadVarInt(rr); err != nil { return } - tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - p.X = math.Float32frombits(tmp0) - var tmp1 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + if _, err = rr.Read(tmp[:1]); err != nil { return } - tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - p.Y = math.Float32frombits(tmp1) - var tmp2 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + e.Yaw = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:1]); err != nil { return } - tmp2 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - p.Z = math.Float32frombits(tmp2) - var tmp3 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + e.Pitch = int8((uint8(tmp[0]) << 0)) + if e.OnGround, err = ReadBool(rr); err != nil { return } - tmp3 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - p.OffsetX = math.Float32frombits(tmp3) - var tmp4 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + return +} + +func (e *Entity) id() int { return 41 } +func (e *Entity) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, e.EntityID); err != nil { return } - tmp4 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - p.OffsetY = math.Float32frombits(tmp4) - var tmp5 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + return +} +func (e *Entity) read(rr io.Reader) (err error) { + if e.EntityID, err = ReadVarInt(rr); err != nil { return } - tmp5 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - p.OffsetZ = math.Float32frombits(tmp5) - var tmp6 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + return +} + +func (s *SignEditorOpen) id() int { return 42 } +func (s *SignEditorOpen) write(ww io.Writer) (err error) { + var tmp [8]byte + tmp[0] = byte(s.Location >> 56) + tmp[1] = byte(s.Location >> 48) + tmp[2] = byte(s.Location >> 40) + tmp[3] = byte(s.Location >> 32) + tmp[4] = byte(s.Location >> 24) + tmp[5] = byte(s.Location >> 16) + tmp[6] = byte(s.Location >> 8) + tmp[7] = byte(s.Location >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } - tmp6 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - p.Speed = math.Float32frombits(tmp6) - if _, err = rr.Read(tmp[:4]); err != nil { + return +} +func (s *SignEditorOpen) read(rr io.Reader) (err error) { + var tmp [8]byte + if _, err = rr.Read(tmp[:8]); err != nil { return } - p.Count = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - tmp7 := particleDataLength(p) - if tmp7 > math.MaxInt16 { - return fmt.Errorf("array larger than max value: %d > %d", tmp7, math.MaxInt16) - } - if tmp7 < 0 { - return fmt.Errorf("negative array size: %d < 0", tmp7) - } - p.Data = make([]VarInt, tmp7) - for tmp8 := range p.Data { - if p.Data[tmp8], err = ReadVarInt(rr); err != nil { - return - } - } + s.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) return } -func (c *ChangeGameState) id() int { return 43 } -func (c *ChangeGameState) write(ww io.Writer) (err error) { +func (p *PlayerAbilities) id() int { return 43 } +func (p *PlayerAbilities) write(ww io.Writer) (err error) { var tmp [4]byte - tmp[0] = byte(c.Reason >> 0) + tmp[0] = byte(p.Flags >> 0) if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp0 := math.Float32bits(c.Value) + tmp0 := math.Float32bits(p.FlyingSpeed) tmp[0] = byte(tmp0 >> 24) tmp[1] = byte(tmp0 >> 16) tmp[2] = byte(tmp0 >> 8) @@ -2280,924 +2248,697 @@ func (c *ChangeGameState) write(ww io.Writer) (err error) { if _, err = ww.Write(tmp[:4]); err != nil { return } + tmp1 := math.Float32bits(p.WalkingSpeed) + tmp[0] = byte(tmp1 >> 24) + tmp[1] = byte(tmp1 >> 16) + tmp[2] = byte(tmp1 >> 8) + tmp[3] = byte(tmp1 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { + return + } return } -func (c *ChangeGameState) read(rr io.Reader) (err error) { +func (p *PlayerAbilities) read(rr io.Reader) (err error) { var tmp [4]byte if _, err = rr.Read(tmp[:1]); err != nil { return } - c.Reason = (byte(tmp[0]) << 0) + p.Flags = (byte(tmp[0]) << 0) var tmp0 uint32 if _, err = rr.Read(tmp[:4]); err != nil { return } tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - c.Value = math.Float32frombits(tmp0) - return -} - -func (s *SpawnGlobalEntity) id() int { return 44 } -func (s *SpawnGlobalEntity) write(ww io.Writer) (err error) { - var tmp [4]byte - if err = WriteVarInt(ww, s.EntityID); err != nil { - return - } - tmp[0] = byte(s.Type >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp[0] = byte(s.X >> 24) - tmp[1] = byte(s.X >> 16) - tmp[2] = byte(s.X >> 8) - tmp[3] = byte(s.X >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - tmp[0] = byte(s.Y >> 24) - tmp[1] = byte(s.Y >> 16) - tmp[2] = byte(s.Y >> 8) - tmp[3] = byte(s.Y >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - tmp[0] = byte(s.Z >> 24) - tmp[1] = byte(s.Z >> 16) - tmp[2] = byte(s.Z >> 8) - tmp[3] = byte(s.Z >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - return -} -func (s *SpawnGlobalEntity) read(rr io.Reader) (err error) { - var tmp [4]byte - if s.EntityID, err = ReadVarInt(rr); err != nil { - return - } - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - s.Type = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:4]); err != nil { - return - } - s.X = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - if _, err = rr.Read(tmp[:4]); err != nil { - return - } - s.Y = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + p.FlyingSpeed = math.Float32frombits(tmp0) + var tmp1 uint32 if _, err = rr.Read(tmp[:4]); err != nil { return } - s.Z = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + p.WalkingSpeed = math.Float32frombits(tmp1) return } -func (w *WindowOpen) id() int { return 45 } -func (w *WindowOpen) write(ww io.Writer) (err error) { +func (c *CombatEvent) id() int { return 44 } +func (c *CombatEvent) write(ww io.Writer) (err error) { var tmp [4]byte - tmp[0] = byte(w.ID >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - if err = WriteString(ww, w.Type); err != nil { - return - } - var tmp0 []byte - if tmp0, err = json.Marshal(&w.Title); err != nil { + if err = WriteVarInt(ww, c.Event); err != nil { return } - tmp1 := string(tmp0) - if err = WriteString(ww, tmp1); err != nil { - return + if c.Event == 1 { + if err = WriteVarInt(ww, c.Duration); err != nil { + return + } } - tmp[0] = byte(w.SlotCount >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return + if c.Event == 2 { + if err = WriteVarInt(ww, c.PlayerID); err != nil { + return + } } - if w.Type == "EntityHorse" { - tmp[0] = byte(w.EntityID >> 24) - tmp[1] = byte(w.EntityID >> 16) - tmp[2] = byte(w.EntityID >> 8) - tmp[3] = byte(w.EntityID >> 0) + if c.Event == 1 || c.Event == 2 { + tmp[0] = byte(c.EntityID >> 24) + tmp[1] = byte(c.EntityID >> 16) + tmp[2] = byte(c.EntityID >> 8) + tmp[3] = byte(c.EntityID >> 0) if _, err = ww.Write(tmp[:4]); err != nil { return } } + if c.Event == 2 { + var tmp0 []byte + if tmp0, err = json.Marshal(&c.Message); err != nil { + return + } + tmp1 := string(tmp0) + if err = WriteString(ww, tmp1); err != nil { + return + } + } return } -func (w *WindowOpen) read(rr io.Reader) (err error) { +func (c *CombatEvent) read(rr io.Reader) (err error) { var tmp [4]byte - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - w.ID = (byte(tmp[0]) << 0) - if w.Type, err = ReadString(rr); err != nil { + if c.Event, err = ReadVarInt(rr); err != nil { return } - var tmp0 string - if tmp0, err = ReadString(rr); err != nil { - return err - } - if err = json.Unmarshal([]byte(tmp0), &w.Title); err != nil { - return + if c.Event == 1 { + if c.Duration, err = ReadVarInt(rr); err != nil { + return + } } - if _, err = rr.Read(tmp[:1]); err != nil { - return + if c.Event == 2 { + if c.PlayerID, err = ReadVarInt(rr); err != nil { + return + } } - w.SlotCount = (byte(tmp[0]) << 0) - if w.Type == "EntityHorse" { + if c.Event == 1 || c.Event == 2 { if _, err = rr.Read(tmp[:4]); err != nil { return } - w.EntityID = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - } - return -} - -func (w *WindowClose) id() int { return 46 } -func (w *WindowClose) write(ww io.Writer) (err error) { - var tmp [1]byte - tmp[0] = byte(w.ID >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return + c.EntityID = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) } - return -} -func (w *WindowClose) read(rr io.Reader) (err error) { - var tmp [1]byte - if _, err = rr.Read(tmp[:1]); err != nil { - return + if c.Event == 2 { + var tmp0 string + if tmp0, err = ReadString(rr); err != nil { + return err + } + if err = json.Unmarshal([]byte(tmp0), &c.Message); err != nil { + return + } } - w.ID = (byte(tmp[0]) << 0) return } -func (w *WindowSetSlot) id() int { return 47 } -func (w *WindowSetSlot) write(ww io.Writer) (err error) { - var tmp [2]byte - tmp[0] = byte(w.ID >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { +func (p *PlayerInfo) id() int { return 45 } +func (p *PlayerInfo) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, p.Action); err != nil { return } - tmp[0] = byte(w.Slot >> 8) - tmp[1] = byte(w.Slot >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { + if err = WriteVarInt(ww, VarInt(len(p.Players))); err != nil { return } - if err = w.ItemStack.Serialize(ww); err != nil { - return + for tmp0 := range p.Players { + if err = p.Players[tmp0].UUID.Serialize(ww); err != nil { + return + } + if p.Action == 0 { + if err = WriteString(ww, p.Players[tmp0].Name); err != nil { + return + } + if err = WriteVarInt(ww, VarInt(len(p.Players[tmp0].Properties))); err != nil { + return + } + for tmp1 := range p.Players[tmp0].Properties { + if err = WriteString(ww, p.Players[tmp0].Properties[tmp1].Name); err != nil { + return + } + if err = WriteString(ww, p.Players[tmp0].Properties[tmp1].Value); err != nil { + return + } + if err = WriteBool(ww, p.Players[tmp0].Properties[tmp1].IsSigned); err != nil { + return + } + if p.Players[tmp0].Properties[tmp1].IsSigned == true { + if err = WriteString(ww, p.Players[tmp0].Properties[tmp1].Signature); err != nil { + return + } + } + } + } + if p.Action == 0 || p.Action == 1 { + if err = WriteVarInt(ww, p.Players[tmp0].GameMode); err != nil { + return + } + } + if p.Action == 0 || p.Action == 2 { + if err = WriteVarInt(ww, p.Players[tmp0].Ping); err != nil { + return + } + } + if p.Action == 0 || p.Action == 3 { + if err = WriteBool(ww, p.Players[tmp0].HasDisplay); err != nil { + return + } + } + if p.Players[tmp0].HasDisplay == true { + var tmp2 []byte + if tmp2, err = json.Marshal(&p.Players[tmp0].DisplayName); err != nil { + return + } + tmp3 := string(tmp2) + if err = WriteString(ww, tmp3); err != nil { + return + } + } } return } -func (w *WindowSetSlot) read(rr io.Reader) (err error) { - var tmp [2]byte - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - w.ID = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:2]); err != nil { +func (p *PlayerInfo) read(rr io.Reader) (err error) { + if p.Action, err = ReadVarInt(rr); err != nil { return } - w.Slot = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) - if err = w.ItemStack.Deserialize(rr); err != nil { + var tmp0 VarInt + if tmp0, err = ReadVarInt(rr); err != nil { return } - return -} - -func (w *WindowItems) id() int { return 48 } -func (w *WindowItems) write(ww io.Writer) (err error) { - var tmp [2]byte - tmp[0] = byte(w.ID >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return + if tmp0 > math.MaxInt16 { + return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) } - tmp[0] = byte(int16(len(w.Items)) >> 8) - tmp[1] = byte(int16(len(w.Items)) >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { - return + if tmp0 < 0 { + return fmt.Errorf("negative array size: %d < 0", tmp0) } - for tmp0 := range w.Items { - if err = w.Items[tmp0].Serialize(ww); err != nil { + p.Players = make([]PlayerDetail, tmp0) + for tmp1 := range p.Players { + if err = p.Players[tmp1].UUID.Deserialize(rr); err != nil { return } - } - return -} -func (w *WindowItems) read(rr io.Reader) (err error) { - var tmp [2]byte - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - w.ID = (byte(tmp[0]) << 0) - var tmp0 int16 - if _, err = rr.Read(tmp[:2]); err != nil { - return - } - tmp0 = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) - if tmp0 > math.MaxInt16 { - return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) - } - if tmp0 < 0 { - return fmt.Errorf("negative array size: %d < 0", tmp0) - } - w.Items = make([]ItemStack, tmp0) - for tmp1 := range w.Items { - if err = w.Items[tmp1].Deserialize(rr); err != nil { - return + if p.Action == 0 { + if p.Players[tmp1].Name, err = ReadString(rr); err != nil { + return + } + var tmp2 VarInt + if tmp2, err = ReadVarInt(rr); err != nil { + return + } + if tmp2 > math.MaxInt16 { + return fmt.Errorf("array larger than max value: %d > %d", tmp2, math.MaxInt16) + } + if tmp2 < 0 { + return fmt.Errorf("negative array size: %d < 0", tmp2) + } + p.Players[tmp1].Properties = make([]PlayerProperty, tmp2) + for tmp3 := range p.Players[tmp1].Properties { + if p.Players[tmp1].Properties[tmp3].Name, err = ReadString(rr); err != nil { + return + } + if p.Players[tmp1].Properties[tmp3].Value, err = ReadString(rr); err != nil { + return + } + if p.Players[tmp1].Properties[tmp3].IsSigned, err = ReadBool(rr); err != nil { + return + } + if p.Players[tmp1].Properties[tmp3].IsSigned == true { + if p.Players[tmp1].Properties[tmp3].Signature, err = ReadString(rr); err != nil { + return + } + } + } + } + if p.Action == 0 || p.Action == 1 { + if p.Players[tmp1].GameMode, err = ReadVarInt(rr); err != nil { + return + } + } + if p.Action == 0 || p.Action == 2 { + if p.Players[tmp1].Ping, err = ReadVarInt(rr); err != nil { + return + } + } + if p.Action == 0 || p.Action == 3 { + if p.Players[tmp1].HasDisplay, err = ReadBool(rr); err != nil { + return + } + } + if p.Players[tmp1].HasDisplay == true { + var tmp4 string + if tmp4, err = ReadString(rr); err != nil { + return err + } + if err = json.Unmarshal([]byte(tmp4), &p.Players[tmp1].DisplayName); err != nil { + return + } } } return } -func (w *WindowProperty) id() int { return 49 } -func (w *WindowProperty) write(ww io.Writer) (err error) { - var tmp [2]byte - tmp[0] = byte(w.ID >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { +func (t *TeleportPlayer) id() int { return 46 } +func (t *TeleportPlayer) write(ww io.Writer) (err error) { + var tmp [8]byte + tmp0 := math.Float64bits(t.X) + tmp[0] = byte(tmp0 >> 56) + tmp[1] = byte(tmp0 >> 48) + tmp[2] = byte(tmp0 >> 40) + tmp[3] = byte(tmp0 >> 32) + tmp[4] = byte(tmp0 >> 24) + tmp[5] = byte(tmp0 >> 16) + tmp[6] = byte(tmp0 >> 8) + tmp[7] = byte(tmp0 >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } - tmp[0] = byte(w.Property >> 8) - tmp[1] = byte(w.Property >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { + tmp1 := math.Float64bits(t.Y) + tmp[0] = byte(tmp1 >> 56) + tmp[1] = byte(tmp1 >> 48) + tmp[2] = byte(tmp1 >> 40) + tmp[3] = byte(tmp1 >> 32) + tmp[4] = byte(tmp1 >> 24) + tmp[5] = byte(tmp1 >> 16) + tmp[6] = byte(tmp1 >> 8) + tmp[7] = byte(tmp1 >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } - tmp[0] = byte(w.Value >> 8) - tmp[1] = byte(w.Value >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { + tmp2 := math.Float64bits(t.Z) + tmp[0] = byte(tmp2 >> 56) + tmp[1] = byte(tmp2 >> 48) + tmp[2] = byte(tmp2 >> 40) + tmp[3] = byte(tmp2 >> 32) + tmp[4] = byte(tmp2 >> 24) + tmp[5] = byte(tmp2 >> 16) + tmp[6] = byte(tmp2 >> 8) + tmp[7] = byte(tmp2 >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } - return -} -func (w *WindowProperty) read(rr io.Reader) (err error) { - var tmp [2]byte - if _, err = rr.Read(tmp[:1]); err != nil { + tmp3 := math.Float32bits(t.Yaw) + tmp[0] = byte(tmp3 >> 24) + tmp[1] = byte(tmp3 >> 16) + tmp[2] = byte(tmp3 >> 8) + tmp[3] = byte(tmp3 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - w.ID = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:2]); err != nil { + tmp4 := math.Float32bits(t.Pitch) + tmp[0] = byte(tmp4 >> 24) + tmp[1] = byte(tmp4 >> 16) + tmp[2] = byte(tmp4 >> 8) + tmp[3] = byte(tmp4 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - w.Property = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) - if _, err = rr.Read(tmp[:2]); err != nil { + tmp[0] = byte(t.Flags >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - w.Value = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) return } - -func (c *ConfirmTransaction) id() int { return 50 } -func (c *ConfirmTransaction) write(ww io.Writer) (err error) { - var tmp [2]byte - tmp[0] = byte(c.ID >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { +func (t *TeleportPlayer) read(rr io.Reader) (err error) { + var tmp [8]byte + var tmp0 uint64 + if _, err = rr.Read(tmp[:8]); err != nil { return } - tmp[0] = byte(c.ActionNumber >> 8) - tmp[1] = byte(c.ActionNumber >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { + tmp0 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) + t.X = math.Float64frombits(tmp0) + var tmp1 uint64 + if _, err = rr.Read(tmp[:8]); err != nil { return } - if err = WriteBool(ww, c.Accepted); err != nil { + tmp1 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) + t.Y = math.Float64frombits(tmp1) + var tmp2 uint64 + if _, err = rr.Read(tmp[:8]); err != nil { return } - return -} -func (c *ConfirmTransaction) read(rr io.Reader) (err error) { - var tmp [2]byte - if _, err = rr.Read(tmp[:1]); err != nil { + tmp2 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) + t.Z = math.Float64frombits(tmp2) + var tmp3 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - c.ID = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:2]); err != nil { + tmp3 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + t.Yaw = math.Float32frombits(tmp3) + var tmp4 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - c.ActionNumber = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) - if c.Accepted, err = ReadBool(rr); err != nil { + tmp4 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + t.Pitch = math.Float32frombits(tmp4) + if _, err = rr.Read(tmp[:1]); err != nil { return } + t.Flags = (byte(tmp[0]) << 0) return } -func (u *UpdateSign) id() int { return 51 } -func (u *UpdateSign) write(ww io.Writer) (err error) { +func (e *EntityUsedBed) id() int { return 47 } +func (e *EntityUsedBed) write(ww io.Writer) (err error) { var tmp [8]byte - tmp[0] = byte(u.Location >> 56) - tmp[1] = byte(u.Location >> 48) - tmp[2] = byte(u.Location >> 40) - tmp[3] = byte(u.Location >> 32) - tmp[4] = byte(u.Location >> 24) - tmp[5] = byte(u.Location >> 16) - tmp[6] = byte(u.Location >> 8) - tmp[7] = byte(u.Location >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + if err = WriteVarInt(ww, e.EntityID); err != nil { return } - var tmp0 []byte - if tmp0, err = json.Marshal(&u.Line1); err != nil { + tmp[0] = byte(e.Location >> 56) + tmp[1] = byte(e.Location >> 48) + tmp[2] = byte(e.Location >> 40) + tmp[3] = byte(e.Location >> 32) + tmp[4] = byte(e.Location >> 24) + tmp[5] = byte(e.Location >> 16) + tmp[6] = byte(e.Location >> 8) + tmp[7] = byte(e.Location >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } - tmp1 := string(tmp0) - if err = WriteString(ww, tmp1); err != nil { + return +} +func (e *EntityUsedBed) read(rr io.Reader) (err error) { + var tmp [8]byte + if e.EntityID, err = ReadVarInt(rr); err != nil { return } - var tmp2 []byte - if tmp2, err = json.Marshal(&u.Line2); err != nil { + if _, err = rr.Read(tmp[:8]); err != nil { return } - tmp3 := string(tmp2) - if err = WriteString(ww, tmp3); err != nil { + e.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) + return +} + +func (e *EntityDestroy) id() int { return 48 } +func (e *EntityDestroy) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, VarInt(len(e.EntityIDs))); err != nil { return } - var tmp4 []byte - if tmp4, err = json.Marshal(&u.Line3); err != nil { - return + for tmp0 := range e.EntityIDs { + if err = WriteVarInt(ww, e.EntityIDs[tmp0]); err != nil { + return + } } - tmp5 := string(tmp4) - if err = WriteString(ww, tmp5); err != nil { + return +} +func (e *EntityDestroy) read(rr io.Reader) (err error) { + var tmp0 VarInt + if tmp0, err = ReadVarInt(rr); err != nil { return } - var tmp6 []byte - if tmp6, err = json.Marshal(&u.Line4); err != nil { - return + if tmp0 > math.MaxInt16 { + return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) } - tmp7 := string(tmp6) - if err = WriteString(ww, tmp7); err != nil { - return + if tmp0 < 0 { + return fmt.Errorf("negative array size: %d < 0", tmp0) + } + e.EntityIDs = make([]VarInt, tmp0) + for tmp1 := range e.EntityIDs { + if e.EntityIDs[tmp1], err = ReadVarInt(rr); err != nil { + return + } } return } -func (u *UpdateSign) read(rr io.Reader) (err error) { - var tmp [8]byte - if _, err = rr.Read(tmp[:8]); err != nil { - return - } - u.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) - var tmp0 string - if tmp0, err = ReadString(rr); err != nil { - return err - } - if err = json.Unmarshal([]byte(tmp0), &u.Line1); err != nil { + +func (e *EntityRemoveEffect) id() int { return 49 } +func (e *EntityRemoveEffect) write(ww io.Writer) (err error) { + var tmp [1]byte + if err = WriteVarInt(ww, e.EntityID); err != nil { return } - var tmp1 string - if tmp1, err = ReadString(rr); err != nil { - return err - } - if err = json.Unmarshal([]byte(tmp1), &u.Line2); err != nil { + tmp[0] = byte(e.EffectID >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - var tmp2 string - if tmp2, err = ReadString(rr); err != nil { - return err - } - if err = json.Unmarshal([]byte(tmp2), &u.Line3); err != nil { + return +} +func (e *EntityRemoveEffect) read(rr io.Reader) (err error) { + var tmp [1]byte + if e.EntityID, err = ReadVarInt(rr); err != nil { return } - var tmp3 string - if tmp3, err = ReadString(rr); err != nil { - return err - } - if err = json.Unmarshal([]byte(tmp3), &u.Line4); err != nil { + if _, err = rr.Read(tmp[:1]); err != nil { return } + e.EffectID = int8((uint8(tmp[0]) << 0)) return } -func (m *Maps) id() int { return 52 } -func (m *Maps) write(ww io.Writer) (err error) { - var tmp [1]byte - if err = WriteVarInt(ww, m.ItemDamage); err != nil { - return - } - tmp[0] = byte(m.Scale >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { +func (r *ResourcePackSend) id() int { return 50 } +func (r *ResourcePackSend) write(ww io.Writer) (err error) { + if err = WriteString(ww, r.URL); err != nil { return } - if err = WriteBool(ww, m.TrackingPosition); err != nil { + if err = WriteString(ww, r.Hash); err != nil { return } - if err = WriteVarInt(ww, VarInt(len(m.Icons))); err != nil { + return +} +func (r *ResourcePackSend) read(rr io.Reader) (err error) { + if r.URL, err = ReadString(rr); err != nil { return } - for tmp0 := range m.Icons { - tmp[0] = byte(m.Icons[tmp0].DirectionType >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp[0] = byte(m.Icons[tmp0].X >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp[0] = byte(m.Icons[tmp0].Z >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - } - tmp[0] = byte(m.Columns >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + if r.Hash, err = ReadString(rr); err != nil { return } - if m.Columns > 0 { - tmp[0] = byte(m.Rows >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp[0] = byte(m.X >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp[0] = byte(m.Z >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - if err = WriteVarInt(ww, VarInt(len(m.Data))); err != nil { - return - } - if _, err = ww.Write(m.Data); err != nil { - return - } - } return } -func (m *Maps) read(rr io.Reader) (err error) { - var tmp [1]byte - if m.ItemDamage, err = ReadVarInt(rr); err != nil { + +func (r *Respawn) id() int { return 51 } +func (r *Respawn) write(ww io.Writer) (err error) { + var tmp [4]byte + tmp[0] = byte(r.Dimension >> 24) + tmp[1] = byte(r.Dimension >> 16) + tmp[2] = byte(r.Dimension >> 8) + tmp[3] = byte(r.Dimension >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - if _, err = rr.Read(tmp[:1]); err != nil { + tmp[0] = byte(r.Difficulty >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - m.Scale = int8((uint8(tmp[0]) << 0)) - if m.TrackingPosition, err = ReadBool(rr); err != nil { + tmp[0] = byte(r.Gamemode >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - var tmp0 VarInt - if tmp0, err = ReadVarInt(rr); err != nil { + if err = WriteString(ww, r.LevelType); err != nil { return } - if tmp0 > math.MaxInt16 { - return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) - } - if tmp0 < 0 { - return fmt.Errorf("negative array size: %d < 0", tmp0) + return +} +func (r *Respawn) read(rr io.Reader) (err error) { + var tmp [4]byte + if _, err = rr.Read(tmp[:4]); err != nil { + return } - m.Icons = make([]MapIcon, tmp0) - for tmp1 := range m.Icons { - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - m.Icons[tmp1].DirectionType = int8((uint8(tmp[0]) << 0)) - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - m.Icons[tmp1].X = int8((uint8(tmp[0]) << 0)) - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - m.Icons[tmp1].Z = int8((uint8(tmp[0]) << 0)) + r.Dimension = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:1]); err != nil { + return } + r.Difficulty = (byte(tmp[0]) << 0) if _, err = rr.Read(tmp[:1]); err != nil { return } - m.Columns = (byte(tmp[0]) << 0) - if m.Columns > 0 { - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - m.Rows = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - m.X = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - m.Z = (byte(tmp[0]) << 0) - var tmp2 VarInt - if tmp2, err = ReadVarInt(rr); err != nil { - return - } - if tmp2 > math.MaxInt16 { - return fmt.Errorf("array larger than max value: %d > %d", tmp2, math.MaxInt16) - } - if tmp2 < 0 { - return fmt.Errorf("negative array size: %d < 0", tmp2) - } - m.Data = make([]byte, tmp2) - if _, err = rr.Read(m.Data); err != nil { - return - } + r.Gamemode = (byte(tmp[0]) << 0) + if r.LevelType, err = ReadString(rr); err != nil { + return } return } -func (u *UpdateBlockEntity) id() int { return 53 } -func (u *UpdateBlockEntity) write(ww io.Writer) (err error) { - var tmp [8]byte - tmp[0] = byte(u.Location >> 56) - tmp[1] = byte(u.Location >> 48) - tmp[2] = byte(u.Location >> 40) - tmp[3] = byte(u.Location >> 32) - tmp[4] = byte(u.Location >> 24) - tmp[5] = byte(u.Location >> 16) - tmp[6] = byte(u.Location >> 8) - tmp[7] = byte(u.Location >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { +func (e *EntityHeadLook) id() int { return 52 } +func (e *EntityHeadLook) write(ww io.Writer) (err error) { + var tmp [1]byte + if err = WriteVarInt(ww, e.EntityID); err != nil { return } - tmp[0] = byte(u.Action >> 0) + tmp[0] = byte(e.HeadYaw >> 0) if _, err = ww.Write(tmp[:1]); err != nil { return } - if err = WriteNBT(ww, u.NBT); err != nil { - return - } return } -func (u *UpdateBlockEntity) read(rr io.Reader) (err error) { - var tmp [8]byte - if _, err = rr.Read(tmp[:8]); err != nil { +func (e *EntityHeadLook) read(rr io.Reader) (err error) { + var tmp [1]byte + if e.EntityID, err = ReadVarInt(rr); err != nil { return } - u.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) if _, err = rr.Read(tmp[:1]); err != nil { return } - u.Action = (byte(tmp[0]) << 0) - if u.NBT, err = ReadNBT(rr); err != nil { - return - } + e.HeadYaw = int8((uint8(tmp[0]) << 0)) return } -func (s *SignEditorOpen) id() int { return 54 } -func (s *SignEditorOpen) write(ww io.Writer) (err error) { - var tmp [8]byte - tmp[0] = byte(s.Location >> 56) - tmp[1] = byte(s.Location >> 48) - tmp[2] = byte(s.Location >> 40) - tmp[3] = byte(s.Location >> 32) - tmp[4] = byte(s.Location >> 24) - tmp[5] = byte(s.Location >> 16) - tmp[6] = byte(s.Location >> 8) - tmp[7] = byte(s.Location >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { - return - } - return -} -func (s *SignEditorOpen) read(rr io.Reader) (err error) { +func (w *WorldBorder) id() int { return 53 } +func (w *WorldBorder) write(ww io.Writer) (err error) { var tmp [8]byte - if _, err = rr.Read(tmp[:8]); err != nil { - return - } - s.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) - return -} - -func (s *Statistics) id() int { return 55 } -func (s *Statistics) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, VarInt(len(s.Statistics))); err != nil { + if err = WriteVarInt(ww, w.Action); err != nil { return } - for tmp0 := range s.Statistics { - if err = WriteString(ww, s.Statistics[tmp0].Name); err != nil { - return - } - if err = WriteVarInt(ww, s.Statistics[tmp0].Value); err != nil { + if w.Action == 3 || w.Action == 1 { + tmp0 := math.Float64bits(w.OldRadius) + tmp[0] = byte(tmp0 >> 56) + tmp[1] = byte(tmp0 >> 48) + tmp[2] = byte(tmp0 >> 40) + tmp[3] = byte(tmp0 >> 32) + tmp[4] = byte(tmp0 >> 24) + tmp[5] = byte(tmp0 >> 16) + tmp[6] = byte(tmp0 >> 8) + tmp[7] = byte(tmp0 >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } } - return -} -func (s *Statistics) read(rr io.Reader) (err error) { - var tmp0 VarInt - if tmp0, err = ReadVarInt(rr); err != nil { - return - } - if tmp0 > math.MaxInt16 { - return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) - } - if tmp0 < 0 { - return fmt.Errorf("negative array size: %d < 0", tmp0) - } - s.Statistics = make([]Statistic, tmp0) - for tmp1 := range s.Statistics { - if s.Statistics[tmp1].Name, err = ReadString(rr); err != nil { + if w.Action == 3 || w.Action == 1 || w.Action == 0 { + tmp1 := math.Float64bits(w.NewRadius) + tmp[0] = byte(tmp1 >> 56) + tmp[1] = byte(tmp1 >> 48) + tmp[2] = byte(tmp1 >> 40) + tmp[3] = byte(tmp1 >> 32) + tmp[4] = byte(tmp1 >> 24) + tmp[5] = byte(tmp1 >> 16) + tmp[6] = byte(tmp1 >> 8) + tmp[7] = byte(tmp1 >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } - if s.Statistics[tmp1].Value, err = ReadVarInt(rr); err != nil { + } + if w.Action == 3 || w.Action == 1 { + if err = WriteVarLong(ww, w.Speed); err != nil { return } } - return -} - -func (p *PlayerInfo) id() int { return 56 } -func (p *PlayerInfo) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, p.Action); err != nil { - return - } - if err = WriteVarInt(ww, VarInt(len(p.Players))); err != nil { - return - } - for tmp0 := range p.Players { - if err = p.Players[tmp0].UUID.Serialize(ww); err != nil { + if w.Action == 3 || w.Action == 2 { + tmp2 := math.Float64bits(w.X) + tmp[0] = byte(tmp2 >> 56) + tmp[1] = byte(tmp2 >> 48) + tmp[2] = byte(tmp2 >> 40) + tmp[3] = byte(tmp2 >> 32) + tmp[4] = byte(tmp2 >> 24) + tmp[5] = byte(tmp2 >> 16) + tmp[6] = byte(tmp2 >> 8) + tmp[7] = byte(tmp2 >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } - if p.Action == 0 { - if err = WriteString(ww, p.Players[tmp0].Name); err != nil { - return - } - if err = WriteVarInt(ww, VarInt(len(p.Players[tmp0].Properties))); err != nil { - return - } - for tmp1 := range p.Players[tmp0].Properties { - if err = WriteString(ww, p.Players[tmp0].Properties[tmp1].Name); err != nil { - return - } - if err = WriteString(ww, p.Players[tmp0].Properties[tmp1].Value); err != nil { - return - } - if err = WriteBool(ww, p.Players[tmp0].Properties[tmp1].IsSigned); err != nil { - return - } - if p.Players[tmp0].Properties[tmp1].IsSigned == true { - if err = WriteString(ww, p.Players[tmp0].Properties[tmp1].Signature); err != nil { - return - } - } - } - } - if p.Action == 0 || p.Action == 1 { - if err = WriteVarInt(ww, p.Players[tmp0].GameMode); err != nil { - return - } - } - if p.Action == 0 || p.Action == 2 { - if err = WriteVarInt(ww, p.Players[tmp0].Ping); err != nil { - return - } - } - if p.Action == 0 || p.Action == 3 { - if err = WriteBool(ww, p.Players[tmp0].HasDisplay); err != nil { - return - } - } - if p.Players[tmp0].HasDisplay == true { - var tmp2 []byte - if tmp2, err = json.Marshal(&p.Players[tmp0].DisplayName); err != nil { - return - } - tmp3 := string(tmp2) - if err = WriteString(ww, tmp3); err != nil { - return - } + tmp3 := math.Float64bits(w.Z) + tmp[0] = byte(tmp3 >> 56) + tmp[1] = byte(tmp3 >> 48) + tmp[2] = byte(tmp3 >> 40) + tmp[3] = byte(tmp3 >> 32) + tmp[4] = byte(tmp3 >> 24) + tmp[5] = byte(tmp3 >> 16) + tmp[6] = byte(tmp3 >> 8) + tmp[7] = byte(tmp3 >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { + return } } - return -} -func (p *PlayerInfo) read(rr io.Reader) (err error) { - if p.Action, err = ReadVarInt(rr); err != nil { - return - } - var tmp0 VarInt - if tmp0, err = ReadVarInt(rr); err != nil { - return - } - if tmp0 > math.MaxInt16 { - return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) - } - if tmp0 < 0 { - return fmt.Errorf("negative array size: %d < 0", tmp0) - } - p.Players = make([]PlayerDetail, tmp0) - for tmp1 := range p.Players { - if err = p.Players[tmp1].UUID.Deserialize(rr); err != nil { + if w.Action == 3 { + if err = WriteVarInt(ww, w.PortalBoundary); err != nil { return } - if p.Action == 0 { - if p.Players[tmp1].Name, err = ReadString(rr); err != nil { - return - } - var tmp2 VarInt - if tmp2, err = ReadVarInt(rr); err != nil { - return - } - if tmp2 > math.MaxInt16 { - return fmt.Errorf("array larger than max value: %d > %d", tmp2, math.MaxInt16) - } - if tmp2 < 0 { - return fmt.Errorf("negative array size: %d < 0", tmp2) - } - p.Players[tmp1].Properties = make([]PlayerProperty, tmp2) - for tmp3 := range p.Players[tmp1].Properties { - if p.Players[tmp1].Properties[tmp3].Name, err = ReadString(rr); err != nil { - return - } - if p.Players[tmp1].Properties[tmp3].Value, err = ReadString(rr); err != nil { - return - } - if p.Players[tmp1].Properties[tmp3].IsSigned, err = ReadBool(rr); err != nil { - return - } - if p.Players[tmp1].Properties[tmp3].IsSigned == true { - if p.Players[tmp1].Properties[tmp3].Signature, err = ReadString(rr); err != nil { - return - } - } - } - } - if p.Action == 0 || p.Action == 1 { - if p.Players[tmp1].GameMode, err = ReadVarInt(rr); err != nil { - return - } - } - if p.Action == 0 || p.Action == 2 { - if p.Players[tmp1].Ping, err = ReadVarInt(rr); err != nil { - return - } - } - if p.Action == 0 || p.Action == 3 { - if p.Players[tmp1].HasDisplay, err = ReadBool(rr); err != nil { - return - } - } - if p.Players[tmp1].HasDisplay == true { - var tmp4 string - if tmp4, err = ReadString(rr); err != nil { - return err - } - if err = json.Unmarshal([]byte(tmp4), &p.Players[tmp1].DisplayName); err != nil { - return - } - } - } - return -} - -func (p *PlayerAbilities) id() int { return 57 } -func (p *PlayerAbilities) write(ww io.Writer) (err error) { - var tmp [4]byte - tmp[0] = byte(p.Flags >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp0 := math.Float32bits(p.FlyingSpeed) - tmp[0] = byte(tmp0 >> 24) - tmp[1] = byte(tmp0 >> 16) - tmp[2] = byte(tmp0 >> 8) - tmp[3] = byte(tmp0 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - tmp1 := math.Float32bits(p.WalkingSpeed) - tmp[0] = byte(tmp1 >> 24) - tmp[1] = byte(tmp1 >> 16) - tmp[2] = byte(tmp1 >> 8) - tmp[3] = byte(tmp1 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - return -} -func (p *PlayerAbilities) read(rr io.Reader) (err error) { - var tmp [4]byte - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - p.Flags = (byte(tmp[0]) << 0) - var tmp0 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { - return - } - tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - p.FlyingSpeed = math.Float32frombits(tmp0) - var tmp1 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { - return } - tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - p.WalkingSpeed = math.Float32frombits(tmp1) - return -} - -func (t *TabCompleteReply) id() int { return 58 } -func (t *TabCompleteReply) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, VarInt(len(t.Matches))); err != nil { - return + if w.Action == 3 || w.Action == 4 { + if err = WriteVarInt(ww, w.WarningTime); err != nil { + return + } } - for tmp0 := range t.Matches { - if err = WriteString(ww, t.Matches[tmp0]); err != nil { + if w.Action == 3 || w.Action == 5 { + if err = WriteVarInt(ww, w.WarningBlocks); err != nil { return } } return } -func (t *TabCompleteReply) read(rr io.Reader) (err error) { - var tmp0 VarInt - if tmp0, err = ReadVarInt(rr); err != nil { +func (w *WorldBorder) read(rr io.Reader) (err error) { + var tmp [8]byte + if w.Action, err = ReadVarInt(rr); err != nil { return } - if tmp0 > math.MaxInt16 { - return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) - } - if tmp0 < 0 { - return fmt.Errorf("negative array size: %d < 0", tmp0) - } - t.Matches = make([]string, tmp0) - for tmp1 := range t.Matches { - if t.Matches[tmp1], err = ReadString(rr); err != nil { + if w.Action == 3 || w.Action == 1 { + var tmp0 uint64 + if _, err = rr.Read(tmp[:8]); err != nil { return } + tmp0 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) + w.OldRadius = math.Float64frombits(tmp0) } - return -} - -func (s *ScoreboardObjective) id() int { return 59 } -func (s *ScoreboardObjective) write(ww io.Writer) (err error) { - var tmp [1]byte - if err = WriteString(ww, s.Name); err != nil { - return + if w.Action == 3 || w.Action == 1 || w.Action == 0 { + var tmp1 uint64 + if _, err = rr.Read(tmp[:8]); err != nil { + return + } + tmp1 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) + w.NewRadius = math.Float64frombits(tmp1) } - tmp[0] = byte(s.Mode >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return + if w.Action == 3 || w.Action == 1 { + if w.Speed, err = ReadVarLong(rr); err != nil { + return + } } - if s.Mode == 0 || s.Mode == 2 { - if err = WriteString(ww, s.Value); err != nil { + if w.Action == 3 || w.Action == 2 { + var tmp2 uint64 + if _, err = rr.Read(tmp[:8]); err != nil { return } - if err = WriteString(ww, s.Type); err != nil { + tmp2 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) + w.X = math.Float64frombits(tmp2) + var tmp3 uint64 + if _, err = rr.Read(tmp[:8]); err != nil { return } + tmp3 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) + w.Z = math.Float64frombits(tmp3) } - return -} -func (s *ScoreboardObjective) read(rr io.Reader) (err error) { - var tmp [1]byte - if s.Name, err = ReadString(rr); err != nil { - return - } - if _, err = rr.Read(tmp[:1]); err != nil { - return + if w.Action == 3 { + if w.PortalBoundary, err = ReadVarInt(rr); err != nil { + return + } } - s.Mode = (byte(tmp[0]) << 0) - if s.Mode == 0 || s.Mode == 2 { - if s.Value, err = ReadString(rr); err != nil { + if w.Action == 3 || w.Action == 4 { + if w.WarningTime, err = ReadVarInt(rr); err != nil { return } - if s.Type, err = ReadString(rr); err != nil { + } + if w.Action == 3 || w.Action == 5 { + if w.WarningBlocks, err = ReadVarInt(rr); err != nil { return } } return } -func (u *UpdateScore) id() int { return 60 } -func (u *UpdateScore) write(ww io.Writer) (err error) { - var tmp [1]byte - if err = WriteString(ww, u.Name); err != nil { - return - } - tmp[0] = byte(u.Action >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { +func (c *Camera) id() int { return 54 } +func (c *Camera) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, c.TargetID); err != nil { return } - if err = WriteString(ww, u.ObjectName); err != nil { + return +} +func (c *Camera) read(rr io.Reader) (err error) { + if c.TargetID, err = ReadVarInt(rr); err != nil { return } - if u.Action != 1 { - if err = WriteVarInt(ww, u.Value); err != nil { - return - } - } return } -func (u *UpdateScore) read(rr io.Reader) (err error) { + +func (s *SetCurrentHotbarSlot) id() int { return 55 } +func (s *SetCurrentHotbarSlot) write(ww io.Writer) (err error) { var tmp [1]byte - if u.Name, err = ReadString(rr); err != nil { + tmp[0] = byte(s.Slot >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } + return +} +func (s *SetCurrentHotbarSlot) read(rr io.Reader) (err error) { + var tmp [1]byte if _, err = rr.Read(tmp[:1]); err != nil { return } - u.Action = (byte(tmp[0]) << 0) - if u.ObjectName, err = ReadString(rr); err != nil { - return - } - if u.Action != 1 { - if u.Value, err = ReadVarInt(rr); err != nil { - return - } - } + s.Slot = (byte(tmp[0]) << 0) return } -func (s *ScoreboardDisplay) id() int { return 61 } +func (s *ScoreboardDisplay) id() int { return 56 } func (s *ScoreboardDisplay) write(ww io.Writer) (err error) { var tmp [1]byte tmp[0] = byte(s.Position >> 0) @@ -3221,388 +2962,461 @@ func (s *ScoreboardDisplay) read(rr io.Reader) (err error) { return } -func (t *Teams) id() int { return 62 } -func (t *Teams) write(ww io.Writer) (err error) { - var tmp [1]byte - if err = WriteString(ww, t.Name); err != nil { +func (e *EntityMetadata) id() int { return 57 } +func (e *EntityMetadata) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, e.EntityID); err != nil { return } - tmp[0] = byte(t.Mode >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + if err = writeMetadata(ww, e.Metadata); err != nil { return } - if t.Mode == 0 || t.Mode == 2 { - if err = WriteString(ww, t.DisplayName); err != nil { - return - } - if err = WriteString(ww, t.Prefix); err != nil { - return - } - if err = WriteString(ww, t.Suffix); err != nil { - return - } - tmp[0] = byte(t.Flags >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - if err = WriteString(ww, t.NameTagVisibility); err != nil { - return - } - tmp[0] = byte(t.Color >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } + return +} +func (e *EntityMetadata) read(rr io.Reader) (err error) { + if e.EntityID, err = ReadVarInt(rr); err != nil { + return } - if t.Mode == 0 || t.Mode == 3 || t.Mode == 4 { - if err = WriteVarInt(ww, VarInt(len(t.Players))); err != nil { - return - } - for tmp0 := range t.Players { - if err = WriteString(ww, t.Players[tmp0]); err != nil { - return - } - } + if e.Metadata, err = readMetadata(rr); err != nil { + return } return } -func (t *Teams) read(rr io.Reader) (err error) { - var tmp [1]byte - if t.Name, err = ReadString(rr); err != nil { + +func (e *EntityAttach) id() int { return 58 } +func (e *EntityAttach) write(ww io.Writer) (err error) { + var tmp [4]byte + tmp[0] = byte(e.EntityID >> 24) + tmp[1] = byte(e.EntityID >> 16) + tmp[2] = byte(e.EntityID >> 8) + tmp[3] = byte(e.EntityID >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - if _, err = rr.Read(tmp[:1]); err != nil { + tmp[0] = byte(e.Vehicle >> 24) + tmp[1] = byte(e.Vehicle >> 16) + tmp[2] = byte(e.Vehicle >> 8) + tmp[3] = byte(e.Vehicle >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - t.Mode = (byte(tmp[0]) << 0) - if t.Mode == 0 || t.Mode == 2 { - if t.DisplayName, err = ReadString(rr); err != nil { - return - } - if t.Prefix, err = ReadString(rr); err != nil { - return - } - if t.Suffix, err = ReadString(rr); err != nil { - return - } - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - t.Flags = (byte(tmp[0]) << 0) - if t.NameTagVisibility, err = ReadString(rr); err != nil { - return - } - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - t.Color = (byte(tmp[0]) << 0) + if err = WriteBool(ww, e.Leash); err != nil { + return + } + return +} +func (e *EntityAttach) read(rr io.Reader) (err error) { + var tmp [4]byte + if _, err = rr.Read(tmp[:4]); err != nil { + return + } + e.EntityID = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:4]); err != nil { + return + } + e.Vehicle = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if e.Leash, err = ReadBool(rr); err != nil { + return + } + return +} + +func (e *EntityVelocity) id() int { return 59 } +func (e *EntityVelocity) write(ww io.Writer) (err error) { + var tmp [2]byte + if err = WriteVarInt(ww, e.EntityID); err != nil { + return + } + tmp[0] = byte(e.VelocityX >> 8) + tmp[1] = byte(e.VelocityX >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { + return + } + tmp[0] = byte(e.VelocityY >> 8) + tmp[1] = byte(e.VelocityY >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { + return + } + tmp[0] = byte(e.VelocityZ >> 8) + tmp[1] = byte(e.VelocityZ >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { + return + } + return +} +func (e *EntityVelocity) read(rr io.Reader) (err error) { + var tmp [2]byte + if e.EntityID, err = ReadVarInt(rr); err != nil { + return + } + if _, err = rr.Read(tmp[:2]); err != nil { + return + } + e.VelocityX = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + if _, err = rr.Read(tmp[:2]); err != nil { + return } - if t.Mode == 0 || t.Mode == 3 || t.Mode == 4 { - var tmp0 VarInt - if tmp0, err = ReadVarInt(rr); err != nil { - return - } - if tmp0 > math.MaxInt16 { - return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) - } - if tmp0 < 0 { - return fmt.Errorf("negative array size: %d < 0", tmp0) - } - t.Players = make([]string, tmp0) - for tmp1 := range t.Players { - if t.Players[tmp1], err = ReadString(rr); err != nil { - return - } - } + e.VelocityY = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + if _, err = rr.Read(tmp[:2]); err != nil { + return } + e.VelocityZ = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) return } -func (p *PluginMessageClientbound) id() int { return 63 } -func (p *PluginMessageClientbound) write(ww io.Writer) (err error) { - if err = WriteString(ww, p.Channel); err != nil { +func (e *EntityEquipment) id() int { return 60 } +func (e *EntityEquipment) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, e.EntityID); err != nil { return } - if _, err = ww.Write(p.Data); err != nil { + if err = WriteVarInt(ww, e.Slot); err != nil { + return + } + if err = e.Item.Serialize(ww); err != nil { return } return } -func (p *PluginMessageClientbound) read(rr io.Reader) (err error) { - if p.Channel, err = ReadString(rr); err != nil { +func (e *EntityEquipment) read(rr io.Reader) (err error) { + if e.EntityID, err = ReadVarInt(rr); err != nil { return } - if p.Data, err = ioutil.ReadAll(rr); err != nil { + if e.Slot, err = ReadVarInt(rr); err != nil { + return + } + if err = e.Item.Deserialize(rr); err != nil { return } return } -func (d *Disconnect) id() int { return 64 } -func (d *Disconnect) write(ww io.Writer) (err error) { - var tmp0 []byte - if tmp0, err = json.Marshal(&d.Reason); err != nil { +func (s *SetExperience) id() int { return 61 } +func (s *SetExperience) write(ww io.Writer) (err error) { + var tmp [4]byte + tmp0 := math.Float32bits(s.ExperienceBar) + tmp[0] = byte(tmp0 >> 24) + tmp[1] = byte(tmp0 >> 16) + tmp[2] = byte(tmp0 >> 8) + tmp[3] = byte(tmp0 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp1 := string(tmp0) - if err = WriteString(ww, tmp1); err != nil { + if err = WriteVarInt(ww, s.Level); err != nil { + return + } + if err = WriteVarInt(ww, s.TotalExperience); err != nil { return } return } -func (d *Disconnect) read(rr io.Reader) (err error) { - var tmp0 string - if tmp0, err = ReadString(rr); err != nil { - return err +func (s *SetExperience) read(rr io.Reader) (err error) { + var tmp [4]byte + var tmp0 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { + return } - if err = json.Unmarshal([]byte(tmp0), &d.Reason); err != nil { + tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + s.ExperienceBar = math.Float32frombits(tmp0) + if s.Level, err = ReadVarInt(rr); err != nil { + return + } + if s.TotalExperience, err = ReadVarInt(rr); err != nil { return } return } -func (s *ServerDifficulty) id() int { return 65 } -func (s *ServerDifficulty) write(ww io.Writer) (err error) { - var tmp [1]byte - tmp[0] = byte(s.Difficulty >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { +func (u *UpdateHealth) id() int { return 62 } +func (u *UpdateHealth) write(ww io.Writer) (err error) { + var tmp [4]byte + tmp0 := math.Float32bits(u.Health) + tmp[0] = byte(tmp0 >> 24) + tmp[1] = byte(tmp0 >> 16) + tmp[2] = byte(tmp0 >> 8) + tmp[3] = byte(tmp0 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - return -} -func (s *ServerDifficulty) read(rr io.Reader) (err error) { - var tmp [1]byte - if _, err = rr.Read(tmp[:1]); err != nil { + if err = WriteVarInt(ww, u.Food); err != nil { + return + } + tmp1 := math.Float32bits(u.FoodSaturation) + tmp[0] = byte(tmp1 >> 24) + tmp[1] = byte(tmp1 >> 16) + tmp[2] = byte(tmp1 >> 8) + tmp[3] = byte(tmp1 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - s.Difficulty = (byte(tmp[0]) << 0) return } - -func (c *CombatEvent) id() int { return 66 } -func (c *CombatEvent) write(ww io.Writer) (err error) { +func (u *UpdateHealth) read(rr io.Reader) (err error) { var tmp [4]byte - if err = WriteVarInt(ww, c.Event); err != nil { + var tmp0 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - if c.Event == 1 { - if err = WriteVarInt(ww, c.Duration); err != nil { - return - } + tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + u.Health = math.Float32frombits(tmp0) + if u.Food, err = ReadVarInt(rr); err != nil { + return } - if c.Event == 2 { - if err = WriteVarInt(ww, c.PlayerID); err != nil { - return - } + var tmp1 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { + return } - if c.Event == 1 || c.Event == 2 { - tmp[0] = byte(c.EntityID >> 24) - tmp[1] = byte(c.EntityID >> 16) - tmp[2] = byte(c.EntityID >> 8) - tmp[3] = byte(c.EntityID >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } + tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + u.FoodSaturation = math.Float32frombits(tmp1) + return +} + +func (s *ScoreboardObjective) id() int { return 63 } +func (s *ScoreboardObjective) write(ww io.Writer) (err error) { + var tmp [1]byte + if err = WriteString(ww, s.Name); err != nil { + return } - if c.Event == 2 { - var tmp0 []byte - if tmp0, err = json.Marshal(&c.Message); err != nil { + tmp[0] = byte(s.Mode >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + if s.Mode == 0 || s.Mode == 2 { + if err = WriteString(ww, s.Value); err != nil { return } - tmp1 := string(tmp0) - if err = WriteString(ww, tmp1); err != nil { + if err = WriteString(ww, s.Type); err != nil { return } } return } -func (c *CombatEvent) read(rr io.Reader) (err error) { - var tmp [4]byte - if c.Event, err = ReadVarInt(rr); err != nil { +func (s *ScoreboardObjective) read(rr io.Reader) (err error) { + var tmp [1]byte + if s.Name, err = ReadString(rr); err != nil { return } - if c.Event == 1 { - if c.Duration, err = ReadVarInt(rr); err != nil { - return - } - } - if c.Event == 2 { - if c.PlayerID, err = ReadVarInt(rr); err != nil { - return - } + if _, err = rr.Read(tmp[:1]); err != nil { + return } - if c.Event == 1 || c.Event == 2 { - if _, err = rr.Read(tmp[:4]); err != nil { + s.Mode = (byte(tmp[0]) << 0) + if s.Mode == 0 || s.Mode == 2 { + if s.Value, err = ReadString(rr); err != nil { return } - c.EntityID = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) - } - if c.Event == 2 { - var tmp0 string - if tmp0, err = ReadString(rr); err != nil { - return err - } - if err = json.Unmarshal([]byte(tmp0), &c.Message); err != nil { + if s.Type, err = ReadString(rr); err != nil { return } } return } -func (c *Camera) id() int { return 67 } -func (c *Camera) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, c.TargetID); err != nil { - return - } - return -} -func (c *Camera) read(rr io.Reader) (err error) { - if c.TargetID, err = ReadVarInt(rr); err != nil { +func (t *Teams) id() int { return 64 } +func (t *Teams) write(ww io.Writer) (err error) { + var tmp [1]byte + if err = WriteString(ww, t.Name); err != nil { return } - return -} - -func (w *WorldBorder) id() int { return 68 } -func (w *WorldBorder) write(ww io.Writer) (err error) { - var tmp [8]byte - if err = WriteVarInt(ww, w.Action); err != nil { + tmp[0] = byte(t.Mode >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - if w.Action == 3 || w.Action == 1 { - tmp0 := math.Float64bits(w.OldRadius) - tmp[0] = byte(tmp0 >> 56) - tmp[1] = byte(tmp0 >> 48) - tmp[2] = byte(tmp0 >> 40) - tmp[3] = byte(tmp0 >> 32) - tmp[4] = byte(tmp0 >> 24) - tmp[5] = byte(tmp0 >> 16) - tmp[6] = byte(tmp0 >> 8) - tmp[7] = byte(tmp0 >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + if t.Mode == 0 || t.Mode == 2 { + if err = WriteString(ww, t.DisplayName); err != nil { return } - } - if w.Action == 3 || w.Action == 1 || w.Action == 0 { - tmp1 := math.Float64bits(w.NewRadius) - tmp[0] = byte(tmp1 >> 56) - tmp[1] = byte(tmp1 >> 48) - tmp[2] = byte(tmp1 >> 40) - tmp[3] = byte(tmp1 >> 32) - tmp[4] = byte(tmp1 >> 24) - tmp[5] = byte(tmp1 >> 16) - tmp[6] = byte(tmp1 >> 8) - tmp[7] = byte(tmp1 >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + if err = WriteString(ww, t.Prefix); err != nil { return } - } - if w.Action == 3 || w.Action == 1 { - if err = WriteVarLong(ww, w.Speed); err != nil { + if err = WriteString(ww, t.Suffix); err != nil { return } - } - if w.Action == 3 || w.Action == 2 { - tmp2 := math.Float64bits(w.X) - tmp[0] = byte(tmp2 >> 56) - tmp[1] = byte(tmp2 >> 48) - tmp[2] = byte(tmp2 >> 40) - tmp[3] = byte(tmp2 >> 32) - tmp[4] = byte(tmp2 >> 24) - tmp[5] = byte(tmp2 >> 16) - tmp[6] = byte(tmp2 >> 8) - tmp[7] = byte(tmp2 >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + tmp[0] = byte(t.Flags >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp3 := math.Float64bits(w.Z) - tmp[0] = byte(tmp3 >> 56) - tmp[1] = byte(tmp3 >> 48) - tmp[2] = byte(tmp3 >> 40) - tmp[3] = byte(tmp3 >> 32) - tmp[4] = byte(tmp3 >> 24) - tmp[5] = byte(tmp3 >> 16) - tmp[6] = byte(tmp3 >> 8) - tmp[7] = byte(tmp3 >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + if err = WriteString(ww, t.NameTagVisibility); err != nil { return } - } - if w.Action == 3 { - if err = WriteVarInt(ww, w.PortalBoundary); err != nil { + if err = WriteString(ww, t.CollisionRule); err != nil { return } - } - if w.Action == 3 || w.Action == 4 { - if err = WriteVarInt(ww, w.WarningTime); err != nil { + tmp[0] = byte(t.Color >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } } - if w.Action == 3 || w.Action == 5 { - if err = WriteVarInt(ww, w.WarningBlocks); err != nil { + if t.Mode == 0 || t.Mode == 3 || t.Mode == 4 { + if err = WriteVarInt(ww, VarInt(len(t.Players))); err != nil { return } + for tmp0 := range t.Players { + if err = WriteString(ww, t.Players[tmp0]); err != nil { + return + } + } } return } -func (w *WorldBorder) read(rr io.Reader) (err error) { - var tmp [8]byte - if w.Action, err = ReadVarInt(rr); err != nil { +func (t *Teams) read(rr io.Reader) (err error) { + var tmp [1]byte + if t.Name, err = ReadString(rr); err != nil { return } - if w.Action == 3 || w.Action == 1 { - var tmp0 uint64 - if _, err = rr.Read(tmp[:8]); err != nil { + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + t.Mode = (byte(tmp[0]) << 0) + if t.Mode == 0 || t.Mode == 2 { + if t.DisplayName, err = ReadString(rr); err != nil { return } - tmp0 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) - w.OldRadius = math.Float64frombits(tmp0) - } - if w.Action == 3 || w.Action == 1 || w.Action == 0 { - var tmp1 uint64 - if _, err = rr.Read(tmp[:8]); err != nil { + if t.Prefix, err = ReadString(rr); err != nil { return } - tmp1 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) - w.NewRadius = math.Float64frombits(tmp1) - } - if w.Action == 3 || w.Action == 1 { - if w.Speed, err = ReadVarLong(rr); err != nil { + if t.Suffix, err = ReadString(rr); err != nil { return } - } - if w.Action == 3 || w.Action == 2 { - var tmp2 uint64 - if _, err = rr.Read(tmp[:8]); err != nil { + if _, err = rr.Read(tmp[:1]); err != nil { return } - tmp2 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) - w.X = math.Float64frombits(tmp2) - var tmp3 uint64 - if _, err = rr.Read(tmp[:8]); err != nil { + t.Flags = (byte(tmp[0]) << 0) + if t.NameTagVisibility, err = ReadString(rr); err != nil { return } - tmp3 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) - w.Z = math.Float64frombits(tmp3) + if t.CollisionRule, err = ReadString(rr); err != nil { + return + } + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + t.Color = (byte(tmp[0]) << 0) } - if w.Action == 3 { - if w.PortalBoundary, err = ReadVarInt(rr); err != nil { + if t.Mode == 0 || t.Mode == 3 || t.Mode == 4 { + var tmp0 VarInt + if tmp0, err = ReadVarInt(rr); err != nil { return } + if tmp0 > math.MaxInt16 { + return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) + } + if tmp0 < 0 { + return fmt.Errorf("negative array size: %d < 0", tmp0) + } + t.Players = make([]string, tmp0) + for tmp1 := range t.Players { + if t.Players[tmp1], err = ReadString(rr); err != nil { + return + } + } } - if w.Action == 3 || w.Action == 4 { - if w.WarningTime, err = ReadVarInt(rr); err != nil { + return +} + +func (u *UpdateScore) id() int { return 65 } +func (u *UpdateScore) write(ww io.Writer) (err error) { + var tmp [1]byte + if err = WriteString(ww, u.Name); err != nil { + return + } + tmp[0] = byte(u.Action >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + if err = WriteString(ww, u.ObjectName); err != nil { + return + } + if u.Action != 1 { + if err = WriteVarInt(ww, u.Value); err != nil { return } } - if w.Action == 3 || w.Action == 5 { - if w.WarningBlocks, err = ReadVarInt(rr); err != nil { + return +} +func (u *UpdateScore) read(rr io.Reader) (err error) { + var tmp [1]byte + if u.Name, err = ReadString(rr); err != nil { + return + } + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + u.Action = (byte(tmp[0]) << 0) + if u.ObjectName, err = ReadString(rr); err != nil { + return + } + if u.Action != 1 { + if u.Value, err = ReadVarInt(rr); err != nil { return } } return } -func (t *Title) id() int { return 69 } +func (s *SpawnPosition) id() int { return 66 } +func (s *SpawnPosition) write(ww io.Writer) (err error) { + var tmp [8]byte + tmp[0] = byte(s.Location >> 56) + tmp[1] = byte(s.Location >> 48) + tmp[2] = byte(s.Location >> 40) + tmp[3] = byte(s.Location >> 32) + tmp[4] = byte(s.Location >> 24) + tmp[5] = byte(s.Location >> 16) + tmp[6] = byte(s.Location >> 8) + tmp[7] = byte(s.Location >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { + return + } + return +} +func (s *SpawnPosition) read(rr io.Reader) (err error) { + var tmp [8]byte + if _, err = rr.Read(tmp[:8]); err != nil { + return + } + s.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) + return +} + +func (t *TimeUpdate) id() int { return 67 } +func (t *TimeUpdate) write(ww io.Writer) (err error) { + var tmp [8]byte + tmp[0] = byte(t.WorldAge >> 56) + tmp[1] = byte(t.WorldAge >> 48) + tmp[2] = byte(t.WorldAge >> 40) + tmp[3] = byte(t.WorldAge >> 32) + tmp[4] = byte(t.WorldAge >> 24) + tmp[5] = byte(t.WorldAge >> 16) + tmp[6] = byte(t.WorldAge >> 8) + tmp[7] = byte(t.WorldAge >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { + return + } + tmp[0] = byte(t.TimeOfDay >> 56) + tmp[1] = byte(t.TimeOfDay >> 48) + tmp[2] = byte(t.TimeOfDay >> 40) + tmp[3] = byte(t.TimeOfDay >> 32) + tmp[4] = byte(t.TimeOfDay >> 24) + tmp[5] = byte(t.TimeOfDay >> 16) + tmp[6] = byte(t.TimeOfDay >> 8) + tmp[7] = byte(t.TimeOfDay >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { + return + } + return +} +func (t *TimeUpdate) read(rr io.Reader) (err error) { + var tmp [8]byte + if _, err = rr.Read(tmp[:8]); err != nil { + return + } + t.WorldAge = int64((uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56)) + if _, err = rr.Read(tmp[:8]); err != nil { + return + } + t.TimeOfDay = int64((uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56)) + return +} + +func (t *Title) id() int { return 68 } func (t *Title) write(ww io.Writer) (err error) { var tmp [4]byte if err = WriteVarInt(ww, t.Action); err != nil { @@ -3693,21 +3507,92 @@ func (t *Title) read(rr io.Reader) (err error) { return } -func (s *SetCompression) id() int { return 70 } -func (s *SetCompression) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, s.Threshold); err != nil { +func (u *UpdateSign) id() int { return 69 } +func (u *UpdateSign) write(ww io.Writer) (err error) { + var tmp [8]byte + tmp[0] = byte(u.Location >> 56) + tmp[1] = byte(u.Location >> 48) + tmp[2] = byte(u.Location >> 40) + tmp[3] = byte(u.Location >> 32) + tmp[4] = byte(u.Location >> 24) + tmp[5] = byte(u.Location >> 16) + tmp[6] = byte(u.Location >> 8) + tmp[7] = byte(u.Location >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { + return + } + var tmp0 []byte + if tmp0, err = json.Marshal(&u.Line1); err != nil { + return + } + tmp1 := string(tmp0) + if err = WriteString(ww, tmp1); err != nil { + return + } + var tmp2 []byte + if tmp2, err = json.Marshal(&u.Line2); err != nil { + return + } + tmp3 := string(tmp2) + if err = WriteString(ww, tmp3); err != nil { + return + } + var tmp4 []byte + if tmp4, err = json.Marshal(&u.Line3); err != nil { + return + } + tmp5 := string(tmp4) + if err = WriteString(ww, tmp5); err != nil { + return + } + var tmp6 []byte + if tmp6, err = json.Marshal(&u.Line4); err != nil { + return + } + tmp7 := string(tmp6) + if err = WriteString(ww, tmp7); err != nil { return } return } -func (s *SetCompression) read(rr io.Reader) (err error) { - if s.Threshold, err = ReadVarInt(rr); err != nil { +func (u *UpdateSign) read(rr io.Reader) (err error) { + var tmp [8]byte + if _, err = rr.Read(tmp[:8]); err != nil { + return + } + u.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) + var tmp0 string + if tmp0, err = ReadString(rr); err != nil { + return err + } + if err = json.Unmarshal([]byte(tmp0), &u.Line1); err != nil { + return + } + var tmp1 string + if tmp1, err = ReadString(rr); err != nil { + return err + } + if err = json.Unmarshal([]byte(tmp1), &u.Line2); err != nil { + return + } + var tmp2 string + if tmp2, err = ReadString(rr); err != nil { + return err + } + if err = json.Unmarshal([]byte(tmp2), &u.Line3); err != nil { + return + } + var tmp3 string + if tmp3, err = ReadString(rr); err != nil { + return err + } + if err = json.Unmarshal([]byte(tmp3), &u.Line4); err != nil { return } return } -func (p *PlayerListHeaderFooter) id() int { return 71 } +func (p *PlayerListHeaderFooter) id() int { return 70 } func (p *PlayerListHeaderFooter) write(ww io.Writer) (err error) { var tmp0 []byte if tmp0, err = json.Marshal(&p.Header); err != nil { @@ -3745,207 +3630,328 @@ func (p *PlayerListHeaderFooter) read(rr io.Reader) (err error) { return } -func (r *ResourcePackSend) id() int { return 72 } -func (r *ResourcePackSend) write(ww io.Writer) (err error) { - if err = WriteString(ww, r.URL); err != nil { +func (c *CollectItem) id() int { return 71 } +func (c *CollectItem) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, c.CollectedEntityID); err != nil { return } - if err = WriteString(ww, r.Hash); err != nil { + if err = WriteVarInt(ww, c.CollectorEntityID); err != nil { return } return } -func (r *ResourcePackSend) read(rr io.Reader) (err error) { - if r.URL, err = ReadString(rr); err != nil { +func (c *CollectItem) read(rr io.Reader) (err error) { + if c.CollectedEntityID, err = ReadVarInt(rr); err != nil { return } - if r.Hash, err = ReadString(rr); err != nil { + if c.CollectorEntityID, err = ReadVarInt(rr); err != nil { return } return } -func (b *BossBar) id() int { return 73 } -func (b *BossBar) write(ww io.Writer) (err error) { +func (e *EntityTeleport) id() int { return 72 } +func (e *EntityTeleport) write(ww io.Writer) (err error) { var tmp [4]byte - if err = b.UUID.Serialize(ww); err != nil { + if err = WriteVarInt(ww, e.EntityID); err != nil { return } - if err = WriteVarInt(ww, b.Action); err != nil { + tmp[0] = byte(e.X >> 24) + tmp[1] = byte(e.X >> 16) + tmp[2] = byte(e.X >> 8) + tmp[3] = byte(e.X >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - if b.Action == 0 || b.Action == 3 { - var tmp0 []byte - if tmp0, err = json.Marshal(&b.Title); err != nil { - return - } - tmp1 := string(tmp0) - if err = WriteString(ww, tmp1); err != nil { - return - } + tmp[0] = byte(e.Y >> 24) + tmp[1] = byte(e.Y >> 16) + tmp[2] = byte(e.Y >> 8) + tmp[3] = byte(e.Y >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { + return } - if b.Action == 0 || b.Action == 2 { - tmp2 := math.Float32bits(b.Health) - tmp[0] = byte(tmp2 >> 24) - tmp[1] = byte(tmp2 >> 16) - tmp[2] = byte(tmp2 >> 8) - tmp[3] = byte(tmp2 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } + tmp[0] = byte(e.Z >> 24) + tmp[1] = byte(e.Z >> 16) + tmp[2] = byte(e.Z >> 8) + tmp[3] = byte(e.Z >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { + return } - if b.Action == 0 || b.Action == 4 { - if err = WriteVarInt(ww, b.Color); err != nil { - return - } - if err = WriteVarInt(ww, b.Style); err != nil { - return - } + tmp[0] = byte(e.Yaw >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return } - if b.Action == 0 || b.Action == 5 { - tmp[0] = byte(b.Flags >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } + tmp[0] = byte(e.Pitch >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + if err = WriteBool(ww, e.OnGround); err != nil { + return } return } -func (b *BossBar) read(rr io.Reader) (err error) { +func (e *EntityTeleport) read(rr io.Reader) (err error) { var tmp [4]byte - if err = b.UUID.Deserialize(rr); err != nil { + if e.EntityID, err = ReadVarInt(rr); err != nil { return } - if b.Action, err = ReadVarInt(rr); err != nil { + if _, err = rr.Read(tmp[:4]); err != nil { return } - if b.Action == 0 || b.Action == 3 { - var tmp0 string - if tmp0, err = ReadString(rr); err != nil { - return err + e.X = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:4]); err != nil { + return + } + e.Y = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:4]); err != nil { + return + } + e.Z = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + e.Yaw = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + e.Pitch = int8((uint8(tmp[0]) << 0)) + if e.OnGround, err = ReadBool(rr); err != nil { + return + } + return +} + +func (e *EntityProperties) id() int { return 73 } +func (e *EntityProperties) write(ww io.Writer) (err error) { + var tmp [8]byte + if err = WriteVarInt(ww, e.EntityID); err != nil { + return + } + tmp[0] = byte(int32(len(e.Properties)) >> 24) + tmp[1] = byte(int32(len(e.Properties)) >> 16) + tmp[2] = byte(int32(len(e.Properties)) >> 8) + tmp[3] = byte(int32(len(e.Properties)) >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { + return + } + for tmp0 := range e.Properties { + if err = WriteString(ww, e.Properties[tmp0].Key); err != nil { + return } - if err = json.Unmarshal([]byte(tmp0), &b.Title); err != nil { + tmp1 := math.Float64bits(e.Properties[tmp0].Value) + tmp[0] = byte(tmp1 >> 56) + tmp[1] = byte(tmp1 >> 48) + tmp[2] = byte(tmp1 >> 40) + tmp[3] = byte(tmp1 >> 32) + tmp[4] = byte(tmp1 >> 24) + tmp[5] = byte(tmp1 >> 16) + tmp[6] = byte(tmp1 >> 8) + tmp[7] = byte(tmp1 >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } - } - if b.Action == 0 || b.Action == 2 { - var tmp1 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + if err = WriteVarInt(ww, VarInt(len(e.Properties[tmp0].Modifiers))); err != nil { return } - tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - b.Health = math.Float32frombits(tmp1) + for tmp2 := range e.Properties[tmp0].Modifiers { + if err = e.Properties[tmp0].Modifiers[tmp2].UUID.Serialize(ww); err != nil { + return + } + tmp3 := math.Float64bits(e.Properties[tmp0].Modifiers[tmp2].Amount) + tmp[0] = byte(tmp3 >> 56) + tmp[1] = byte(tmp3 >> 48) + tmp[2] = byte(tmp3 >> 40) + tmp[3] = byte(tmp3 >> 32) + tmp[4] = byte(tmp3 >> 24) + tmp[5] = byte(tmp3 >> 16) + tmp[6] = byte(tmp3 >> 8) + tmp[7] = byte(tmp3 >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { + return + } + tmp[0] = byte(e.Properties[tmp0].Modifiers[tmp2].Operation >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + } } - if b.Action == 0 || b.Action == 4 { - if b.Color, err = ReadVarInt(rr); err != nil { + return +} +func (e *EntityProperties) read(rr io.Reader) (err error) { + var tmp [8]byte + if e.EntityID, err = ReadVarInt(rr); err != nil { + return + } + var tmp0 int32 + if _, err = rr.Read(tmp[:4]); err != nil { + return + } + tmp0 = int32((uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24)) + if tmp0 > math.MaxInt16 { + return fmt.Errorf("array larger than max value: %d > %d", tmp0, math.MaxInt16) + } + if tmp0 < 0 { + return fmt.Errorf("negative array size: %d < 0", tmp0) + } + e.Properties = make([]EntityProperty, tmp0) + for tmp1 := range e.Properties { + if e.Properties[tmp1].Key, err = ReadString(rr); err != nil { return } - if b.Style, err = ReadVarInt(rr); err != nil { + var tmp2 uint64 + if _, err = rr.Read(tmp[:8]); err != nil { return } - } - if b.Action == 0 || b.Action == 5 { - if _, err = rr.Read(tmp[:1]); err != nil { + tmp2 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) + e.Properties[tmp1].Value = math.Float64frombits(tmp2) + var tmp3 VarInt + if tmp3, err = ReadVarInt(rr); err != nil { return } - b.Flags = (byte(tmp[0]) << 0) + if tmp3 > math.MaxInt16 { + return fmt.Errorf("array larger than max value: %d > %d", tmp3, math.MaxInt16) + } + if tmp3 < 0 { + return fmt.Errorf("negative array size: %d < 0", tmp3) + } + e.Properties[tmp1].Modifiers = make([]PropertyModifier, tmp3) + for tmp4 := range e.Properties[tmp1].Modifiers { + if err = e.Properties[tmp1].Modifiers[tmp4].UUID.Deserialize(rr); err != nil { + return + } + var tmp5 uint64 + if _, err = rr.Read(tmp[:8]); err != nil { + return + } + tmp5 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) + e.Properties[tmp1].Modifiers[tmp4].Amount = math.Float64frombits(tmp5) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + e.Properties[tmp1].Modifiers[tmp4].Operation = int8((uint8(tmp[0]) << 0)) + } } return } -func (s *SetCooldown) id() int { return 74 } -func (s *SetCooldown) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, s.ItemID); err != nil { +func (e *EntityEffect) id() int { return 74 } +func (e *EntityEffect) write(ww io.Writer) (err error) { + var tmp [1]byte + if err = WriteVarInt(ww, e.EntityID); err != nil { return } - if err = WriteVarInt(ww, s.Ticks); err != nil { + tmp[0] = byte(e.EffectID >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp[0] = byte(e.Amplifier >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + if err = WriteVarInt(ww, e.Duration); err != nil { + return + } + if err = WriteBool(ww, e.HideParticles); err != nil { return } return } -func (s *SetCooldown) read(rr io.Reader) (err error) { - if s.ItemID, err = ReadVarInt(rr); err != nil { +func (e *EntityEffect) read(rr io.Reader) (err error) { + var tmp [1]byte + if e.EntityID, err = ReadVarInt(rr); err != nil { return } - if s.Ticks, err = ReadVarInt(rr); err != nil { + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + e.EffectID = int8((uint8(tmp[0]) << 0)) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + e.Amplifier = int8((uint8(tmp[0]) << 0)) + if e.Duration, err = ReadVarInt(rr); err != nil { + return + } + if e.HideParticles, err = ReadBool(rr); err != nil { return } return } func init() { - packetCreator[Play][clientbound][0] = func() Packet { return &KeepAliveClientbound{} } - packetCreator[Play][clientbound][1] = func() Packet { return &JoinGame{} } - packetCreator[Play][clientbound][2] = func() Packet { return &ServerMessage{} } - packetCreator[Play][clientbound][3] = func() Packet { return &TimeUpdate{} } - packetCreator[Play][clientbound][4] = func() Packet { return &EntityEquipment{} } - packetCreator[Play][clientbound][5] = func() Packet { return &SpawnPosition{} } - packetCreator[Play][clientbound][6] = func() Packet { return &UpdateHealth{} } - packetCreator[Play][clientbound][7] = func() Packet { return &Respawn{} } - packetCreator[Play][clientbound][8] = func() Packet { return &TeleportPlayer{} } - packetCreator[Play][clientbound][9] = func() Packet { return &SetCurrentHotbarSlot{} } - packetCreator[Play][clientbound][10] = func() Packet { return &EntityUsedBed{} } - packetCreator[Play][clientbound][11] = func() Packet { return &Animation{} } - packetCreator[Play][clientbound][12] = func() Packet { return &SpawnPlayer{} } - packetCreator[Play][clientbound][13] = func() Packet { return &CollectItem{} } - packetCreator[Play][clientbound][14] = func() Packet { return &SpawnObject{} } - packetCreator[Play][clientbound][15] = func() Packet { return &SpawnMob{} } - packetCreator[Play][clientbound][16] = func() Packet { return &SpawnPainting{} } - packetCreator[Play][clientbound][17] = func() Packet { return &SpawnExperienceOrb{} } - packetCreator[Play][clientbound][18] = func() Packet { return &EntityVelocity{} } - packetCreator[Play][clientbound][19] = func() Packet { return &EntityDestroy{} } - packetCreator[Play][clientbound][20] = func() Packet { return &Entity{} } - packetCreator[Play][clientbound][21] = func() Packet { return &EntityMove{} } - packetCreator[Play][clientbound][22] = func() Packet { return &EntityLook{} } - packetCreator[Play][clientbound][23] = func() Packet { return &EntityLookAndMove{} } - packetCreator[Play][clientbound][24] = func() Packet { return &EntityTeleport{} } - packetCreator[Play][clientbound][25] = func() Packet { return &EntityHeadLook{} } + packetCreator[Play][clientbound][0] = func() Packet { return &SpawnObject{} } + packetCreator[Play][clientbound][1] = func() Packet { return &SpawnExperienceOrb{} } + packetCreator[Play][clientbound][2] = func() Packet { return &SpawnGlobalEntity{} } + packetCreator[Play][clientbound][3] = func() Packet { return &SpawnMob{} } + packetCreator[Play][clientbound][4] = func() Packet { return &SpawnPainting{} } + packetCreator[Play][clientbound][5] = func() Packet { return &SpawnPlayer{} } + packetCreator[Play][clientbound][6] = func() Packet { return &Animation{} } + packetCreator[Play][clientbound][7] = func() Packet { return &Statistics{} } + packetCreator[Play][clientbound][8] = func() Packet { return &BlockBreakAnimation{} } + packetCreator[Play][clientbound][9] = func() Packet { return &UpdateBlockEntity{} } + packetCreator[Play][clientbound][10] = func() Packet { return &BlockAction{} } + packetCreator[Play][clientbound][11] = func() Packet { return &BlockChange{} } + packetCreator[Play][clientbound][12] = func() Packet { return &BossBar{} } + packetCreator[Play][clientbound][13] = func() Packet { return &ServerDifficulty{} } + packetCreator[Play][clientbound][14] = func() Packet { return &TabCompleteReply{} } + packetCreator[Play][clientbound][15] = func() Packet { return &ServerMessage{} } + packetCreator[Play][clientbound][16] = func() Packet { return &MultiBlockChange{} } + packetCreator[Play][clientbound][17] = func() Packet { return &ConfirmTransaction{} } + packetCreator[Play][clientbound][18] = func() Packet { return &WindowClose{} } + packetCreator[Play][clientbound][19] = func() Packet { return &WindowOpen{} } + packetCreator[Play][clientbound][20] = func() Packet { return &WindowItems{} } + packetCreator[Play][clientbound][21] = func() Packet { return &WindowProperty{} } + packetCreator[Play][clientbound][22] = func() Packet { return &WindowSetSlot{} } + packetCreator[Play][clientbound][23] = func() Packet { return &SetCooldown{} } + packetCreator[Play][clientbound][24] = func() Packet { return &PluginMessageClientbound{} } + packetCreator[Play][clientbound][25] = func() Packet { return &Disconnect{} } packetCreator[Play][clientbound][26] = func() Packet { return &EntityAction{} } - packetCreator[Play][clientbound][27] = func() Packet { return &EntityAttach{} } - packetCreator[Play][clientbound][28] = func() Packet { return &EntityMetadata{} } - packetCreator[Play][clientbound][29] = func() Packet { return &EntityEffect{} } - packetCreator[Play][clientbound][30] = func() Packet { return &EntityRemoveEffect{} } - packetCreator[Play][clientbound][31] = func() Packet { return &SetExperience{} } - packetCreator[Play][clientbound][32] = func() Packet { return &EntityProperties{} } - packetCreator[Play][clientbound][33] = func() Packet { return &ChunkData{} } - packetCreator[Play][clientbound][34] = func() Packet { return &ChunkUnload{} } - packetCreator[Play][clientbound][35] = func() Packet { return &MultiBlockChange{} } - packetCreator[Play][clientbound][36] = func() Packet { return &BlockChange{} } - packetCreator[Play][clientbound][37] = func() Packet { return &BlockAction{} } - packetCreator[Play][clientbound][38] = func() Packet { return &BlockBreakAnimation{} } - packetCreator[Play][clientbound][39] = func() Packet { return &Explosion{} } - packetCreator[Play][clientbound][40] = func() Packet { return &Effect{} } - packetCreator[Play][clientbound][41] = func() Packet { return &SoundEffect{} } - packetCreator[Play][clientbound][42] = func() Packet { return &Particle{} } - packetCreator[Play][clientbound][43] = func() Packet { return &ChangeGameState{} } - packetCreator[Play][clientbound][44] = func() Packet { return &SpawnGlobalEntity{} } - packetCreator[Play][clientbound][45] = func() Packet { return &WindowOpen{} } - packetCreator[Play][clientbound][46] = func() Packet { return &WindowClose{} } - packetCreator[Play][clientbound][47] = func() Packet { return &WindowSetSlot{} } - packetCreator[Play][clientbound][48] = func() Packet { return &WindowItems{} } - packetCreator[Play][clientbound][49] = func() Packet { return &WindowProperty{} } - packetCreator[Play][clientbound][50] = func() Packet { return &ConfirmTransaction{} } - packetCreator[Play][clientbound][51] = func() Packet { return &UpdateSign{} } - packetCreator[Play][clientbound][52] = func() Packet { return &Maps{} } - packetCreator[Play][clientbound][53] = func() Packet { return &UpdateBlockEntity{} } - packetCreator[Play][clientbound][54] = func() Packet { return &SignEditorOpen{} } - packetCreator[Play][clientbound][55] = func() Packet { return &Statistics{} } - packetCreator[Play][clientbound][56] = func() Packet { return &PlayerInfo{} } - packetCreator[Play][clientbound][57] = func() Packet { return &PlayerAbilities{} } - packetCreator[Play][clientbound][58] = func() Packet { return &TabCompleteReply{} } - packetCreator[Play][clientbound][59] = func() Packet { return &ScoreboardObjective{} } - packetCreator[Play][clientbound][60] = func() Packet { return &UpdateScore{} } - packetCreator[Play][clientbound][61] = func() Packet { return &ScoreboardDisplay{} } - packetCreator[Play][clientbound][62] = func() Packet { return &Teams{} } - packetCreator[Play][clientbound][63] = func() Packet { return &PluginMessageClientbound{} } - packetCreator[Play][clientbound][64] = func() Packet { return &Disconnect{} } - packetCreator[Play][clientbound][65] = func() Packet { return &ServerDifficulty{} } - packetCreator[Play][clientbound][66] = func() Packet { return &CombatEvent{} } - packetCreator[Play][clientbound][67] = func() Packet { return &Camera{} } - packetCreator[Play][clientbound][68] = func() Packet { return &WorldBorder{} } - packetCreator[Play][clientbound][69] = func() Packet { return &Title{} } - packetCreator[Play][clientbound][70] = func() Packet { return &SetCompression{} } - packetCreator[Play][clientbound][71] = func() Packet { return &PlayerListHeaderFooter{} } - packetCreator[Play][clientbound][72] = func() Packet { return &ResourcePackSend{} } - packetCreator[Play][clientbound][73] = func() Packet { return &BossBar{} } - packetCreator[Play][clientbound][74] = func() Packet { return &SetCooldown{} } + packetCreator[Play][clientbound][27] = func() Packet { return &Explosion{} } + packetCreator[Play][clientbound][28] = func() Packet { return &ChunkUnload{} } + packetCreator[Play][clientbound][29] = func() Packet { return &SetCompression{} } + packetCreator[Play][clientbound][30] = func() Packet { return &ChangeGameState{} } + packetCreator[Play][clientbound][31] = func() Packet { return &KeepAliveClientbound{} } + packetCreator[Play][clientbound][32] = func() Packet { return &ChunkData{} } + packetCreator[Play][clientbound][33] = func() Packet { return &Effect{} } + packetCreator[Play][clientbound][34] = func() Packet { return &Particle{} } + packetCreator[Play][clientbound][35] = func() Packet { return &SoundEffect{} } + packetCreator[Play][clientbound][36] = func() Packet { return &JoinGame{} } + packetCreator[Play][clientbound][37] = func() Packet { return &Maps{} } + packetCreator[Play][clientbound][38] = func() Packet { return &EntityMove{} } + packetCreator[Play][clientbound][39] = func() Packet { return &EntityLookAndMove{} } + packetCreator[Play][clientbound][40] = func() Packet { return &EntityLook{} } + packetCreator[Play][clientbound][41] = func() Packet { return &Entity{} } + packetCreator[Play][clientbound][42] = func() Packet { return &SignEditorOpen{} } + packetCreator[Play][clientbound][43] = func() Packet { return &PlayerAbilities{} } + packetCreator[Play][clientbound][44] = func() Packet { return &CombatEvent{} } + packetCreator[Play][clientbound][45] = func() Packet { return &PlayerInfo{} } + packetCreator[Play][clientbound][46] = func() Packet { return &TeleportPlayer{} } + packetCreator[Play][clientbound][47] = func() Packet { return &EntityUsedBed{} } + packetCreator[Play][clientbound][48] = func() Packet { return &EntityDestroy{} } + packetCreator[Play][clientbound][49] = func() Packet { return &EntityRemoveEffect{} } + packetCreator[Play][clientbound][50] = func() Packet { return &ResourcePackSend{} } + packetCreator[Play][clientbound][51] = func() Packet { return &Respawn{} } + packetCreator[Play][clientbound][52] = func() Packet { return &EntityHeadLook{} } + packetCreator[Play][clientbound][53] = func() Packet { return &WorldBorder{} } + packetCreator[Play][clientbound][54] = func() Packet { return &Camera{} } + packetCreator[Play][clientbound][55] = func() Packet { return &SetCurrentHotbarSlot{} } + packetCreator[Play][clientbound][56] = func() Packet { return &ScoreboardDisplay{} } + packetCreator[Play][clientbound][57] = func() Packet { return &EntityMetadata{} } + packetCreator[Play][clientbound][58] = func() Packet { return &EntityAttach{} } + packetCreator[Play][clientbound][59] = func() Packet { return &EntityVelocity{} } + packetCreator[Play][clientbound][60] = func() Packet { return &EntityEquipment{} } + packetCreator[Play][clientbound][61] = func() Packet { return &SetExperience{} } + packetCreator[Play][clientbound][62] = func() Packet { return &UpdateHealth{} } + packetCreator[Play][clientbound][63] = func() Packet { return &ScoreboardObjective{} } + packetCreator[Play][clientbound][64] = func() Packet { return &Teams{} } + packetCreator[Play][clientbound][65] = func() Packet { return &UpdateScore{} } + packetCreator[Play][clientbound][66] = func() Packet { return &SpawnPosition{} } + packetCreator[Play][clientbound][67] = func() Packet { return &TimeUpdate{} } + packetCreator[Play][clientbound][68] = func() Packet { return &Title{} } + packetCreator[Play][clientbound][69] = func() Packet { return &UpdateSign{} } + packetCreator[Play][clientbound][70] = func() Packet { return &PlayerListHeaderFooter{} } + packetCreator[Play][clientbound][71] = func() Packet { return &CollectItem{} } + packetCreator[Play][clientbound][72] = func() Packet { return &EntityTeleport{} } + packetCreator[Play][clientbound][73] = func() Packet { return &EntityProperties{} } + packetCreator[Play][clientbound][74] = func() Packet { return &EntityEffect{} } } diff --git a/protocol/play_serverbound.go b/protocol/play_serverbound.go index 6db9a89..87b7b95 100644 --- a/protocol/play_serverbound.go +++ b/protocol/play_serverbound.go @@ -16,13 +16,14 @@ package protocol -// KeepAliveServerbound is sent by a client as a response to a -// KeepAliveClientbound. If the client doesn't reply the server -// may disconnect the client. +// TabComplete is sent by the client when the client presses tab in +// the chat box. // // This is a Minecraft packet -type KeepAliveServerbound struct { - ID VarInt +type TabComplete struct { + Text string + HasTarget bool + Target Position `if:".HasTarget==true"` } // ChatMessage is sent by the client when it sends a chat message or @@ -33,6 +34,71 @@ type ChatMessage struct { Message string } +// ClientStatus is sent to update the client's status +// +// This is a Minecraft packet +type ClientStatus struct { + ActionID VarInt +} + +// ClientSettings is sent by the client to update its current settings. +// +// This is a Minecraft packet +type ClientSettings struct { + Locale string + ViewDistance byte + ChatMode byte + ChatColors bool + DisplayedSkinParts byte + MainHand VarInt +} + +// ConfirmTransactionServerbound is a reply to ConfirmTransaction. +// +// This is a Minecraft packet +type ConfirmTransactionServerbound struct { + ID byte + ActionNumber int16 + Accepted bool +} + +// EnchantItem is sent when the client enchants an item. +// +// This is a Minecraft packet +type EnchantItem struct { + ID byte + Enchantment byte +} + +// ClickWindow is sent when the client clicks in a window. +// +// This is a Minecraft packet +type ClickWindow struct { + ID byte + Slot int16 + Button byte + ActionNumber int16 + Mode byte + ClickedItem ItemStack `as:"raw"` +} + +// CloseWindow is sent when the client closes a window. +// +// This is a Minecraft packet +type CloseWindow struct { + ID byte +} + +// PluginMessageServerbound is used for custom messages between the client +// and server. This is mainly for plugins/mods but vanilla has a few channels +// registered too. +// +// This is a Minecraft packet +type PluginMessageServerbound struct { + Channel string + Data []byte `length:"remaining"` +} + // UseEntity is sent when the user interacts (right clicks) or attacks // (left clicks) an entity. // @@ -46,11 +112,13 @@ type UseEntity struct { Hand VarInt `if:".Type==0 .Type==2"` } -// Player is used to update whether the player is on the ground or not. +// KeepAliveServerbound is sent by a client as a response to a +// KeepAliveClientbound. If the client doesn't reply the server +// may disconnect the client. // // This is a Minecraft packet -type Player struct { - OnGround bool +type KeepAliveServerbound struct { + ID VarInt } // PlayerPosition is used to update the player's position. @@ -61,14 +129,6 @@ type PlayerPosition struct { OnGround bool } -// PlayerLook is used to update the player's rotation. -// -// This is a Minecraft packet -type PlayerLook struct { - Yaw, Pitch float32 - OnGround bool -} - // PlayerPositionLook is a combination of PlayerPosition and // PlayerLook. // @@ -79,52 +139,44 @@ type PlayerPositionLook struct { OnGround bool } -// PlayerDigging is sent when the client starts/stops digging a block. -// It also can be sent for droppping items and eating/shooting. +// PlayerLook is used to update the player's rotation. // // This is a Minecraft packet -type PlayerDigging struct { - Status byte - Location Position - Face byte +type PlayerLook struct { + Yaw, Pitch float32 + OnGround bool } -// UseItem is sent when the client tries to use an item. +// Player is used to update whether the player is on the ground or not. // // This is a Minecraft packet -type UseItem struct { - Hand VarInt +type Player struct { + OnGround bool } -// PlayerBlockPlacement is sent when the client tries to place a block. +// ClientAbilities is used to modify the players current abilities. +// Currently flying is the only one // // This is a Minecraft packet -type PlayerBlockPlacement struct { - Location Position - Face VarInt - Hand VarInt - CursorX, CursorY, CursorZ byte +type ClientAbilities struct { + Flags byte + FlyingSpeed float32 + WalkingSpeed float32 } -// HeldItemChange is sent when the player changes the currently active -// hotbar slot. +// PlayerDigging is sent when the client starts/stops digging a block. +// It also can be sent for droppping items and eating/shooting. // // This is a Minecraft packet -type HeldItemChange struct { - Slot int16 -} - -// ArmSwing is sent by the client when the player left clicks (to swing their -// arm). -// -// This is a Minecraft packetA -type ArmSwing struct { - Hand VarInt +type PlayerDigging struct { + Status byte + Location Position + Face byte } // PlayerAction is sent when a player preforms various actions. // -// This is a Minecraft packetB +// This is a Minecraft packet type PlayerAction struct { EntityID VarInt ActionID VarInt @@ -134,39 +186,26 @@ type PlayerAction struct { // SteerVehicle is sent by the client when steers or preforms an action // on a vehicle. // -// This is a Minecraft packetC +// This is a Minecraft packet type SteerVehicle struct { Sideways float32 Forward float32 Flags byte } -// CloseWindow is sent when the client closes a window. -// -// This is a Minecraft packetD -type CloseWindow struct { - ID byte -} - -// ClickWindow is sent when the client clicks in a window. -// -// This is a Minecraft packetE -type ClickWindow struct { - ID byte - Slot int16 - Button byte - ActionNumber int16 - Mode byte - ClickedItem ItemStack `as:"raw"` +// ResourcePackStatus informs the server of the client's current progress +// in activating the requested resource pack +type ResourcePackStatus struct { + Hash string + Result VarInt } -// ConfirmTransactionServerbound is a reply to ConfirmTransaction. +// HeldItemChange is sent when the player changes the currently active +// hotbar slot. // -// This is a Minecraft packetF -type ConfirmTransactionServerbound struct { - ID byte - ActionNumber int16 - Accepted bool +// This is a Minecraft packet +type HeldItemChange struct { + Slot int16 } // CreativeInventoryAction is sent when the client clicks in the creative @@ -178,14 +217,6 @@ type CreativeInventoryAction struct { ClickedItem ItemStack `as:"raw"` } -// EnchantItem is sent when the client enchants an item. -// -// This is a Minecraft packet -type EnchantItem struct { - ID byte - Enchantment byte -} - // SetSign sets the text on a sign after placing it. // // This is a Minecraft packet @@ -197,65 +228,34 @@ type SetSign struct { Line4 string } -// ClientAbilities is used to modify the players current abilities. -// Currently flying is the only one -// -// This is a Minecraft packet -type ClientAbilities struct { - Flags byte - FlyingSpeed float32 - WalkingSpeed float32 -} - -// TabComplete is sent by the client when the client presses tab in -// the chat box. -// -// This is a Minecraft packet -type TabComplete struct { - Text string - HasTarget bool - Target Position `if:".HasTarget==true"` -} - -// ClientSettings is sent by the client to update its current settings. +// ArmSwing is sent by the client when the player left clicks (to swing their +// arm). // // This is a Minecraft packet -type ClientSettings struct { - Locale string - ViewDistance byte - ChatMode byte - ChatColors bool - DisplayedSkinParts byte - MainHand VarInt +type ArmSwing struct { + Hand VarInt } -// ClientStatus is sent to update the client's status +// SpectateTeleport is sent by clients in spectator mode to teleport to a player. // // This is a Minecraft packet -type ClientStatus struct { - ActionID VarInt +type SpectateTeleport struct { + Target UUID `as:"raw"` } -// PluginMessageServerbound is used for custom messages between the client -// and server. This is mainly for plugins/mods but vanilla has a few channels -// registered too. +// UseItem is sent when the client tries to use an item. // // This is a Minecraft packet -type PluginMessageServerbound struct { - Channel string - Data []byte `length:"remaining"` +type UseItem struct { + Hand VarInt } -// SpectateTeleport is sent by clients in spectator mode to teleport to a player. +// PlayerBlockPlacement is sent when the client tries to place a block. // // This is a Minecraft packet -type SpectateTeleport struct { - Target UUID `as:"raw"` -} - -// ResourcePackStatus informs the server of the client's current progress -// in activating the requested resource pack -type ResourcePackStatus struct { - Hash string - Result VarInt +type PlayerBlockPlacement struct { + Location Position + Face VarInt + Hand VarInt + CursorX, CursorY, CursorZ byte } diff --git a/protocol/play_serverbound_proto.go b/protocol/play_serverbound_proto.go index 229d369..781bda5 100644 --- a/protocol/play_serverbound_proto.go +++ b/protocol/play_serverbound_proto.go @@ -9,17 +9,44 @@ import ( "math" ) -func (k *KeepAliveServerbound) id() int { return 0 } -func (k *KeepAliveServerbound) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, k.ID); err != nil { +func (t *TabComplete) id() int { return 0 } +func (t *TabComplete) write(ww io.Writer) (err error) { + var tmp [8]byte + if err = WriteString(ww, t.Text); err != nil { return } + if err = WriteBool(ww, t.HasTarget); err != nil { + return + } + if t.HasTarget == true { + tmp[0] = byte(t.Target >> 56) + tmp[1] = byte(t.Target >> 48) + tmp[2] = byte(t.Target >> 40) + tmp[3] = byte(t.Target >> 32) + tmp[4] = byte(t.Target >> 24) + tmp[5] = byte(t.Target >> 16) + tmp[6] = byte(t.Target >> 8) + tmp[7] = byte(t.Target >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { + return + } + } return } -func (k *KeepAliveServerbound) read(rr io.Reader) (err error) { - if k.ID, err = ReadVarInt(rr); err != nil { +func (t *TabComplete) read(rr io.Reader) (err error) { + var tmp [8]byte + if t.Text, err = ReadString(rr); err != nil { return } + if t.HasTarget, err = ReadBool(rr); err != nil { + return + } + if t.HasTarget == true { + if _, err = rr.Read(tmp[:8]); err != nil { + return + } + t.Target = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) + } return } @@ -37,7 +64,228 @@ func (c *ChatMessage) read(rr io.Reader) (err error) { return } -func (u *UseEntity) id() int { return 2 } +func (c *ClientStatus) id() int { return 2 } +func (c *ClientStatus) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, c.ActionID); err != nil { + return + } + return +} +func (c *ClientStatus) read(rr io.Reader) (err error) { + if c.ActionID, err = ReadVarInt(rr); err != nil { + return + } + return +} + +func (c *ClientSettings) id() int { return 3 } +func (c *ClientSettings) write(ww io.Writer) (err error) { + var tmp [1]byte + if err = WriteString(ww, c.Locale); err != nil { + return + } + tmp[0] = byte(c.ViewDistance >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp[0] = byte(c.ChatMode >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + if err = WriteBool(ww, c.ChatColors); err != nil { + return + } + tmp[0] = byte(c.DisplayedSkinParts >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + if err = WriteVarInt(ww, c.MainHand); err != nil { + return + } + return +} +func (c *ClientSettings) read(rr io.Reader) (err error) { + var tmp [1]byte + if c.Locale, err = ReadString(rr); err != nil { + return + } + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + c.ViewDistance = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + c.ChatMode = (byte(tmp[0]) << 0) + if c.ChatColors, err = ReadBool(rr); err != nil { + return + } + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + c.DisplayedSkinParts = (byte(tmp[0]) << 0) + if c.MainHand, err = ReadVarInt(rr); err != nil { + return + } + return +} + +func (c *ConfirmTransactionServerbound) id() int { return 4 } +func (c *ConfirmTransactionServerbound) write(ww io.Writer) (err error) { + var tmp [2]byte + tmp[0] = byte(c.ID >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp[0] = byte(c.ActionNumber >> 8) + tmp[1] = byte(c.ActionNumber >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { + return + } + if err = WriteBool(ww, c.Accepted); err != nil { + return + } + return +} +func (c *ConfirmTransactionServerbound) read(rr io.Reader) (err error) { + var tmp [2]byte + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + c.ID = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:2]); err != nil { + return + } + c.ActionNumber = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + if c.Accepted, err = ReadBool(rr); err != nil { + return + } + return +} + +func (e *EnchantItem) id() int { return 5 } +func (e *EnchantItem) write(ww io.Writer) (err error) { + var tmp [1]byte + tmp[0] = byte(e.ID >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp[0] = byte(e.Enchantment >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + return +} +func (e *EnchantItem) read(rr io.Reader) (err error) { + var tmp [1]byte + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + e.ID = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + e.Enchantment = (byte(tmp[0]) << 0) + return +} + +func (c *ClickWindow) id() int { return 6 } +func (c *ClickWindow) write(ww io.Writer) (err error) { + var tmp [2]byte + tmp[0] = byte(c.ID >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp[0] = byte(c.Slot >> 8) + tmp[1] = byte(c.Slot >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { + return + } + tmp[0] = byte(c.Button >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + tmp[0] = byte(c.ActionNumber >> 8) + tmp[1] = byte(c.ActionNumber >> 0) + if _, err = ww.Write(tmp[:2]); err != nil { + return + } + tmp[0] = byte(c.Mode >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + if err = c.ClickedItem.Serialize(ww); err != nil { + return + } + return +} +func (c *ClickWindow) read(rr io.Reader) (err error) { + var tmp [2]byte + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + c.ID = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:2]); err != nil { + return + } + c.Slot = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + c.Button = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:2]); err != nil { + return + } + c.ActionNumber = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + c.Mode = (byte(tmp[0]) << 0) + if err = c.ClickedItem.Deserialize(rr); err != nil { + return + } + return +} + +func (c *CloseWindow) id() int { return 7 } +func (c *CloseWindow) write(ww io.Writer) (err error) { + var tmp [1]byte + tmp[0] = byte(c.ID >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { + return + } + return +} +func (c *CloseWindow) read(rr io.Reader) (err error) { + var tmp [1]byte + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + c.ID = (byte(tmp[0]) << 0) + return +} + +func (p *PluginMessageServerbound) id() int { return 8 } +func (p *PluginMessageServerbound) write(ww io.Writer) (err error) { + if err = WriteString(ww, p.Channel); err != nil { + return + } + if _, err = ww.Write(p.Data); err != nil { + return + } + return +} +func (p *PluginMessageServerbound) read(rr io.Reader) (err error) { + if p.Channel, err = ReadString(rr); err != nil { + return + } + if p.Data, err = ioutil.ReadAll(rr); err != nil { + return + } + return +} + +func (u *UseEntity) id() int { return 9 } func (u *UseEntity) write(ww io.Writer) (err error) { var tmp [4]byte if err = WriteVarInt(ww, u.TargetID); err != nil { @@ -115,21 +363,21 @@ func (u *UseEntity) read(rr io.Reader) (err error) { return } -func (p *Player) id() int { return 3 } -func (p *Player) write(ww io.Writer) (err error) { - if err = WriteBool(ww, p.OnGround); err != nil { +func (k *KeepAliveServerbound) id() int { return 10 } +func (k *KeepAliveServerbound) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, k.ID); err != nil { return } return } -func (p *Player) read(rr io.Reader) (err error) { - if p.OnGround, err = ReadBool(rr); err != nil { +func (k *KeepAliveServerbound) read(rr io.Reader) (err error) { + if k.ID, err = ReadVarInt(rr); err != nil { return } return } -func (p *PlayerPosition) id() int { return 4 } +func (p *PlayerPosition) id() int { return 11 } func (p *PlayerPosition) write(ww io.Writer) (err error) { var tmp [8]byte tmp0 := math.Float64bits(p.X) @@ -179,71 +427,27 @@ func (p *PlayerPosition) read(rr io.Reader) (err error) { if _, err = rr.Read(tmp[:8]); err != nil { return } - tmp0 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) - p.X = math.Float64frombits(tmp0) - var tmp1 uint64 - if _, err = rr.Read(tmp[:8]); err != nil { - return - } - tmp1 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) - p.Y = math.Float64frombits(tmp1) - var tmp2 uint64 - if _, err = rr.Read(tmp[:8]); err != nil { - return - } - tmp2 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) - p.Z = math.Float64frombits(tmp2) - if p.OnGround, err = ReadBool(rr); err != nil { - return - } - return -} - -func (p *PlayerLook) id() int { return 5 } -func (p *PlayerLook) write(ww io.Writer) (err error) { - var tmp [4]byte - tmp0 := math.Float32bits(p.Yaw) - tmp[0] = byte(tmp0 >> 24) - tmp[1] = byte(tmp0 >> 16) - tmp[2] = byte(tmp0 >> 8) - tmp[3] = byte(tmp0 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - tmp1 := math.Float32bits(p.Pitch) - tmp[0] = byte(tmp1 >> 24) - tmp[1] = byte(tmp1 >> 16) - tmp[2] = byte(tmp1 >> 8) - tmp[3] = byte(tmp1 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - if err = WriteBool(ww, p.OnGround); err != nil { - return - } - return -} -func (p *PlayerLook) read(rr io.Reader) (err error) { - var tmp [4]byte - var tmp0 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { - return - } - tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - p.Yaw = math.Float32frombits(tmp0) - var tmp1 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { + tmp0 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) + p.X = math.Float64frombits(tmp0) + var tmp1 uint64 + if _, err = rr.Read(tmp[:8]); err != nil { return } - tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - p.Pitch = math.Float32frombits(tmp1) + tmp1 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) + p.Y = math.Float64frombits(tmp1) + var tmp2 uint64 + if _, err = rr.Read(tmp[:8]); err != nil { + return + } + tmp2 = (uint64(tmp[7]) << 0) | (uint64(tmp[6]) << 8) | (uint64(tmp[5]) << 16) | (uint64(tmp[4]) << 24) | (uint64(tmp[3]) << 32) | (uint64(tmp[2]) << 40) | (uint64(tmp[1]) << 48) | (uint64(tmp[0]) << 56) + p.Z = math.Float64frombits(tmp2) if p.OnGround, err = ReadBool(rr); err != nil { return } return } -func (p *PlayerPositionLook) id() int { return 6 } +func (p *PlayerPositionLook) id() int { return 12 } func (p *PlayerPositionLook) write(ww io.Writer) (err error) { var tmp [8]byte tmp0 := math.Float64bits(p.X) @@ -341,156 +545,152 @@ func (p *PlayerPositionLook) read(rr io.Reader) (err error) { return } -func (p *PlayerDigging) id() int { return 7 } -func (p *PlayerDigging) write(ww io.Writer) (err error) { - var tmp [8]byte - tmp[0] = byte(p.Status >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { +func (p *PlayerLook) id() int { return 13 } +func (p *PlayerLook) write(ww io.Writer) (err error) { + var tmp [4]byte + tmp0 := math.Float32bits(p.Yaw) + tmp[0] = byte(tmp0 >> 24) + tmp[1] = byte(tmp0 >> 16) + tmp[2] = byte(tmp0 >> 8) + tmp[3] = byte(tmp0 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp[0] = byte(p.Location >> 56) - tmp[1] = byte(p.Location >> 48) - tmp[2] = byte(p.Location >> 40) - tmp[3] = byte(p.Location >> 32) - tmp[4] = byte(p.Location >> 24) - tmp[5] = byte(p.Location >> 16) - tmp[6] = byte(p.Location >> 8) - tmp[7] = byte(p.Location >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { + tmp1 := math.Float32bits(p.Pitch) + tmp[0] = byte(tmp1 >> 24) + tmp[1] = byte(tmp1 >> 16) + tmp[2] = byte(tmp1 >> 8) + tmp[3] = byte(tmp1 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp[0] = byte(p.Face >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + if err = WriteBool(ww, p.OnGround); err != nil { return } return } -func (p *PlayerDigging) read(rr io.Reader) (err error) { - var tmp [8]byte - if _, err = rr.Read(tmp[:1]); err != nil { +func (p *PlayerLook) read(rr io.Reader) (err error) { + var tmp [4]byte + var tmp0 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - p.Status = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:8]); err != nil { + tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + p.Yaw = math.Float32frombits(tmp0) + var tmp1 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - p.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) - if _, err = rr.Read(tmp[:1]); err != nil { + tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + p.Pitch = math.Float32frombits(tmp1) + if p.OnGround, err = ReadBool(rr); err != nil { return } - p.Face = (byte(tmp[0]) << 0) return } -func (u *UseItem) id() int { return 8 } -func (u *UseItem) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, u.Hand); err != nil { +func (p *Player) id() int { return 14 } +func (p *Player) write(ww io.Writer) (err error) { + if err = WriteBool(ww, p.OnGround); err != nil { return } return } -func (u *UseItem) read(rr io.Reader) (err error) { - if u.Hand, err = ReadVarInt(rr); err != nil { +func (p *Player) read(rr io.Reader) (err error) { + if p.OnGround, err = ReadBool(rr); err != nil { return } return } -func (p *PlayerBlockPlacement) id() int { return 9 } -func (p *PlayerBlockPlacement) write(ww io.Writer) (err error) { - var tmp [8]byte - tmp[0] = byte(p.Location >> 56) - tmp[1] = byte(p.Location >> 48) - tmp[2] = byte(p.Location >> 40) - tmp[3] = byte(p.Location >> 32) - tmp[4] = byte(p.Location >> 24) - tmp[5] = byte(p.Location >> 16) - tmp[6] = byte(p.Location >> 8) - tmp[7] = byte(p.Location >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { - return - } - if err = WriteVarInt(ww, p.Face); err != nil { - return - } - if err = WriteVarInt(ww, p.Hand); err != nil { - return - } - tmp[0] = byte(p.CursorX >> 0) +func (c *ClientAbilities) id() int { return 15 } +func (c *ClientAbilities) write(ww io.Writer) (err error) { + var tmp [4]byte + tmp[0] = byte(c.Flags >> 0) if _, err = ww.Write(tmp[:1]); err != nil { return } - tmp[0] = byte(p.CursorY >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + tmp0 := math.Float32bits(c.FlyingSpeed) + tmp[0] = byte(tmp0 >> 24) + tmp[1] = byte(tmp0 >> 16) + tmp[2] = byte(tmp0 >> 8) + tmp[3] = byte(tmp0 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } - tmp[0] = byte(p.CursorZ >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + tmp1 := math.Float32bits(c.WalkingSpeed) + tmp[0] = byte(tmp1 >> 24) + tmp[1] = byte(tmp1 >> 16) + tmp[2] = byte(tmp1 >> 8) + tmp[3] = byte(tmp1 >> 0) + if _, err = ww.Write(tmp[:4]); err != nil { return } return } -func (p *PlayerBlockPlacement) read(rr io.Reader) (err error) { - var tmp [8]byte - if _, err = rr.Read(tmp[:8]); err != nil { - return - } - p.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) - if p.Face, err = ReadVarInt(rr); err != nil { - return - } - if p.Hand, err = ReadVarInt(rr); err != nil { - return - } +func (c *ClientAbilities) read(rr io.Reader) (err error) { + var tmp [4]byte if _, err = rr.Read(tmp[:1]); err != nil { return } - p.CursorX = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:1]); err != nil { + c.Flags = (byte(tmp[0]) << 0) + var tmp0 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - p.CursorY = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:1]); err != nil { + tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + c.FlyingSpeed = math.Float32frombits(tmp0) + var tmp1 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - p.CursorZ = (byte(tmp[0]) << 0) + tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + c.WalkingSpeed = math.Float32frombits(tmp1) return } -func (h *HeldItemChange) id() int { return 10 } -func (h *HeldItemChange) write(ww io.Writer) (err error) { - var tmp [2]byte - tmp[0] = byte(h.Slot >> 8) - tmp[1] = byte(h.Slot >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { +func (p *PlayerDigging) id() int { return 16 } +func (p *PlayerDigging) write(ww io.Writer) (err error) { + var tmp [8]byte + tmp[0] = byte(p.Status >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - return -} -func (h *HeldItemChange) read(rr io.Reader) (err error) { - var tmp [2]byte - if _, err = rr.Read(tmp[:2]); err != nil { + tmp[0] = byte(p.Location >> 56) + tmp[1] = byte(p.Location >> 48) + tmp[2] = byte(p.Location >> 40) + tmp[3] = byte(p.Location >> 32) + tmp[4] = byte(p.Location >> 24) + tmp[5] = byte(p.Location >> 16) + tmp[6] = byte(p.Location >> 8) + tmp[7] = byte(p.Location >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } - h.Slot = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) - return -} - -func (a *ArmSwing) id() int { return 11 } -func (a *ArmSwing) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, a.Hand); err != nil { + tmp[0] = byte(p.Face >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } return } -func (a *ArmSwing) read(rr io.Reader) (err error) { - if a.Hand, err = ReadVarInt(rr); err != nil { +func (p *PlayerDigging) read(rr io.Reader) (err error) { + var tmp [8]byte + if _, err = rr.Read(tmp[:1]); err != nil { + return + } + p.Status = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:8]); err != nil { + return + } + p.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) + if _, err = rr.Read(tmp[:1]); err != nil { return } + p.Face = (byte(tmp[0]) << 0) return } -func (p *PlayerAction) id() int { return 12 } +func (p *PlayerAction) id() int { return 17 } func (p *PlayerAction) write(ww io.Writer) (err error) { if err = WriteVarInt(ww, p.EntityID); err != nil { return @@ -516,7 +716,7 @@ func (p *PlayerAction) read(rr io.Reader) (err error) { return } -func (s *SteerVehicle) id() int { return 13 } +func (s *SteerVehicle) id() int { return 18 } func (s *SteerVehicle) write(ww io.Writer) (err error) { var tmp [4]byte tmp0 := math.Float32bits(s.Sideways) @@ -532,146 +732,56 @@ func (s *SteerVehicle) write(ww io.Writer) (err error) { tmp[1] = byte(tmp1 >> 16) tmp[2] = byte(tmp1 >> 8) tmp[3] = byte(tmp1 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - tmp[0] = byte(s.Flags >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - return -} -func (s *SteerVehicle) read(rr io.Reader) (err error) { - var tmp [4]byte - var tmp0 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { - return - } - tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - s.Sideways = math.Float32frombits(tmp0) - var tmp1 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { - return - } - tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - s.Forward = math.Float32frombits(tmp1) - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - s.Flags = (byte(tmp[0]) << 0) - return -} - -func (c *CloseWindow) id() int { return 14 } -func (c *CloseWindow) write(ww io.Writer) (err error) { - var tmp [1]byte - tmp[0] = byte(c.ID >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - return -} -func (c *CloseWindow) read(rr io.Reader) (err error) { - var tmp [1]byte - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - c.ID = (byte(tmp[0]) << 0) - return -} - -func (c *ClickWindow) id() int { return 15 } -func (c *ClickWindow) write(ww io.Writer) (err error) { - var tmp [2]byte - tmp[0] = byte(c.ID >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp[0] = byte(c.Slot >> 8) - tmp[1] = byte(c.Slot >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { - return - } - tmp[0] = byte(c.Button >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp[0] = byte(c.ActionNumber >> 8) - tmp[1] = byte(c.ActionNumber >> 0) - if _, err = ww.Write(tmp[:2]); err != nil { - return - } - tmp[0] = byte(c.Mode >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { + if _, err = ww.Write(tmp[:4]); err != nil { return } - if err = c.ClickedItem.Serialize(ww); err != nil { + tmp[0] = byte(s.Flags >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } return } -func (c *ClickWindow) read(rr io.Reader) (err error) { - var tmp [2]byte - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - c.ID = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:2]); err != nil { - return - } - c.Slot = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) - if _, err = rr.Read(tmp[:1]); err != nil { +func (s *SteerVehicle) read(rr io.Reader) (err error) { + var tmp [4]byte + var tmp0 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - c.Button = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:2]); err != nil { + tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + s.Sideways = math.Float32frombits(tmp0) + var tmp1 uint32 + if _, err = rr.Read(tmp[:4]); err != nil { return } - c.ActionNumber = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) + tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) + s.Forward = math.Float32frombits(tmp1) if _, err = rr.Read(tmp[:1]); err != nil { return } - c.Mode = (byte(tmp[0]) << 0) - if err = c.ClickedItem.Deserialize(rr); err != nil { - return - } + s.Flags = (byte(tmp[0]) << 0) return } -func (c *ConfirmTransactionServerbound) id() int { return 16 } -func (c *ConfirmTransactionServerbound) write(ww io.Writer) (err error) { +func (h *HeldItemChange) id() int { return 19 } +func (h *HeldItemChange) write(ww io.Writer) (err error) { var tmp [2]byte - tmp[0] = byte(c.ID >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp[0] = byte(c.ActionNumber >> 8) - tmp[1] = byte(c.ActionNumber >> 0) + tmp[0] = byte(h.Slot >> 8) + tmp[1] = byte(h.Slot >> 0) if _, err = ww.Write(tmp[:2]); err != nil { return } - if err = WriteBool(ww, c.Accepted); err != nil { - return - } return } -func (c *ConfirmTransactionServerbound) read(rr io.Reader) (err error) { +func (h *HeldItemChange) read(rr io.Reader) (err error) { var tmp [2]byte - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - c.ID = (byte(tmp[0]) << 0) if _, err = rr.Read(tmp[:2]); err != nil { return } - c.ActionNumber = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) - if c.Accepted, err = ReadBool(rr); err != nil { - return - } + h.Slot = int16((uint16(tmp[1]) << 0) | (uint16(tmp[0]) << 8)) return } -func (c *CreativeInventoryAction) id() int { return 17 } +func (c *CreativeInventoryAction) id() int { return 20 } func (c *CreativeInventoryAction) write(ww io.Writer) (err error) { var tmp [2]byte tmp[0] = byte(c.Slot >> 8) @@ -696,33 +806,7 @@ func (c *CreativeInventoryAction) read(rr io.Reader) (err error) { return } -func (e *EnchantItem) id() int { return 18 } -func (e *EnchantItem) write(ww io.Writer) (err error) { - var tmp [1]byte - tmp[0] = byte(e.ID >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp[0] = byte(e.Enchantment >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - return -} -func (e *EnchantItem) read(rr io.Reader) (err error) { - var tmp [1]byte - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - e.ID = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - e.Enchantment = (byte(tmp[0]) << 0) - return -} - -func (s *SetSign) id() int { return 19 } +func (s *SetSign) id() int { return 21 } func (s *SetSign) write(ww io.Writer) (err error) { var tmp [8]byte tmp[0] = byte(s.Location >> 56) @@ -771,218 +855,134 @@ func (s *SetSign) read(rr io.Reader) (err error) { return } -func (c *ClientAbilities) id() int { return 20 } -func (c *ClientAbilities) write(ww io.Writer) (err error) { - var tmp [4]byte - tmp[0] = byte(c.Flags >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp0 := math.Float32bits(c.FlyingSpeed) - tmp[0] = byte(tmp0 >> 24) - tmp[1] = byte(tmp0 >> 16) - tmp[2] = byte(tmp0 >> 8) - tmp[3] = byte(tmp0 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { - return - } - tmp1 := math.Float32bits(c.WalkingSpeed) - tmp[0] = byte(tmp1 >> 24) - tmp[1] = byte(tmp1 >> 16) - tmp[2] = byte(tmp1 >> 8) - tmp[3] = byte(tmp1 >> 0) - if _, err = ww.Write(tmp[:4]); err != nil { +func (a *ArmSwing) id() int { return 22 } +func (a *ArmSwing) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, a.Hand); err != nil { return } return } -func (c *ClientAbilities) read(rr io.Reader) (err error) { - var tmp [4]byte - if _, err = rr.Read(tmp[:1]); err != nil { - return - } - c.Flags = (byte(tmp[0]) << 0) - var tmp0 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { - return - } - tmp0 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - c.FlyingSpeed = math.Float32frombits(tmp0) - var tmp1 uint32 - if _, err = rr.Read(tmp[:4]); err != nil { +func (a *ArmSwing) read(rr io.Reader) (err error) { + if a.Hand, err = ReadVarInt(rr); err != nil { return } - tmp1 = (uint32(tmp[3]) << 0) | (uint32(tmp[2]) << 8) | (uint32(tmp[1]) << 16) | (uint32(tmp[0]) << 24) - c.WalkingSpeed = math.Float32frombits(tmp1) return } -func (t *TabComplete) id() int { return 21 } -func (t *TabComplete) write(ww io.Writer) (err error) { - var tmp [8]byte - if err = WriteString(ww, t.Text); err != nil { - return - } - if err = WriteBool(ww, t.HasTarget); err != nil { +func (s *SpectateTeleport) id() int { return 23 } +func (s *SpectateTeleport) write(ww io.Writer) (err error) { + if err = s.Target.Serialize(ww); err != nil { return } - if t.HasTarget == true { - tmp[0] = byte(t.Target >> 56) - tmp[1] = byte(t.Target >> 48) - tmp[2] = byte(t.Target >> 40) - tmp[3] = byte(t.Target >> 32) - tmp[4] = byte(t.Target >> 24) - tmp[5] = byte(t.Target >> 16) - tmp[6] = byte(t.Target >> 8) - tmp[7] = byte(t.Target >> 0) - if _, err = ww.Write(tmp[:8]); err != nil { - return - } - } return } -func (t *TabComplete) read(rr io.Reader) (err error) { - var tmp [8]byte - if t.Text, err = ReadString(rr); err != nil { - return - } - if t.HasTarget, err = ReadBool(rr); err != nil { +func (s *SpectateTeleport) read(rr io.Reader) (err error) { + if err = s.Target.Deserialize(rr); err != nil { return } - if t.HasTarget == true { - if _, err = rr.Read(tmp[:8]); err != nil { - return - } - t.Target = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) - } return } -func (c *ClientSettings) id() int { return 22 } -func (c *ClientSettings) write(ww io.Writer) (err error) { - var tmp [1]byte - if err = WriteString(ww, c.Locale); err != nil { - return - } - tmp[0] = byte(c.ViewDistance >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - tmp[0] = byte(c.ChatMode >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - if err = WriteBool(ww, c.ChatColors); err != nil { - return - } - tmp[0] = byte(c.DisplayedSkinParts >> 0) - if _, err = ww.Write(tmp[:1]); err != nil { - return - } - if err = WriteVarInt(ww, c.MainHand); err != nil { +func (u *UseItem) id() int { return 24 } +func (u *UseItem) write(ww io.Writer) (err error) { + if err = WriteVarInt(ww, u.Hand); err != nil { return } return } -func (c *ClientSettings) read(rr io.Reader) (err error) { - var tmp [1]byte - if c.Locale, err = ReadString(rr); err != nil { - return - } - if _, err = rr.Read(tmp[:1]); err != nil { +func (u *UseItem) read(rr io.Reader) (err error) { + if u.Hand, err = ReadVarInt(rr); err != nil { return } - c.ViewDistance = (byte(tmp[0]) << 0) - if _, err = rr.Read(tmp[:1]); err != nil { + return +} + +func (p *PlayerBlockPlacement) id() int { return 25 } +func (p *PlayerBlockPlacement) write(ww io.Writer) (err error) { + var tmp [8]byte + tmp[0] = byte(p.Location >> 56) + tmp[1] = byte(p.Location >> 48) + tmp[2] = byte(p.Location >> 40) + tmp[3] = byte(p.Location >> 32) + tmp[4] = byte(p.Location >> 24) + tmp[5] = byte(p.Location >> 16) + tmp[6] = byte(p.Location >> 8) + tmp[7] = byte(p.Location >> 0) + if _, err = ww.Write(tmp[:8]); err != nil { return } - c.ChatMode = (byte(tmp[0]) << 0) - if c.ChatColors, err = ReadBool(rr); err != nil { + if err = WriteVarInt(ww, p.Face); err != nil { return } - if _, err = rr.Read(tmp[:1]); err != nil { + if err = WriteVarInt(ww, p.Hand); err != nil { return } - c.DisplayedSkinParts = (byte(tmp[0]) << 0) - if c.MainHand, err = ReadVarInt(rr); err != nil { + tmp[0] = byte(p.CursorX >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - return -} - -func (c *ClientStatus) id() int { return 23 } -func (c *ClientStatus) write(ww io.Writer) (err error) { - if err = WriteVarInt(ww, c.ActionID); err != nil { + tmp[0] = byte(p.CursorY >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } - return -} -func (c *ClientStatus) read(rr io.Reader) (err error) { - if c.ActionID, err = ReadVarInt(rr); err != nil { + tmp[0] = byte(p.CursorZ >> 0) + if _, err = ww.Write(tmp[:1]); err != nil { return } return } - -func (p *PluginMessageServerbound) id() int { return 24 } -func (p *PluginMessageServerbound) write(ww io.Writer) (err error) { - if err = WriteString(ww, p.Channel); err != nil { +func (p *PlayerBlockPlacement) read(rr io.Reader) (err error) { + var tmp [8]byte + if _, err = rr.Read(tmp[:8]); err != nil { return } - if _, err = ww.Write(p.Data); err != nil { + p.Location = (Position(tmp[7]) << 0) | (Position(tmp[6]) << 8) | (Position(tmp[5]) << 16) | (Position(tmp[4]) << 24) | (Position(tmp[3]) << 32) | (Position(tmp[2]) << 40) | (Position(tmp[1]) << 48) | (Position(tmp[0]) << 56) + if p.Face, err = ReadVarInt(rr); err != nil { return } - return -} -func (p *PluginMessageServerbound) read(rr io.Reader) (err error) { - if p.Channel, err = ReadString(rr); err != nil { + if p.Hand, err = ReadVarInt(rr); err != nil { return } - if p.Data, err = ioutil.ReadAll(rr); err != nil { + if _, err = rr.Read(tmp[:1]); err != nil { return } - return -} - -func (s *SpectateTeleport) id() int { return 25 } -func (s *SpectateTeleport) write(ww io.Writer) (err error) { - if err = s.Target.Serialize(ww); err != nil { + p.CursorX = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:1]); err != nil { return } - return -} -func (s *SpectateTeleport) read(rr io.Reader) (err error) { - if err = s.Target.Deserialize(rr); err != nil { + p.CursorY = (byte(tmp[0]) << 0) + if _, err = rr.Read(tmp[:1]); err != nil { return } + p.CursorZ = (byte(tmp[0]) << 0) return } func init() { - packetCreator[Play][serverbound][0] = func() Packet { return &KeepAliveServerbound{} } + packetCreator[Play][serverbound][0] = func() Packet { return &TabComplete{} } packetCreator[Play][serverbound][1] = func() Packet { return &ChatMessage{} } - packetCreator[Play][serverbound][2] = func() Packet { return &UseEntity{} } - packetCreator[Play][serverbound][3] = func() Packet { return &Player{} } - packetCreator[Play][serverbound][4] = func() Packet { return &PlayerPosition{} } - packetCreator[Play][serverbound][5] = func() Packet { return &PlayerLook{} } - packetCreator[Play][serverbound][6] = func() Packet { return &PlayerPositionLook{} } - packetCreator[Play][serverbound][7] = func() Packet { return &PlayerDigging{} } - packetCreator[Play][serverbound][8] = func() Packet { return &UseItem{} } - packetCreator[Play][serverbound][9] = func() Packet { return &PlayerBlockPlacement{} } - packetCreator[Play][serverbound][10] = func() Packet { return &HeldItemChange{} } - packetCreator[Play][serverbound][11] = func() Packet { return &ArmSwing{} } - packetCreator[Play][serverbound][12] = func() Packet { return &PlayerAction{} } - packetCreator[Play][serverbound][13] = func() Packet { return &SteerVehicle{} } - packetCreator[Play][serverbound][14] = func() Packet { return &CloseWindow{} } - packetCreator[Play][serverbound][15] = func() Packet { return &ClickWindow{} } - packetCreator[Play][serverbound][16] = func() Packet { return &ConfirmTransactionServerbound{} } - packetCreator[Play][serverbound][17] = func() Packet { return &CreativeInventoryAction{} } - packetCreator[Play][serverbound][18] = func() Packet { return &EnchantItem{} } - packetCreator[Play][serverbound][19] = func() Packet { return &SetSign{} } - packetCreator[Play][serverbound][20] = func() Packet { return &ClientAbilities{} } - packetCreator[Play][serverbound][21] = func() Packet { return &TabComplete{} } - packetCreator[Play][serverbound][22] = func() Packet { return &ClientSettings{} } - packetCreator[Play][serverbound][23] = func() Packet { return &ClientStatus{} } - packetCreator[Play][serverbound][24] = func() Packet { return &PluginMessageServerbound{} } - packetCreator[Play][serverbound][25] = func() Packet { return &SpectateTeleport{} } + packetCreator[Play][serverbound][2] = func() Packet { return &ClientStatus{} } + packetCreator[Play][serverbound][3] = func() Packet { return &ClientSettings{} } + packetCreator[Play][serverbound][4] = func() Packet { return &ConfirmTransactionServerbound{} } + packetCreator[Play][serverbound][5] = func() Packet { return &EnchantItem{} } + packetCreator[Play][serverbound][6] = func() Packet { return &ClickWindow{} } + packetCreator[Play][serverbound][7] = func() Packet { return &CloseWindow{} } + packetCreator[Play][serverbound][8] = func() Packet { return &PluginMessageServerbound{} } + packetCreator[Play][serverbound][9] = func() Packet { return &UseEntity{} } + packetCreator[Play][serverbound][10] = func() Packet { return &KeepAliveServerbound{} } + packetCreator[Play][serverbound][11] = func() Packet { return &PlayerPosition{} } + packetCreator[Play][serverbound][12] = func() Packet { return &PlayerPositionLook{} } + packetCreator[Play][serverbound][13] = func() Packet { return &PlayerLook{} } + packetCreator[Play][serverbound][14] = func() Packet { return &Player{} } + packetCreator[Play][serverbound][15] = func() Packet { return &ClientAbilities{} } + packetCreator[Play][serverbound][16] = func() Packet { return &PlayerDigging{} } + packetCreator[Play][serverbound][17] = func() Packet { return &PlayerAction{} } + packetCreator[Play][serverbound][18] = func() Packet { return &SteerVehicle{} } + packetCreator[Play][serverbound][19] = func() Packet { return &HeldItemChange{} } + packetCreator[Play][serverbound][20] = func() Packet { return &CreativeInventoryAction{} } + packetCreator[Play][serverbound][21] = func() Packet { return &SetSign{} } + packetCreator[Play][serverbound][22] = func() Packet { return &ArmSwing{} } + packetCreator[Play][serverbound][23] = func() Packet { return &SpectateTeleport{} } + packetCreator[Play][serverbound][24] = func() Packet { return &UseItem{} } + packetCreator[Play][serverbound][25] = func() Packet { return &PlayerBlockPlacement{} } } diff --git a/protocol/types.go b/protocol/types.go index fe7dd6b..93d9e0a 100644 --- a/protocol/types.go +++ b/protocol/types.go @@ -43,7 +43,7 @@ const ( const ( // SupportedProtocolVersion is current protocol version this package defines - SupportedProtocolVersion = 65 + SupportedProtocolVersion = 69 ) const ( diff --git a/resource/resource.go b/resource/resource.go index 7449fee..5abdbde 100644 --- a/resource/resource.go +++ b/resource/resource.go @@ -31,7 +31,7 @@ import ( ) const ( - ResourcesVersion = "15w35d" + ResourcesVersion = "15w36c" vanillaURL = "https://s3.amazonaws.com/Minecraft.Download/versions/%[1]s/%[1]s.jar" )