Skip to content

Commit

Permalink
minecraft/protocol: Update to support 1.21.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Jun 14, 2024
1 parent 3c4144b commit 082917e
Show file tree
Hide file tree
Showing 14 changed files with 282 additions and 134 deletions.
20 changes: 20 additions & 0 deletions minecraft/protocol/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const (
EventTypeStriderRiddenInLavaInOverworld
EventTypeSneakCloseToSculkSensor
EventTypeCarefulRestoration
EventTypeItemUsed
)

// lookupEvent looks up an Event matching the event type passed. False is
Expand Down Expand Up @@ -87,6 +88,8 @@ func lookupEvent(eventType int32, x *Event) bool {
*x = &WaxedOrUnwaxedCopperEvent{}
case EventTypeSneakCloseToSculkSensor:
*x = &SneakCloseToSculkSensorEvent{}
case EventTypeItemUsed:
*x = &ItemUsedEvent{}
default:
return false
}
Expand Down Expand Up @@ -144,6 +147,8 @@ func lookupEventType(x Event, eventType *int32) bool {
*eventType = EventTypePlayerWaxedOrUnwaxedCopper
case *SneakCloseToSculkSensorEvent:
*eventType = EventTypeSneakCloseToSculkSensor
case *ItemUsedEvent:
*eventType = EventTypeItemUsed
default:
return false
}
Expand Down Expand Up @@ -567,3 +572,18 @@ type SneakCloseToSculkSensorEvent struct{}

// Marshal ...
func (u *SneakCloseToSculkSensorEvent) Marshal(r IO) {}

type ItemUsedEvent struct {
ItemID int16
ItemAux int32
UseMethod int32
UseCount int32
}

// Marshal ...
func (i *ItemUsedEvent) Marshal(r IO) {
r.Int16(&i.ItemID)
r.Varint32(&i.ItemAux)
r.Varint32(&i.UseMethod)
r.Varint32(&i.UseCount)
}
4 changes: 2 additions & 2 deletions minecraft/protocol/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package protocol

const (
// CurrentProtocol is the current protocol version for the version below.
CurrentProtocol = 671
CurrentProtocol = 685
// CurrentVersion is the current version of Minecraft as supported by the `packet` package.
CurrentVersion = "1.20.80"
CurrentVersion = "1.21.0"
)
21 changes: 21 additions & 0 deletions minecraft/protocol/packet/award_achievement.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package packet

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

// AwardAchievement is sent by the server to award an achievement to a player.
type AwardAchievement struct {
// AchievementID is the ID of the achievement that should be awarded to the player. The values for these
// IDs are currently unknown.
AchievementID int32
}

// ID ...
func (*AwardAchievement) ID() uint32 {
return IDAwardAchievement
}

func (pk *AwardAchievement) Marshal(io protocol.IO) {
io.Int32(&pk.AchievementID)
}
24 changes: 16 additions & 8 deletions minecraft/protocol/packet/code_builder_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@ import (
"github.com/sandertv/gophertunnel/minecraft/protocol"
)

const (
CodeBuilderOperationNone = iota
CodeBuilderOperationGet
CodeBuilderOperationSet
CodeBuilderOperationReset
)

const (
CodeBuilderCategoryNone = iota
CodeBuilderCategoryStatus
CodeBuilderCategoryInstantiation
)

const (
CodeBuilderOperationNone = iota
CodeBuilderOperationGet
CodeBuilderOperationSet
CodeBuilderOperationReset
CodeBuilderStatusNone = iota
CodeBuilderStatusNotStarted
CodeBuilderStatusInProgress
CodeBuilderStatusPaused
CodeBuilderStatusError
CodeBuilderStatusSucceeded
)

// CodeBuilderSource is an Education Edition packet sent by the client to the server to run an operation with a
Expand All @@ -25,9 +34,8 @@ type CodeBuilderSource struct {
// Category is used to distinguish the category of the operation performed. It is always one of the constants
// listed above.
Category byte
// Value contains extra data about the operation performed. It is always empty unless the operation is
// CodeBuilderOperationSet.
Value []byte
// CodeStatus is the status of the code builder. It is always one of the constants listed above.
CodeStatus byte
}

// ID ...
Expand All @@ -38,5 +46,5 @@ func (pk *CodeBuilderSource) ID() uint32 {
func (pk *CodeBuilderSource) Marshal(io protocol.IO) {
io.Uint8(&pk.Operation)
io.Uint8(&pk.Category)
io.ByteSlice(&pk.Value)
io.Uint8(&pk.CodeStatus)
}
2 changes: 2 additions & 0 deletions minecraft/protocol/packet/completed_using_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
UseItemRetrieved
UseItemDyed
UseItemTraded
UseItemBrushingCompleted
UseItemOpenedVault
)

// CompletedUsingItem is sent by the server to tell the client that it should be done using the item it is
Expand Down
4 changes: 4 additions & 0 deletions minecraft/protocol/packet/container_close.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type ContainerClose struct {
// WindowID is the ID representing the window of the container that should be closed. It must be equal to
// the one sent in the ContainerOpen packet to close the designated window.
WindowID byte
// ContainerType is the type of container that the server is trying to close. This is used to validate on
// the client side whether or not the server's close request is valid.
ContainerType byte
// ServerSide determines whether or not the container was force-closed by the server. If this value is
// not set correctly, the client may ignore the packet and respond with a PacketViolationWarning.
ServerSide bool
Expand All @@ -23,5 +26,6 @@ func (*ContainerClose) ID() uint32 {

func (pk *ContainerClose) Marshal(io protocol.IO) {
io.Uint8(&pk.WindowID)
io.Uint8(&pk.ContainerType)
io.Bool(&pk.ServerSide)
}
1 change: 1 addition & 0 deletions minecraft/protocol/packet/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,5 @@ const (
IDPlayerToggleCrafterSlotRequest
IDSetPlayerInventoryOptions
IDSetHud
IDAwardAchievement
)
Loading

0 comments on commit 082917e

Please sign in to comment.