Skip to content

Commit 20380a4

Browse files
authored
Merge branch 'Sandertv:master' into master
2 parents 1ebcda3 + 9e042b2 commit 20380a4

19 files changed

+234
-51
lines changed

minecraft/conn.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,8 @@ func (conn *Conn) handlePacket(pk packet.Packet) error {
687687
return conn.handleResourcePackStack(pk)
688688
case *packet.StartGame:
689689
return conn.handleStartGame(pk)
690+
case *packet.ItemRegistry:
691+
return conn.handleItemRegistry(pk)
690692
case *packet.ChunkRadiusUpdated:
691693
return conn.handleChunkRadiusUpdated(pk)
692694
}
@@ -1055,7 +1057,6 @@ func (conn *Conn) startGame() {
10551057
GameRules: data.GameRules,
10561058
Time: data.Time,
10571059
Blocks: data.CustomBlocks,
1058-
Items: data.Items,
10591060
AchievementsDisabled: true,
10601061
Generator: 1,
10611062
EducationFeaturesEnabled: true,
@@ -1077,6 +1078,7 @@ func (conn *Conn) startGame() {
10771078
GameVersion: protocol.CurrentVersion,
10781079
UseBlockNetworkIDHashes: data.UseBlockNetworkIDHashes,
10791080
})
1081+
_ = conn.WritePacket(&packet.ItemRegistry{Items: data.Items})
10801082
_ = conn.Flush()
10811083
conn.expect(packet.IDRequestChunkRadius, packet.IDSetLocalPlayerAsInitialised)
10821084
}
@@ -1256,7 +1258,6 @@ func (conn *Conn) handleStartGame(pk *packet.StartGame) error {
12561258
Time: pk.Time,
12571259
ServerBlockStateChecksum: pk.ServerBlockStateChecksum,
12581260
CustomBlocks: pk.Blocks,
1259-
Items: pk.Items,
12601261
PlayerMovementSettings: pk.PlayerMovementSettings,
12611262
WorldGameMode: pk.WorldGameMode,
12621263
Hardcore: pk.Hardcore,
@@ -1268,6 +1269,14 @@ func (conn *Conn) handleStartGame(pk *packet.StartGame) error {
12681269
Experiments: pk.Experiments,
12691270
UseBlockNetworkIDHashes: pk.UseBlockNetworkIDHashes,
12701271
}
1272+
conn.expect(packet.IDItemRegistry)
1273+
return nil
1274+
}
1275+
1276+
// handleItemRegistry handles an incoming ItemRegistry packet. It contains the item definitions that the client
1277+
// should use, including the shield ID which is necessary for reading and writing items in the future.
1278+
func (conn *Conn) handleItemRegistry(pk *packet.ItemRegistry) error {
1279+
conn.gameData.Items = pk.Items
12711280
for _, item := range pk.Items {
12721281
if item.Name == "minecraft:shield" {
12731282
conn.shieldID.Store(int32(item.RuntimeID))

minecraft/protocol/ability.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const (
2020
AbilityWorldBuilder
2121
AbilityNoClip
2222
AbilityPrivilegedBuilder
23+
AbilityVerticalFlySpeed
2324
AbilityCount
2425
)
2526

@@ -33,8 +34,9 @@ const (
3334
)
3435

3536
const (
36-
AbilityBaseFlySpeed = 0.05
37-
AbilityBaseWalkSpeed = 0.1
37+
AbilityBaseFlySpeed = 0.05
38+
AbilityBaseWalkSpeed = 0.1
39+
AbilityBaseVerticalFlySpeed = 1.0
3840
)
3941

4042
// AbilityData represents various data about the abilities of a player, such as ability layers or permissions.
@@ -70,8 +72,10 @@ type AbilityLayer struct {
7072
// Values is a set of values that are associated with the enabled abilities, representing the values of the
7173
// abilities.
7274
Values uint32
73-
// FlySpeed is the default fly speed of the layer.
75+
// FlySpeed is the default horizontal fly speed of the layer.
7476
FlySpeed float32
77+
// VerticalFlySpeed is the default vertical fly speed of the layer.
78+
VerticalFlySpeed float32
7579
// WalkSpeed is the default walk speed of the layer.
7680
WalkSpeed float32
7781
}
@@ -82,5 +86,6 @@ func (x *AbilityLayer) Marshal(r IO) {
8286
r.Uint32(&x.Abilities)
8387
r.Uint32(&x.Values)
8488
r.Float32(&x.FlySpeed)
89+
r.Float32(&x.VerticalFlySpeed)
8590
r.Float32(&x.WalkSpeed)
8691
}

minecraft/protocol/camera.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ type CameraPreset struct {
181181
// Radius is only used in a follow_orbit camera and controls how far away from the player the camera should
182182
// be rendered.
183183
Radius Optional[float32]
184+
// MinYawLimit is the minimum yaw limit of the camera.
185+
MinYawLimit Optional[float32]
186+
// MaxYawLimit is the maximum yaw limit of the camera.
187+
MaxYawLimit Optional[float32]
184188
// AudioListener defines where the audio should be played from when using this preset. This is one of the
185189
// constants above.
186190
AudioListener Optional[byte]
@@ -211,6 +215,8 @@ func (x *CameraPreset) Marshal(r IO) {
211215
OptionalFunc(r, &x.ViewOffset, r.Vec2)
212216
OptionalFunc(r, &x.EntityOffset, r.Vec3)
213217
OptionalFunc(r, &x.Radius, r.Float32)
218+
OptionalFunc(r, &x.MinYawLimit, r.Float32)
219+
OptionalFunc(r, &x.MaxYawLimit, r.Float32)
214220
OptionalFunc(r, &x.AudioListener, r.Uint8)
215221
OptionalFunc(r, &x.PlayerEffects, r.Bool)
216222
OptionalFunc(r, &x.AlignTargetAndCameraForward, r.Bool)

minecraft/protocol/creative.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,48 @@
11
package protocol
22

3+
const (
4+
CreativeCategoryAll = iota
5+
CreativeCategoryConstruction
6+
CreativeCategoryNature
7+
CreativeCategoryEquipment
8+
CreativeCategoryItems
9+
CreativeCategoryItemCommandOnly
10+
CreativeCategoryUndefined
11+
)
12+
13+
// CreativeGroup represents a group of items in the creative inventory. Each group has a category, name and an
14+
// icon that represents the group.
15+
type CreativeGroup struct {
16+
// Category is the category the group falls under. It is one of the constants above.
17+
Category int32
18+
// Name is the locale name of the group, i.e. "itemGroup.name.planks".
19+
Name string
20+
// Icon is the item that represents the group in the creative inventory.
21+
Icon ItemStack
22+
}
23+
24+
// Marshal encodes/decodes a CreativeGroup.
25+
func (x *CreativeGroup) Marshal(r IO) {
26+
r.Int32(&x.Category)
27+
r.String(&x.Name)
28+
r.Item(&x.Icon)
29+
}
30+
331
// CreativeItem represents a creative item present in the creative inventory.
432
type CreativeItem struct {
533
// CreativeItemNetworkID is a unique ID for the creative item. It has to be unique for each creative item
634
// sent to the client. An incrementing ID per creative item does the job.
735
CreativeItemNetworkID uint32
836
// Item is the item that should be added to the creative inventory.
937
Item ItemStack
38+
// GroupIndex is the index of the group that the item should be placed in. It is the index of the group in
39+
// the CreativeContent packet previously sent to the client.
40+
GroupIndex uint32
1041
}
1142

1243
// Marshal encodes/decodes a CreativeItem.
1344
func (x *CreativeItem) Marshal(r IO) {
1445
r.Varuint32(&x.CreativeItemNetworkID)
1546
r.Item(&x.Item)
47+
r.Varuint32(&x.GroupIndex)
1648
}

minecraft/protocol/info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package protocol
22

33
const (
44
// CurrentProtocol is the current protocol version for the version below.
5-
CurrentProtocol = 766
5+
CurrentProtocol = 776
66
// CurrentVersion is the current version of Minecraft as supported by the `packet` package.
7-
CurrentVersion = "1.21.50"
7+
CurrentVersion = "1.21.60"
88
)

minecraft/protocol/item.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package protocol
22

3-
import (
4-
"github.com/sandertv/gophertunnel/minecraft/nbt"
3+
import "github.com/sandertv/gophertunnel/minecraft/nbt"
4+
5+
const (
6+
ItemEntryVersionLegacy = iota
7+
ItemEntryVersionDataDriven
8+
ItemEntryVersionNone
59
)
610

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

6069
// Marshal encodes/decodes an ItemEntry.
6170
func (x *ItemEntry) Marshal(r IO) {
6271
r.String(&x.Name)
6372
r.Int16(&x.RuntimeID)
6473
r.Bool(&x.ComponentBased)
65-
}
66-
67-
// ItemComponentEntry is sent in the ItemComponent item table. It holds a name and all of the components and
68-
// properties associated to the item.
69-
type ItemComponentEntry struct {
70-
// Name is the name of the item, which is a name like 'minecraft:stick'.
71-
Name string
72-
// Data is a map containing the components and properties of the item.
73-
Data map[string]any
74-
}
75-
76-
// Marshal encodes/decodes an ItemComponentEntry.
77-
func (x *ItemComponentEntry) Marshal(r IO) {
78-
r.String(&x.Name)
74+
r.Varint32(&x.Version)
7975
r.NBT(&x.Data, nbt.NetworkLittleEndian)
8076
}
8177

minecraft/protocol/packet/boss_event.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ type BossEvent struct {
4949
// a different title if the BossEntityUniqueID matches the client's entity
5050
// unique ID.
5151
BossBarTitle string
52+
// FilteredBossBarTitle is a filtered version of BossBarTitle with all the
53+
// profanity removed. The client will use this over BossBarTitle if this
54+
// field is not empty and they have the "Filter Profanity" setting enabled.
55+
FilteredBossBarTitle string
5256
// HealthPercentage is the percentage of health that is shown in the boss
5357
// bar (0.0-1.0). The HealthPercentage may be set to a specific value if the
5458
// BossEntityUniqueID matches the client's entity unique ID.
@@ -78,6 +82,7 @@ func (pk *BossEvent) Marshal(io protocol.IO) {
7882
switch pk.EventType {
7983
case BossEventShow:
8084
io.String(&pk.BossBarTitle)
85+
io.String(&pk.FilteredBossBarTitle)
8186
io.Float32(&pk.HealthPercentage)
8287
io.Uint16(&pk.ScreenDarkening)
8388
io.Varuint32(&pk.Colour)
@@ -90,6 +95,7 @@ func (pk *BossEvent) Marshal(io protocol.IO) {
9095
io.Float32(&pk.HealthPercentage)
9196
case BossEventTitle:
9297
io.String(&pk.BossBarTitle)
98+
io.String(&pk.FilteredBossBarTitle)
9399
case BossEventAppearanceProperties:
94100
io.Uint16(&pk.ScreenDarkening)
95101
io.Varuint32(&pk.Colour)

minecraft/protocol/packet/camera_aim_assist_presets.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ import (
44
"github.com/sandertv/gophertunnel/minecraft/protocol"
55
)
66

7+
const (
8+
CameraAunAssistPresetOperationSet = iota
9+
CameraAunAssistPresetOperationAddToExisting
10+
)
11+
712
// CameraAimAssistPresets is sent by the server to the client to provide a list of categories and presets
813
// that can be used when sending a CameraAimAssist packet or a CameraInstruction including aim assist.
914
type CameraAimAssistPresets struct {
1015
// CategoryGroups is a list of groups of categories which can be referenced by one of the Presets.
1116
CategoryGroups []protocol.CameraAimAssistCategoryGroup
1217
// Presets is a list of presets which define a base for how aim assist should behave
1318
Presets []protocol.CameraAimAssistPreset
19+
// Operation is the operation to perform with the presets. It is one of the constants above.
20+
Operation byte
1421
}
1522

1623
// ID ...
@@ -21,4 +28,5 @@ func (*CameraAimAssistPresets) ID() uint32 {
2128
func (pk *CameraAimAssistPresets) Marshal(io protocol.IO) {
2229
protocol.Slice(io, &pk.CategoryGroups)
2330
protocol.Slice(io, &pk.Presets)
31+
io.Uint8(&pk.Operation)
2432
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package packet
2+
3+
import (
4+
"github.com/sandertv/gophertunnel/minecraft/protocol"
5+
)
6+
7+
const (
8+
ClientCameraAimAssistActionSet = iota
9+
ClientCameraAimAssistActionClear
10+
)
11+
12+
// ClientCameraAimAssist is sent by the server to send a player animation from one player to all viewers of that player. It
13+
// is used for a couple of actions, such as arm swimming and critical hits.
14+
type ClientCameraAimAssist struct {
15+
// PresetID is the identifier of the preset to use which was previously defined in the CameraAimAssistPresets
16+
// packet.
17+
PresetID string
18+
// Action is the action to perform with the aim assist. It is one of the constants above.
19+
Action byte
20+
// AllowAimAssist specifies the client can use aim assist or not.
21+
AllowAimAssist bool
22+
}
23+
24+
// ID ...
25+
func (*ClientCameraAimAssist) ID() uint32 {
26+
return IDClientCameraAimAssist
27+
}
28+
29+
func (pk *ClientCameraAimAssist) Marshal(io protocol.IO) {
30+
io.String(&pk.PresetID)
31+
io.Uint8(&pk.Action)
32+
io.Bool(&pk.AllowAimAssist)
33+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package packet
2+
3+
import (
4+
"github.com/sandertv/gophertunnel/minecraft/protocol"
5+
)
6+
7+
// ClientMovementPredictionSync is sent by the client to the server periodically if the client has received
8+
// movement corrections from the server, containing information about client-predictions that are relevant
9+
// to movement.
10+
type ClientMovementPredictionSync struct {
11+
// ActorFlags is a bitset of all the flags that are currently set for the client.
12+
ActorFlags protocol.Bitset
13+
// BoundingBoxScale is the scale of the client's bounding box.
14+
BoundingBoxScale float32
15+
// BoundingBoxWidth is the width of the client's bounding box.
16+
BoundingBoxWidth float32
17+
// BoundingBoxHeight is the height of the client's bounding box.
18+
BoundingBoxHeight float32
19+
// MovementSpeed is the movement speed attribute or 0 if not set.
20+
MovementSpeed float32
21+
// UnderwaterMovementSpeed is the underwater movement speed attribute or 0 if not set.
22+
UnderwaterMovementSpeed float32
23+
// LavaMovementSpeed is the lava movement speed attribute or 0 if not set.
24+
LavaMovementSpeed float32
25+
// JumpStrength is the jump strength attribute or 0 if not set.
26+
JumpStrength float32
27+
// Health is the health attribute or 0 if not set.
28+
Health float32
29+
// Hunger is the hunger attribute or 0 if not set.
30+
Hunger float32
31+
}
32+
33+
// ID ...
34+
func (*ClientMovementPredictionSync) ID() uint32 {
35+
return IDClientMovementPredictionSync
36+
}
37+
38+
func (pk *ClientMovementPredictionSync) Marshal(io protocol.IO) {
39+
io.Bitset(&pk.ActorFlags, 120)
40+
io.Float32(&pk.BoundingBoxScale)
41+
io.Float32(&pk.BoundingBoxWidth)
42+
io.Float32(&pk.BoundingBoxHeight)
43+
io.Float32(&pk.MovementSpeed)
44+
io.Float32(&pk.UnderwaterMovementSpeed)
45+
io.Float32(&pk.LavaMovementSpeed)
46+
io.Float32(&pk.JumpStrength)
47+
io.Float32(&pk.Health)
48+
io.Float32(&pk.Hunger)
49+
}

0 commit comments

Comments
 (0)