Skip to content

Commit

Permalink
minecraft/protocol: Update to support 1.20.80
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Apr 27, 2024
1 parent d2d1a1f commit 2fcfd73
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 10 deletions.
2 changes: 2 additions & 0 deletions minecraft/conn.go
Expand Up @@ -1046,6 +1046,7 @@ func (conn *Conn) startGame() {
LANBroadcastEnabled: true,
PlayerMovementSettings: data.PlayerMovementSettings,
WorldGameMode: data.WorldGameMode,
Hardcore: data.Hardcore,
ServerAuthoritativeInventory: data.ServerAuthoritativeInventory,
PlayerPermissions: data.PlayerPermissions,
Experiments: data.Experiments,
Expand Down Expand Up @@ -1238,6 +1239,7 @@ func (conn *Conn) handleStartGame(pk *packet.StartGame) error {
Items: pk.Items,
PlayerMovementSettings: pk.PlayerMovementSettings,
WorldGameMode: pk.WorldGameMode,
Hardcore: pk.Hardcore,
ServerAuthoritativeInventory: pk.ServerAuthoritativeInventory,
PlayerPermissions: pk.PlayerPermissions,
ChatRestrictionLevel: pk.ChatRestrictionLevel,
Expand Down
2 changes: 2 additions & 0 deletions minecraft/game_data.go
Expand Up @@ -65,6 +65,8 @@ type GameData struct {
// WorldGameMode is the game mode that a player gets when it first spawns in the world. It is shown in the
// settings and is used if the PlayerGameMode is set to 5.
WorldGameMode int32
// Hardcore is if the world is in hardcore mode. In hardcore mode, the player cannot respawn after dying.
Hardcore bool
// GameRules defines game rules currently active with their respective values. The value of these game
// rules may be either 'bool', 'int32' or 'float32'. Some game rules are server side only, and don't
// necessarily need to be sent to the client.
Expand Down
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 = 662
CurrentProtocol = 671
// CurrentVersion is the current version of Minecraft as supported by the `packet` package.
CurrentVersion = "1.20.70"
CurrentVersion = "1.20.80"
)
2 changes: 1 addition & 1 deletion minecraft/protocol/packet/client_bound_debug_renderer.go
Expand Up @@ -36,7 +36,7 @@ func (*ClientBoundDebugRenderer) ID() uint32 {
}

func (pk *ClientBoundDebugRenderer) Marshal(io protocol.IO) {
io.Varuint32(&pk.Type)
io.Uint32(&pk.Type)
if pk.Type == ClientBoundDebugRendererAddCube {
io.String(&pk.Text)
io.Vec3(&pk.Position)
Expand Down
12 changes: 9 additions & 3 deletions minecraft/protocol/packet/correct_player_move_prediction.go
Expand Up @@ -14,18 +14,21 @@ const (
// is set to AuthoritativeMovementModeServerWithRewind. The packet is used to correct movement at a specific
// point in time.
type CorrectPlayerMovePrediction struct {
// PredictionType is the type of prediction that was corrected. It is one of the constants above.
PredictionType byte
// Position is the position that the player is supposed to be at the tick written in the field below.
// The client will change its current position based on movement after that tick starting from the
// Position.
Position mgl32.Vec3
// Delta is the change in position compared to what the client sent as its position at that specific tick.
Delta mgl32.Vec3
// Rotation is the rotation of the player at the tick written in the field below. It is only included if
// PredictionType is PredictionTypeVehicle.
Rotation mgl32.Vec2
// OnGround specifies if the player was on the ground at the time of the tick below.
OnGround bool
// Tick is the tick of the movement which was corrected by this packet.
Tick uint64
// PredictionType is the type of prediction that was corrected. It is one of the constants above.
PredictionType byte
}

// ID ...
Expand All @@ -34,9 +37,12 @@ func (*CorrectPlayerMovePrediction) ID() uint32 {
}

func (pk *CorrectPlayerMovePrediction) Marshal(io protocol.IO) {
io.Uint8(&pk.PredictionType)
io.Vec3(&pk.Position)
io.Vec3(&pk.Delta)
if pk.PredictionType == PredictionTypeVehicle {
io.Vec2(&pk.Rotation)
}
io.Bool(&pk.OnGround)
io.Varuint64(&pk.Tick)
io.Uint8(&pk.PredictionType)
}
4 changes: 2 additions & 2 deletions minecraft/protocol/packet/player_auth_input.go
Expand Up @@ -107,7 +107,7 @@ type PlayerAuthInput struct {
PlayMode uint32
// InteractionModel is a constant representing the interaction model the player is using. It is one of the
// constants that may be found above.
InteractionModel int32
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
Expand Down Expand Up @@ -146,7 +146,7 @@ func (pk *PlayerAuthInput) Marshal(io protocol.IO) {
io.Varuint64(&pk.InputData)
io.Varuint32(&pk.InputMode)
io.Varuint32(&pk.PlayMode)
io.Varint32(&pk.InteractionModel)
io.Varuint32(&pk.InteractionModel)
if pk.PlayMode == PlayModeReality {
io.Vec3(&pk.GazeDirection)
}
Expand Down
4 changes: 4 additions & 0 deletions minecraft/protocol/packet/resource_pack_stack.go
Expand Up @@ -27,6 +27,9 @@ type ResourcePackStack struct {
// ExperimentsPreviouslyToggled specifies if any experiments were previously toggled in this world. It is
// probably used for some kind of metrics.
ExperimentsPreviouslyToggled bool
// IncludeEditorPacks specifies if vanilla editor packs should be included in the resource pack stack when
// connecting to an editor world.
IncludeEditorPacks bool
}

// ID ...
Expand All @@ -41,4 +44,5 @@ func (pk *ResourcePackStack) Marshal(io protocol.IO) {
io.String(&pk.BaseGameVersion)
protocol.SliceUint32Length(io, &pk.Experiments)
io.Bool(&pk.ExperimentsPreviouslyToggled)
io.Bool(&pk.IncludeEditorPacks)
}
3 changes: 3 additions & 0 deletions minecraft/protocol/packet/start_game.go
Expand Up @@ -68,6 +68,8 @@ type StartGame struct {
// WorldGameMode is the game mode that a player gets when it first spawns in the world. It is shown in the
// settings and is used if the PlayerGameMode is set to 5.
WorldGameMode int32
// Hardcore is if the world is in hardcore mode. In hardcore mode, the player cannot respawn after dying.
Hardcore bool
// Difficulty is the difficulty of the world. It is a value from 0-3, with 0 being peaceful, 1 being easy,
// 2 being normal and 3 being hard.
Difficulty int32
Expand Down Expand Up @@ -265,6 +267,7 @@ func (pk *StartGame) Marshal(io protocol.IO) {
io.Varint32(&pk.Dimension)
io.Varint32(&pk.Generator)
io.Varint32(&pk.WorldGameMode)
io.Bool(&pk.Hardcore)
io.Varint32(&pk.Difficulty)
io.UBlockPos(&pk.WorldSpawn)
io.Bool(&pk.AchievementsDisabled)
Expand Down
4 changes: 2 additions & 2 deletions minecraft/protocol/packet/update_block_synced.go
Expand Up @@ -28,7 +28,7 @@ type UpdateBlockSynced struct {
// entity transitions from.
// Note that for both possible values for TransitionType, the EntityUniqueID should point to the falling
// block entity involved.
EntityUniqueID int64
EntityUniqueID uint64
// TransitionType is the type of the transition that happened. It is either BlockToEntityTransition, when
// a block placed becomes a falling entity, or EntityToBlockTransition, when a falling entity hits the
// ground and becomes a solid block again.
Expand All @@ -45,6 +45,6 @@ func (pk *UpdateBlockSynced) Marshal(io protocol.IO) {
io.Varuint32(&pk.NewBlockRuntimeID)
io.Varuint32(&pk.Flags)
io.Varuint32(&pk.Layer)
io.Varint64(&pk.EntityUniqueID)
io.Varuint64(&pk.EntityUniqueID)
io.Varuint64(&pk.TransitionType)
}
3 changes: 3 additions & 0 deletions minecraft/protocol/packet/update_player_game_type.go
Expand Up @@ -14,6 +14,8 @@ type UpdatePlayerGameType struct {
// PlayerUniqueID is the entity unique ID of the player that should have its game mode updated. If this
// packet is sent to other clients with the player unique ID of another player, nothing happens.
PlayerUniqueID int64
// Tick is the server tick at which the packet was sent. It is used in relation to CorrectPlayerMovePrediction.
Tick uint64
}

// ID ...
Expand All @@ -24,4 +26,5 @@ func (*UpdatePlayerGameType) ID() uint32 {
func (pk *UpdatePlayerGameType) Marshal(io protocol.IO) {
io.Varint32(&pk.GameType)
io.Varint64(&pk.PlayerUniqueID)
io.Varuint64(&pk.Tick)
}
4 changes: 4 additions & 0 deletions minecraft/protocol/recipe.go
Expand Up @@ -205,6 +205,9 @@ type ShapedRecipe struct {
Block string
// Priority ...
Priority int32
// AssumeSymmetry specifies if the recipe is symmetrical. If this is set to true, the recipe will be
// mirrored along the diagonal axis. This means that the recipe will be the same if rotated 180 degrees.
AssumeSymmetry bool
// 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.
// This field must never be 0.
Expand Down Expand Up @@ -436,6 +439,7 @@ func marshalShaped(r IO, recipe *ShapedRecipe) {
r.UUID(&recipe.UUID)
r.String(&recipe.Block)
r.Varint32(&recipe.Priority)
r.Bool(&recipe.AssumeSymmetry)
r.Varuint32(&recipe.RecipeNetworkID)
}

Expand Down

0 comments on commit 2fcfd73

Please sign in to comment.