这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions minecraft/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,8 @@ func (conn *Conn) handlePacket(pk packet.Packet) error {
return conn.handleResourcePackStack(pk)
case *packet.StartGame:
return conn.handleStartGame(pk)
case *packet.ItemRegistry:
return conn.handleItemRegistry(pk)
case *packet.ChunkRadiusUpdated:
return conn.handleChunkRadiusUpdated(pk)
}
Expand Down Expand Up @@ -1020,7 +1022,6 @@ func (conn *Conn) startGame() {
GameRules: data.GameRules,
Time: data.Time,
Blocks: data.CustomBlocks,
Items: data.Items,
AchievementsDisabled: true,
Generator: 1,
EducationFeaturesEnabled: true,
Expand All @@ -1042,6 +1043,7 @@ func (conn *Conn) startGame() {
GameVersion: protocol.CurrentVersion,
UseBlockNetworkIDHashes: data.UseBlockNetworkIDHashes,
})
_ = conn.WritePacket(&packet.ItemRegistry{Items: data.Items})
_ = conn.Flush()
conn.expect(packet.IDRequestChunkRadius, packet.IDSetLocalPlayerAsInitialised)
}
Expand Down Expand Up @@ -1221,7 +1223,6 @@ func (conn *Conn) handleStartGame(pk *packet.StartGame) error {
Time: pk.Time,
ServerBlockStateChecksum: pk.ServerBlockStateChecksum,
CustomBlocks: pk.Blocks,
Items: pk.Items,
PlayerMovementSettings: pk.PlayerMovementSettings,
WorldGameMode: pk.WorldGameMode,
Hardcore: pk.Hardcore,
Expand All @@ -1233,6 +1234,14 @@ func (conn *Conn) handleStartGame(pk *packet.StartGame) error {
Experiments: pk.Experiments,
UseBlockNetworkIDHashes: pk.UseBlockNetworkIDHashes,
}
conn.expect(packet.IDItemRegistry)
return nil
}

// handleItemRegistry handles an incoming ItemRegistry packet. It contains the item definitions that the client
// should use, including the shield ID which is necessary for reading and writing items in the future.
func (conn *Conn) handleItemRegistry(pk *packet.ItemRegistry) error {
conn.gameData.Items = pk.Items
for _, item := range pk.Items {
if item.Name == "minecraft:shield" {
conn.shieldID.Store(int32(item.RuntimeID))
Expand Down
11 changes: 8 additions & 3 deletions minecraft/protocol/ability.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
AbilityWorldBuilder
AbilityNoClip
AbilityPrivilegedBuilder
AbilityVerticalFlySpeed
AbilityCount
)

Expand All @@ -33,8 +34,9 @@ const (
)

const (
AbilityBaseFlySpeed = 0.05
AbilityBaseWalkSpeed = 0.1
AbilityBaseFlySpeed = 0.05
AbilityBaseWalkSpeed = 0.1
AbilityBaseVerticalFlySpeed = 1.0
)

// AbilityData represents various data about the abilities of a player, such as ability layers or permissions.
Expand Down Expand Up @@ -70,8 +72,10 @@ type AbilityLayer struct {
// Values is a set of values that are associated with the enabled abilities, representing the values of the
// abilities.
Values uint32
// FlySpeed is the default fly speed of the layer.
// FlySpeed is the default horizontal fly speed of the layer.
FlySpeed float32
// VerticalFlySpeed is the default vertical fly speed of the layer.
VerticalFlySpeed float32
// WalkSpeed is the default walk speed of the layer.
WalkSpeed float32
}
Expand All @@ -82,5 +86,6 @@ func (x *AbilityLayer) Marshal(r IO) {
r.Uint32(&x.Abilities)
r.Uint32(&x.Values)
r.Float32(&x.FlySpeed)
r.Float32(&x.VerticalFlySpeed)
r.Float32(&x.WalkSpeed)
}
6 changes: 6 additions & 0 deletions minecraft/protocol/camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ type CameraPreset struct {
// Radius is only used in a follow_orbit camera and controls how far away from the player the camera should
// be rendered.
Radius Optional[float32]
// MinYawLimit is the minimum yaw limit of the camera.
MinYawLimit Optional[float32]
// MaxYawLimit is the maximum yaw limit of the camera.
MaxYawLimit Optional[float32]
// AudioListener defines where the audio should be played from when using this preset. This is one of the
// constants above.
AudioListener Optional[byte]
Expand Down Expand Up @@ -210,6 +214,8 @@ func (x *CameraPreset) Marshal(r IO) {
OptionalFunc(r, &x.ViewOffset, r.Vec2)
OptionalFunc(r, &x.EntityOffset, r.Vec3)
OptionalFunc(r, &x.Radius, r.Float32)
OptionalFunc(r, &x.MinYawLimit, r.Float32)
OptionalFunc(r, &x.MaxYawLimit, r.Float32)
OptionalFunc(r, &x.AudioListener, r.Uint8)
OptionalFunc(r, &x.PlayerEffects, r.Bool)
OptionalFunc(r, &x.AlignTargetAndCameraForward, r.Bool)
Expand Down
32 changes: 32 additions & 0 deletions minecraft/protocol/creative.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,48 @@
package protocol

const (
CreativeCategoryAll = iota
CreativeCategoryConstruction
CreativeCategoryNature
CreativeCategoryEquipment
CreativeCategoryItems
CreativeCategoryItemCommandOnly
CreativeCategoryUndefined
)

// CreativeGroup represents a group of items in the creative inventory. Each group has a category, name and an
// icon that represents the group.
type CreativeGroup struct {
// Category is the category the group falls under. It is one of the constants above.
Category int32
// Name is the locale name of the group, i.e. "itemGroup.name.planks".
Name string
// Icon is the item that represents the group in the creative inventory.
Icon ItemStack
}

// Marshal encodes/decodes a CreativeGroup.
func (x *CreativeGroup) Marshal(r IO) {
r.Int32(&x.Category)
r.String(&x.Name)
r.Item(&x.Icon)
}

// CreativeItem represents a creative item present in the creative inventory.
type CreativeItem struct {
// CreativeItemNetworkID is a unique ID for the creative item. It has to be unique for each creative item
// sent to the client. An incrementing ID per creative item does the job.
CreativeItemNetworkID uint32
// Item is the item that should be added to the creative inventory.
Item ItemStack
// GroupIndex is the index of the group that the item should be placed in. It is the index of the group in
// the CreativeContent packet previously sent to the client.
GroupIndex uint32
}

// Marshal encodes/decodes a CreativeItem.
func (x *CreativeItem) Marshal(r IO) {
r.Varuint32(&x.CreativeItemNetworkID)
r.Item(&x.Item)
r.Varuint32(&x.GroupIndex)
}
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 = 766
CurrentProtocol = 776
// CurrentVersion is the current version of Minecraft as supported by the `packet` package.
CurrentVersion = "1.21.50"
CurrentVersion = "1.21.60"
)
28 changes: 12 additions & 16 deletions minecraft/protocol/item.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package protocol

import (
"github.com/sandertv/gophertunnel/minecraft/nbt"
import "github.com/sandertv/gophertunnel/minecraft/nbt"

const (
ItemEntryVersionLegacy = iota
ItemEntryVersionDataDriven
ItemEntryVersionNone
)

// ItemInstance represents a unique instance of an item stack. These instances carry a specific network ID
Expand Down Expand Up @@ -55,27 +59,19 @@ type ItemEntry struct {
RuntimeID int16
// ComponentBased specifies if the item was created using components, meaning the item is a custom item.
ComponentBased bool
// Version is the version of the item entry which is used by the client to determine how to handle the
// item entry. It is one of the constants above.
Version int32
// Data is a map containing the components and properties of the item, if the item is component based.
Data map[string]any
}

// Marshal encodes/decodes an ItemEntry.
func (x *ItemEntry) Marshal(r IO) {
r.String(&x.Name)
r.Int16(&x.RuntimeID)
r.Bool(&x.ComponentBased)
}

// ItemComponentEntry is sent in the ItemComponent item table. It holds a name and all of the components and
// properties associated to the item.
type ItemComponentEntry struct {
// Name is the name of the item, which is a name like 'minecraft:stick'.
Name string
// Data is a map containing the components and properties of the item.
Data map[string]any
}

// Marshal encodes/decodes an ItemComponentEntry.
func (x *ItemComponentEntry) Marshal(r IO) {
r.String(&x.Name)
r.Varint32(&x.Version)
r.NBT(&x.Data, nbt.NetworkLittleEndian)
}

Expand Down
6 changes: 6 additions & 0 deletions minecraft/protocol/packet/boss_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ type BossEvent struct {
// a different title if the BossEntityUniqueID matches the client's entity
// unique ID.
BossBarTitle string
// FilteredBossBarTitle is a filtered version of BossBarTitle with all the
// profanity removed. The client will use this over BossBarTitle if this
// field is not empty and they have the "Filter Profanity" setting enabled.
FilteredBossBarTitle string
// HealthPercentage is the percentage of health that is shown in the boss
// bar (0.0-1.0). The HealthPercentage may be set to a specific value if the
// BossEntityUniqueID matches the client's entity unique ID.
Expand Down Expand Up @@ -78,6 +82,7 @@ func (pk *BossEvent) Marshal(io protocol.IO) {
switch pk.EventType {
case BossEventShow:
io.String(&pk.BossBarTitle)
io.String(&pk.FilteredBossBarTitle)
io.Float32(&pk.HealthPercentage)
io.Uint16(&pk.ScreenDarkening)
io.Varuint32(&pk.Colour)
Expand All @@ -90,6 +95,7 @@ func (pk *BossEvent) Marshal(io protocol.IO) {
io.Float32(&pk.HealthPercentage)
case BossEventTitle:
io.String(&pk.BossBarTitle)
io.String(&pk.FilteredBossBarTitle)
case BossEventAppearanceProperties:
io.Uint16(&pk.ScreenDarkening)
io.Varuint32(&pk.Colour)
Expand Down
8 changes: 8 additions & 0 deletions minecraft/protocol/packet/camera_aim_assist_presets.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import (
"github.com/sandertv/gophertunnel/minecraft/protocol"
)

const (
CameraAunAssistPresetOperationSet = iota
CameraAunAssistPresetOperationAddToExisting
)

// CameraAimAssistPresets is sent by the server to the client to provide a list of categories and presets
// that can be used when sending a CameraAimAssist packet or a CameraInstruction including aim assist.
type CameraAimAssistPresets struct {
// CategoryGroups is a list of groups of categories which can be referenced by one of the Presets.
CategoryGroups []protocol.CameraAimAssistCategoryGroup
// Presets is a list of presets which define a base for how aim assist should behave
Presets []protocol.CameraAimAssistPreset
// Operation is the operation to perform with the presets. It is one of the constants above.
Operation byte
}

// ID ...
Expand All @@ -21,4 +28,5 @@ func (*CameraAimAssistPresets) ID() uint32 {
func (pk *CameraAimAssistPresets) Marshal(io protocol.IO) {
protocol.Slice(io, &pk.CategoryGroups)
protocol.Slice(io, &pk.Presets)
io.Uint8(&pk.Operation)
}
33 changes: 33 additions & 0 deletions minecraft/protocol/packet/client_camera_aim_assist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package packet

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

const (
ClientCameraAimAssistActionSet = iota
ClientCameraAimAssistActionClear
)

// ClientCameraAimAssist is sent by the server to send a player animation from one player to all viewers of that player. It
// is used for a couple of actions, such as arm swimming and critical hits.
type ClientCameraAimAssist struct {
// PresetID is the identifier of the preset to use which was previously defined in the CameraAimAssistPresets
// packet.
PresetID string
// Action is the action to perform with the aim assist. It is one of the constants above.
Action byte
// AllowAimAssist specifies the client can use aim assist or not.
AllowAimAssist bool
}

// ID ...
func (*ClientCameraAimAssist) ID() uint32 {
return IDClientCameraAimAssist
}

func (pk *ClientCameraAimAssist) Marshal(io protocol.IO) {
io.String(&pk.PresetID)
io.Uint8(&pk.Action)
io.Bool(&pk.AllowAimAssist)
}
49 changes: 49 additions & 0 deletions minecraft/protocol/packet/client_movement_prediction_sync.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package packet

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

// ClientMovementPredictionSync is sent by the client to the server periodically if the client has received
// movement corrections from the server, containing information about client-predictions that are relevant
// to movement.
type ClientMovementPredictionSync struct {
// ActorFlags is a bitset of all the flags that are currently set for the client.
ActorFlags protocol.Bitset
// BoundingBoxScale is the scale of the client's bounding box.
BoundingBoxScale float32
// BoundingBoxWidth is the width of the client's bounding box.
BoundingBoxWidth float32
// BoundingBoxHeight is the height of the client's bounding box.
BoundingBoxHeight float32
// MovementSpeed is the movement speed attribute or 0 if not set.
MovementSpeed float32
// UnderwaterMovementSpeed is the underwater movement speed attribute or 0 if not set.
UnderwaterMovementSpeed float32
// LavaMovementSpeed is the lava movement speed attribute or 0 if not set.
LavaMovementSpeed float32
// JumpStrength is the jump strength attribute or 0 if not set.
JumpStrength float32
// Health is the health attribute or 0 if not set.
Health float32
// Hunger is the hunger attribute or 0 if not set.
Hunger float32
}

// ID ...
func (*ClientMovementPredictionSync) ID() uint32 {
return IDClientMovementPredictionSync
}

func (pk *ClientMovementPredictionSync) Marshal(io protocol.IO) {
io.Bitset(&pk.ActorFlags, 120)
io.Float32(&pk.BoundingBoxScale)
io.Float32(&pk.BoundingBoxWidth)
io.Float32(&pk.BoundingBoxHeight)
io.Float32(&pk.MovementSpeed)
io.Float32(&pk.UnderwaterMovementSpeed)
io.Float32(&pk.LavaMovementSpeed)
io.Float32(&pk.JumpStrength)
io.Float32(&pk.Health)
io.Float32(&pk.Hunger)
}
4 changes: 4 additions & 0 deletions minecraft/protocol/packet/command_block_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ type CommandBlockUpdate struct {
// Name is the name of the command block updated. If not empty, it will show this name hovering above the
// command block when hovering over the block with the cursor.
Name string
// FilteredName is a filtered version of Name with all the profanity removed. The client will use this
// over Name if this field is not empty and they have the "Filter Profanity" setting enabled.
FilteredName string
// ShouldTrackOutput specifies if the command block tracks output. If set to false, the output box won't
// be shown within the command block.
ShouldTrackOutput bool
Expand Down Expand Up @@ -74,6 +77,7 @@ func (pk *CommandBlockUpdate) Marshal(io protocol.IO) {
io.String(&pk.Command)
io.String(&pk.LastOutput)
io.String(&pk.Name)
io.String(&pk.FilteredName)
io.Bool(&pk.ShouldTrackOutput)
io.Int32(&pk.TickDelay)
io.Bool(&pk.ExecuteOnFirstTick)
Expand Down
Loading