Skip to content

Commit

Permalink
minecraft/protocol: Support 1.21.40
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Oct 23, 2024
1 parent 1f2f7c7 commit eed76a6
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 27 deletions.
11 changes: 5 additions & 6 deletions minecraft/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,13 +768,12 @@ func (conn *Conn) handleClientToServerHandshake() error {
}
pk := &packet.ResourcePacksInfo{TexturePackRequired: conn.texturePacksRequired}
for _, pack := range conn.resourcePacks {
if pack.DownloadURL() != "" {
pk.PackURLs = append(pk.PackURLs, protocol.PackURL{
UUIDVersion: fmt.Sprintf("%s_%s", pack.UUID(), pack.Version()),
URL: pack.DownloadURL(),
})
texturePack := protocol.TexturePackInfo{
UUID: pack.UUID(),
Version: pack.Version(),
Size: uint64(pack.Len()),
DownloadURL: pack.DownloadURL(),
}
texturePack := protocol.TexturePackInfo{UUID: pack.UUID(), Version: pack.Version(), Size: uint64(pack.Len())}
if pack.Encrypted() {
texturePack.ContentKey = pack.ContentKey()
texturePack.ContentIdentity = pack.Manifest().Header.UUID
Expand Down
9 changes: 9 additions & 0 deletions minecraft/protocol/camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ type CameraPreset struct {
RotationSpeed Optional[float32]
// SnapToTarget determines whether the camera should snap to the target entity or not.
SnapToTarget Optional[bool]
// HorizontalRotationLimit is the horizontal rotation limit of the camera.
HorizontalRotationLimit Optional[mgl32.Vec2]
// VerticalRotationLimit is the vertical rotation limit of the camera.
VerticalRotationLimit Optional[mgl32.Vec2]
// ContinueTargeting determines whether the camera should continue targeting the entity or not.
ContinueTargeting Optional[bool]
// ViewOffset is only used in a follow_orbit camera and controls an offset based on a pivot point to the
// player, causing it to be shifted in a certain direction.
ViewOffset Optional[mgl32.Vec2]
Expand All @@ -169,6 +175,9 @@ type CameraPreset struct {
AudioListener Optional[byte]
// PlayerEffects is currently unknown.
PlayerEffects Optional[bool]
// AlignTargetAndCameraForward determines whether the camera should align the target and the camera forward
// or not.
AlignTargetAndCameraForward Optional[bool]
}

// Marshal encodes/decodes a CameraPreset.
Expand Down
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 = 729
CurrentProtocol = 748
// CurrentVersion is the current version of Minecraft as supported by the `packet` package.
CurrentVersion = "1.21.30"
CurrentVersion = "1.21.40"
)
14 changes: 14 additions & 0 deletions minecraft/protocol/login/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,20 @@ type ClientData struct {
// CompatibleWithClientSideChunkGen is a boolean indicating if the client's hardware is capable of using the client
// side chunk generation system.
CompatibleWithClientSideChunkGen bool
// MaxViewDistance is the highest render distance that the client's hardware can handle.
MaxViewDistance int
// MemoryTier is the tier of memory that the client's hardware has. This is a number between 0 and 5. The
// full calculation of this tier is currently unknown but the following is a rough estimate from a
// developer at Mojang:
// 0 - Undetermined
// 1 - Super Low, less than ~1.5GB of memory
// 2 - Low, less than ~2GB of memory
// 3 - Mid, less than ~4GB of memory
// 4 - High, less than ~8GB of memory
// 5 - Super High, more than ~8GB of memory
MemoryTier int
// PlatformType is the type of platform the client is running.
PlatformType int
}

// PersonaPiece represents a piece of a persona skin. All pieces are sent separately.
Expand Down
2 changes: 2 additions & 0 deletions minecraft/protocol/packet/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,6 @@ const (
IDServerBoundDiagnostics
IDCameraAimAssist
IDContainerRegistryCleanup
IDMovementEffect
IDSetMovementAuthority
)
8 changes: 5 additions & 3 deletions minecraft/protocol/packet/inventory_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ type InventoryContent struct {
Content []protocol.ItemInstance
// Container is the protocol.FullContainerName that describes the container that the content is for.
Container protocol.FullContainerName
// DynamicContainerSize is the size of the container, if the container is dynamic.
DynamicContainerSize uint32
// StorageItem is the item that is acting as the storage container for the inventory. If the inventory is
// not a dynamic container then this field should be left empty. When set, only the item type is used by
// the client and none of the other stack info.
StorageItem protocol.ItemInstance
}

// ID ...
Expand All @@ -29,5 +31,5 @@ func (pk *InventoryContent) Marshal(io protocol.IO) {
io.Varuint32(&pk.WindowID)
protocol.FuncSlice(io, &pk.Content, io.ItemInstance)
protocol.Single(io, &pk.Container)
io.Varuint32(&pk.DynamicContainerSize)
io.ItemInstance(&pk.StorageItem)
}
8 changes: 5 additions & 3 deletions minecraft/protocol/packet/inventory_slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ type InventorySlot struct {
Slot uint32
// Container is the protocol.FullContainerName that describes the container that the content is for.
Container protocol.FullContainerName
// DynamicContainerSize is the size of the container, if the container is dynamic.
DynamicContainerSize uint32
// StorageItem is the item that is acting as the storage container for the inventory. If the inventory is
// not a dynamic container then this field should be left empty. When set, only the item type is used by
// the client and none of the other stack info.
StorageItem protocol.ItemInstance
// NewItem is the item to be put in the slot at Slot. It will overwrite any item that may currently
// be present in that slot.
NewItem protocol.ItemInstance
Expand All @@ -32,6 +34,6 @@ func (pk *InventorySlot) Marshal(io protocol.IO) {
io.Varuint32(&pk.WindowID)
io.Varuint32(&pk.Slot)
protocol.Single(io, &pk.Container)
io.Varuint32(&pk.DynamicContainerSize)
io.ItemInstance(&pk.StorageItem)
io.ItemInstance(&pk.NewItem)
}
2 changes: 1 addition & 1 deletion minecraft/protocol/packet/mob_effect.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ func (pk *MobEffect) Marshal(io protocol.IO) {
io.Varint32(&pk.Amplifier)
io.Bool(&pk.Particles)
io.Varint32(&pk.Duration)
io.Uint64(&pk.Tick)
io.Varuint64(&pk.Tick)
}
36 changes: 36 additions & 0 deletions minecraft/protocol/packet/movement_effect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package packet

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

const (
MovementEffectTypeGlideBoost = iota
)

// MovementEffect is sent by the server to the client to update specific movement effects to allow the client
// to predict its movement. For example, fireworks used during gliding will send this packet to tell the
// client the exact duration of the boost.
type MovementEffect struct {
// EntityRuntimeID is the runtime ID of the entity. The runtime ID is unique for each world session, and
// entities are generally identified in packets using this runtime ID.
EntityRuntimeID uint64
// Type is the type of movement effect being updated. It is one of the constants found above.
Type int32
// Duration is the duration of the effect, measured in ticks.
Duration int32
// Tick is the server tick at which the packet was sent. It is used in relation to CorrectPlayerMovePrediction.
Tick uint64
}

// ID ...
func (*MovementEffect) ID() uint32 {
return IDMovementEffect
}

func (pk *MovementEffect) Marshal(io protocol.IO) {
io.Varuint64(&pk.EntityRuntimeID)
io.Varint32(&pk.Type)
io.Varint32(&pk.Duration)
io.Varuint64(&pk.Tick)
}
18 changes: 12 additions & 6 deletions minecraft/protocol/packet/player_auth_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const (
InputFlagVerticalCollision
InputFlagDownLeft
InputFlagDownRight
InputFlagCameraRelativeMovementEnabled
InputFlagRotControlledByMoveDirection
InputFlagStartSpinAttack
InputFlagStopSpinAttack
)

const (
Expand Down Expand Up @@ -113,9 +117,10 @@ type PlayerAuthInput struct {
// InteractionModel is a constant representing the interaction model the player is using. It is one of the
// constants that may be found above.
InteractionModel uint32
// GazeDirection is the direction in which the player is gazing, when the PlayMode is PlayModeReality: In
// other words, when the player is playing in virtual reality.
GazeDirection mgl32.Vec3
// InteractPitch and interactYaw is the rotation the player is looking that they intend to use for
// interactions. This is only different to Pitch and Yaw in cases such as VR or when custom cameras
// being used.
InteractPitch, InteractYaw float32
// Tick is the server tick at which the packet was sent. It is used in relation to
// CorrectPlayerMovePrediction.
Tick uint64
Expand All @@ -135,6 +140,7 @@ type PlayerAuthInput struct {
// AnalogueMoveVector is a Vec2 that specifies the direction in which the player moved, as a combination
// of X/Z values which are created using an analogue input.
AnalogueMoveVector mgl32.Vec2
CameraOrientation mgl32.Vec3
}

// ID ...
Expand All @@ -152,9 +158,8 @@ func (pk *PlayerAuthInput) Marshal(io protocol.IO) {
io.Varuint32(&pk.InputMode)
io.Varuint32(&pk.PlayMode)
io.Varuint32(&pk.InteractionModel)
if pk.PlayMode == PlayModeReality {
io.Vec3(&pk.GazeDirection)
}
io.Float32(&pk.InteractPitch)
io.Float32(&pk.InteractYaw)
io.Varuint64(&pk.Tick)
io.Vec3(&pk.Delta)

Expand All @@ -176,4 +181,5 @@ func (pk *PlayerAuthInput) Marshal(io protocol.IO) {
}

io.Vec2(&pk.AnalogueMoveVector)
io.Vec3(&pk.CameraOrientation)
}
2 changes: 2 additions & 0 deletions minecraft/protocol/packet/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ func init() {
IDServerBoundDiagnostics: func() Packet { return &ServerBoundDiagnostics{} },
IDCameraAimAssist: func() Packet { return &CameraAimAssist{} },
IDContainerRegistryCleanup: func() Packet { return &ContainerRegistryCleanup{} },
IDMovementEffect: func() Packet { return &MovementEffect{} },
IDSetMovementAuthority: func() Packet { return &SetMovementAuthority{} },
}
for id, pk := range serverOriginating {
RegisterPacketFromServer(id, pk)
Expand Down
4 changes: 0 additions & 4 deletions minecraft/protocol/packet/resource_packs_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ type ResourcePacksInfo struct {
// The order of these texture packs is not relevant in this packet. It is however important in the
// ResourcePackStack packet.
TexturePacks []protocol.TexturePackInfo
// PackURLs is a list of URLs that the client can use to download a resource pack instead of downloading
// it the usual way.
PackURLs []protocol.PackURL
}

// ID ...
Expand All @@ -36,5 +33,4 @@ func (pk *ResourcePacksInfo) Marshal(io protocol.IO) {
io.Bool(&pk.HasAddons)
io.Bool(&pk.HasScripts)
protocol.SliceUint16Length(io, &pk.TexturePacks)
protocol.Slice(io, &pk.PackURLs)
}
24 changes: 24 additions & 0 deletions minecraft/protocol/packet/set_movement_authority.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package packet

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

// SetMovementAuthority is sent by the server to the client to change its movement mode.
type SetMovementAuthority struct {
// MovementType specifies the way the server handles player movement. Available options are
// protocol.PlayerMovementModeClient, protocol.PlayerMovementModeServer and
// protocol.PlayerMovementModeServerWithRewind, where the server authoritative types result
// in the client sending PlayerAuthInput packets instead of MovePlayer packets and the rewind mode
// requires sending the tick of movement and several actions.
MovementType byte
}

// ID ...
func (*SetMovementAuthority) ID() uint32 {
return IDSetMovementAuthority
}

func (pk *SetMovementAuthority) Marshal(io protocol.IO) {
io.Uint8(&pk.MovementType)
}
4 changes: 2 additions & 2 deletions minecraft/protocol/packet/set_player_game_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type SetPlayerGameType struct {
// GameType is the new game type of the player. It is one of the constants that can be found above. Some
// of these game types require additional flags to be set in an AdventureSettings packet for the game mode
// to obtain its full functionality.
GameType int32
GameType int64
}

// ID ...
Expand All @@ -29,5 +29,5 @@ func (*SetPlayerGameType) ID() uint32 {
}

func (pk *SetPlayerGameType) Marshal(io protocol.IO) {
io.Varint32(&pk.GameType)
io.Varint64(&pk.GameType)
}
1 change: 1 addition & 0 deletions minecraft/protocol/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
PlayerActionStartFlying
PlayerActionStopFlying
PlayerActionClientAckServerData
PlayerActionStartUsingItem
)

const (
Expand Down
4 changes: 4 additions & 0 deletions minecraft/protocol/resource_pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ type TexturePackInfo struct {
AddonPack bool
// RTXEnabled specifies if the texture pack uses the raytracing technology introduced in 1.16.200.
RTXEnabled bool
// DownloadURL is a URL that the client can use to download the pack instead of the server sending it in
// chunks, which it will continue to do if this field is left empty.
DownloadURL string
}

// Marshal encodes/decodes a TexturePackInfo.
Expand All @@ -41,6 +44,7 @@ func (x *TexturePackInfo) Marshal(r IO) {
r.Bool(&x.HasScripts)
r.Bool(&x.AddonPack)
r.Bool(&x.RTXEnabled)
r.String(&x.DownloadURL)
}

// StackResourcePack represents a resource pack sent on the stack of the client. When sent, the client will
Expand Down

0 comments on commit eed76a6

Please sign in to comment.