Skip to content

Commit

Permalink
minecraft/protocol: Update to support 1.20.50
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Dec 8, 2023
1 parent 2b48a19 commit 14c3da7
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 63 deletions.
3 changes: 3 additions & 0 deletions minecraft/protocol/container.go
Expand Up @@ -63,6 +63,7 @@ const (
ContainerCursor
ContainerCreatedOutput
ContainerSmithingTableTemplate
ContainerCrafterLevelEntity
)

const (
Expand Down Expand Up @@ -102,4 +103,6 @@ const (
ContainerTypeJigsawEditor
ContainerTypeSmithingTable
ContainerTypeChestBoat
ContainerTypeDecoratedPot
ContainerTypeCrafter
)
4 changes: 2 additions & 2 deletions minecraft/protocol/info.go
Expand Up @@ -2,7 +2,7 @@ package protocol

const (
// CurrentProtocol is the current protocol version for the version below.
CurrentProtocol = 622
CurrentProtocol = 630
// CurrentVersion is the current version of Minecraft as supported by the `packet` package.
CurrentVersion = "1.20.40"
CurrentVersion = "1.20.50"
)
4 changes: 2 additions & 2 deletions minecraft/protocol/packet/compression.go
Expand Up @@ -54,7 +54,7 @@ var (

// EncodeCompression ...
func (flateCompression) EncodeCompression() uint16 {
return 0
return CompressionAlgorithmFlate
}

// Compress ...
Expand Down Expand Up @@ -103,7 +103,7 @@ func (flateCompression) Decompress(compressed []byte) ([]byte, error) {

// EncodeCompression ...
func (snappyCompression) EncodeCompression() uint16 {
return 1
return CompressionAlgorithmSnappy
}

// Compress ...
Expand Down
38 changes: 0 additions & 38 deletions minecraft/protocol/packet/crafting_event.go

This file was deleted.

4 changes: 3 additions & 1 deletion minecraft/protocol/packet/id.go
Expand Up @@ -53,7 +53,7 @@ const (
IDInventorySlot
IDContainerSetData
IDCraftingData
IDCraftingEvent
_
IDGUIDataPickItem
IDAdventureSettings
IDBlockActorData
Expand Down Expand Up @@ -206,4 +206,6 @@ const (
IDOpenSign
IDAgentAnimation
IDRefreshEntitlements
IDPlayerToggleCrafterSlotRequest
IDSetPlayerInventoryOptions
)
2 changes: 2 additions & 0 deletions minecraft/protocol/packet/level_event.go
Expand Up @@ -86,6 +86,7 @@ const (
LevelEventSculkCharge = 2037
LevelEventSculkChargePop = 2038
LevelEventSonicExplosion = 2039
LevelEventDustPlume = 2040
LevelEventStartRaining = 3001
LevelEventStartThunderstorm = 3002
LevelEventStopRaining = 3003
Expand Down Expand Up @@ -118,6 +119,7 @@ const (
LevelEventParticlesCrackBlockSouth = 3606
LevelEventParticlesCrackBlockWest = 3607
LevelEventParticlesCrackBlockEast = 3608
LevelEventParticlesShootWhiteSmoke = 3609
LevelEventAllPlayersSleeping = 9800
LevelEventSleepingPlayers = 9801
LevelEventJumpPrevented = 9810
Expand Down
7 changes: 7 additions & 0 deletions minecraft/protocol/packet/level_sound_event.go
Expand Up @@ -486,6 +486,13 @@ const (
SoundEventAmbientUnderwaterExit
SoundEventBottleFill
SoundEventBottleEmpty
SoundEventCrafterCraft
SoundEventCrafterFail
SoundEventDecoratedPotInsert
SoundEventDecoratedPotInsertFail
SoundEventCrafterDisableSlot
SoundEventCopperBulbTurnOn
SoundEventCopperBulbTurnOff
)

// LevelSoundEvent is sent by the server to make any kind of built-in sound heard to a player. It is sent to,
Expand Down
6 changes: 6 additions & 0 deletions minecraft/protocol/packet/network_settings.go
Expand Up @@ -4,6 +4,12 @@ import (
"github.com/sandertv/gophertunnel/minecraft/protocol"
)

const (
CompressionAlgorithmFlate = iota
CompressionAlgorithmSnappy
CompressionAlgorithmNone = 0xffff
)

// NetworkSettings is sent by the server to update a variety of network settings. These settings modify the
// way packets are sent over the network stack.
type NetworkSettings struct {
Expand Down
32 changes: 32 additions & 0 deletions minecraft/protocol/packet/player_toggle_crafter_slot_request.go
@@ -0,0 +1,32 @@
package packet

import (
"github.com/sandertv/gophertunnel/minecraft/protocol"
)

// PlayerToggleCrafterSlotRequest is sent by the client when it tries to toggle the state of a slot within a Crafter.
type PlayerToggleCrafterSlotRequest struct {
// PosX is the X position of the Crafter that is being modified.
PosX int32
// PosY is the Y position of the Crafter that is being modified.
PosY int32
// PosZ is the Z position of the Crafter that is being modified.
PosZ int32
// Slot is the index of the slot that was toggled. This should be a value between 0 and 8.
Slot byte
// Disabled is the new state of the slot. If true, the slot is disabled, if false, the slot is enabled.
Disabled bool
}

// ID ...
func (*PlayerToggleCrafterSlotRequest) ID() uint32 {
return IDPlayerToggleCrafterSlotRequest
}

func (pk *PlayerToggleCrafterSlotRequest) Marshal(io protocol.IO) {
io.Int32(&pk.PosX)
io.Int32(&pk.PosY)
io.Int32(&pk.PosZ)
io.Uint8(&pk.Slot)
io.Bool(&pk.Disabled)
}
18 changes: 10 additions & 8 deletions minecraft/protocol/packet/pool.go
Expand Up @@ -98,7 +98,6 @@ func init() {
IDInventorySlot: func() Packet { return &InventorySlot{} },
IDContainerSetData: func() Packet { return &ContainerSetData{} },
IDCraftingData: func() Packet { return &CraftingData{} },
IDCraftingEvent: func() Packet { return &CraftingEvent{} },
IDGUIDataPickItem: func() Packet { return &GUIDataPickItem{} },
IDAdventureSettings: func() Packet { return &AdventureSettings{} },
IDBlockActorData: func() Packet { return &BlockActorData{} },
Expand Down Expand Up @@ -245,12 +244,14 @@ func init() {
IDCameraPresets: func() Packet { return &CameraPresets{} },
IDUnlockedRecipes: func() Packet { return &UnlockedRecipes{} },
// ---
IDCameraInstruction: func() Packet { return &CameraInstruction{} },
IDCompressedBiomeDefinitionList: func() Packet { return &CompressedBiomeDefinitionList{} },
IDTrimData: func() Packet { return &TrimData{} },
IDOpenSign: func() Packet { return &OpenSign{} },
IDAgentAnimation: func() Packet { return &AgentAnimation{} },
IDRefreshEntitlements: func() Packet { return &RefreshEntitlements{} },
IDCameraInstruction: func() Packet { return &CameraInstruction{} },
IDCompressedBiomeDefinitionList: func() Packet { return &CompressedBiomeDefinitionList{} },
IDTrimData: func() Packet { return &TrimData{} },
IDOpenSign: func() Packet { return &OpenSign{} },
IDAgentAnimation: func() Packet { return &AgentAnimation{} },
IDRefreshEntitlements: func() Packet { return &RefreshEntitlements{} },
IDPlayerToggleCrafterSlotRequest: func() Packet { return &PlayerToggleCrafterSlotRequest{} },
IDSetPlayerInventoryOptions: func() Packet { return &SetPlayerInventoryOptions{} },
}
for id, pk := range serverOriginating {
RegisterPacketFromServer(id, pk)
Expand Down Expand Up @@ -279,7 +280,6 @@ func init() {
IDRespawn: func() Packet { return &Respawn{} },
IDContainerOpen: func() Packet { return &ContainerOpen{} },
IDContainerClose: func() Packet { return &ContainerClose{} },
IDCraftingEvent: func() Packet { return &CraftingEvent{} },
IDAdventureSettings: func() Packet { return &AdventureSettings{} },
IDPlayerInput: func() Packet { return &PlayerInput{} },
IDSetPlayerGameType: func() Packet { return &SetPlayerGameType{} },
Expand Down Expand Up @@ -333,6 +333,8 @@ func init() {
IDGameTestResults: func() Packet { return &GameTestResults{} },
IDOpenSign: func() Packet { return &OpenSign{} },
IDBlockActorData: func() Packet { return &BlockActorData{} },
IDPlayerToggleCrafterSlotRequest: func() Packet { return &PlayerToggleCrafterSlotRequest{} },
IDSetPlayerInventoryOptions: func() Packet { return &SetPlayerInventoryOptions{} },
}
for id, pk := range clientOriginating {
RegisterPacketFromClient(id, pk)
Expand Down
58 changes: 58 additions & 0 deletions minecraft/protocol/packet/set_player_inventory_options.go
@@ -0,0 +1,58 @@
package packet

import (
"github.com/sandertv/gophertunnel/minecraft/protocol"
)

const (
InventoryLayoutNone = iota
InventoryLayoutSurvival
InventoryLayoutRecipeBook
InventoryLayoutCreative
)

const (
InventoryLeftTabNone = iota
InventoryLeftTabConstruction
InventoryLeftTabEquipment
InventoryLeftTabItems
InventoryLeftTabNature
InventoryLeftTabSearch
InventoryLeftTabSurvival
)

const (
InventoryRightTabNone = iota
InventoryRightTabFullScreen
InventoryRightTabCrafting
InventoryRightTabArmour
)

// SetPlayerInventoryOptions is sent by the client when it tries to toggle the state of a slot within a Crafter.
type SetPlayerInventoryOptions struct {
// LeftInventoryTab is the tab that is selected on the left side of the inventory. This is usually for the creative
// inventory. It is one of the constants above.
LeftInventoryTab byte
// RightInventoryTab is the tab that is selected on the right side of the inventory. This is usually for the player's
// own inventory. It is one of the constants above.
RightInventoryTab byte
// Filtering is whether the player has enabled the filtering between recipes they have unlocked or not.
Filtering bool
// InventoryLayout is the layout of the inventory. It is one of the constants above.
InventoryLayout byte
// CraftingLayout is the layout of the crafting inventory. It is one of the constants above.
CraftingLayout byte
}

// ID ...
func (*SetPlayerInventoryOptions) ID() uint32 {
return IDSetPlayerInventoryOptions
}

func (pk *SetPlayerInventoryOptions) Marshal(io protocol.IO) {
io.Uint8(&pk.LeftInventoryTab)
io.Uint8(&pk.RightInventoryTab)
io.Bool(&pk.Filtering)
io.Uint8(&pk.InventoryLayout)
io.Uint8(&pk.CraftingLayout)
}
18 changes: 12 additions & 6 deletions minecraft/protocol/packet/show_store_offer.go
Expand Up @@ -4,19 +4,25 @@ import (
"github.com/sandertv/gophertunnel/minecraft/protocol"
)

const (
StoreOfferTypeMarketplace = iota
StoreOfferTypeDressingRoom
StoreOfferTypeServerPage
)

// ShowStoreOffer is sent by the server to show a Marketplace store offer to a player. It opens a window
// client-side that displays the item.
// The ShowStoreOffer packet only works on the partnered servers: Servers that are not partnered will not have
// a store buttons show up in the in-game pause menu and will, as a result, not be able to open store offers
// on the client side. Sending the packet does therefore not work when using a proxy that is not connected to
// with the domain of one of the partnered servers.
type ShowStoreOffer struct {
// OfferID is a string that identifies the offer for which a window should be opened. While typically a
// UUID, the ID could be anything.
// OfferID is a string that identifies the offer for which a window should be opened. ID should be in the format of
// a UUID, however it can be left empty if StoreOfferTypeServerPage is used.
OfferID string
// ShowAll specifies if all other offers of the same 'author' as the one of the offer associated with the
// OfferID should also be displayed, alongside the target offer.
ShowAll bool
// Type is the type of the store offer that is being shown to the player. It is one of the constants that may be
// found above.
Type byte
}

// ID ...
Expand All @@ -26,5 +32,5 @@ func (*ShowStoreOffer) ID() uint32 {

func (pk *ShowStoreOffer) Marshal(io protocol.IO) {
io.String(&pk.OfferID)
io.Bool(&pk.ShowAll)
io.Uint8(&pk.Type)
}
9 changes: 3 additions & 6 deletions minecraft/protocol/recipe.go
Expand Up @@ -149,8 +149,7 @@ type ShapelessRecipe struct {
Input []ItemDescriptorCount
// Output is a list of items that are created as a result of crafting the recipe.
Output []ItemStack
// UUID is a UUID identifying the recipe. This can actually be set to an empty UUID if the CraftingEvent
// packet is not used.
// UUID is a UUID identifying the recipe. Since the CraftingEvent packet no longer exists, this can always be empty.
UUID uuid.UUID
// Block is the block name that is required to craft the output of the recipe. The block is not prefixed
// with 'minecraft:', so it will look like 'crafting_table' as an example.
Expand Down Expand Up @@ -199,8 +198,7 @@ type ShapedRecipe struct {
Input []ItemDescriptorCount
// Output is a list of items that are created as a result of crafting the recipe.
Output []ItemStack
// UUID is a UUID identifying the recipe. This can actually be set to an empty UUID if the CraftingEvent
// packet is not used.
// UUID is a UUID identifying the recipe. Since the CraftingEvent packet no longer exists, this can always be empty.
UUID uuid.UUID
// Block is the block name that is required to craft the output of the recipe. The block is not prefixed
// with 'minecraft:', so it will look like 'crafting_table' as an example.
Expand Down Expand Up @@ -240,8 +238,7 @@ type FurnaceDataRecipe struct {

// MultiRecipe serves as an 'enable' switch for multi-shape recipes.
type MultiRecipe struct {
// UUID is a UUID identifying the recipe. This can actually be set to an empty UUID if the CraftingEvent
// packet is not used.
// UUID is a UUID identifying the recipe. Since the CraftingEvent packet no longer exists, this can always be empty.
UUID uuid.UUID
// RecipeNetworkID is a unique ID used to identify the recipe over network. Each recipe must have a unique
// network ID. Recommended is to just increment a variable for each unique recipe registered.
Expand Down

0 comments on commit 14c3da7

Please sign in to comment.