Skip to content
This repository was archived by the owner on Feb 21, 2025. It is now read-only.

Commit 31e73c9

Browse files
authored
Fetch from upstream. (#9)
2 parents 4635d17 + e400da0 commit 31e73c9

27 files changed

+352
-51
lines changed

minecraft/conn.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ func (conn *Conn) handleClientToServerHandshake() error {
935935
}
936936
if pack.Encrypted() {
937937
texturePack.ContentKey = pack.ContentKey()
938-
texturePack.ContentIdentity = pack.Manifest().Header.UUID
938+
texturePack.ContentIdentity = pack.Manifest().Header.UUID.String()
939939
}
940940
pk.TexturePacks = append(pk.TexturePacks, texturePack)
941941
}
@@ -1014,22 +1014,23 @@ func (conn *Conn) handleResourcePacksInfo(pk *packet.ResourcePacksInfo) error {
10141014
packsToDownload := make([]string, 0, totalPacks)
10151015

10161016
for index, pack := range pk.TexturePacks {
1017-
if _, ok := conn.packQueue.downloadingPacks[pack.UUID]; ok {
1017+
id := pack.UUID.String()
1018+
if _, ok := conn.packQueue.downloadingPacks[id]; ok {
10181019
conn.log.Warn("handle ResourcePacksInfo: duplicate texture pack", "UUID", pack.UUID)
10191020
conn.packQueue.packAmount--
10201021
continue
10211022
}
1022-
if conn.downloadResourcePack != nil && !conn.downloadResourcePack(uuid.MustParse(pack.UUID), pack.Version, index, totalPacks) {
1023+
if conn.downloadResourcePack != nil && !conn.downloadResourcePack(uuid.MustParse(id), pack.Version, index, totalPacks) {
10231024
conn.ignoredResourcePacks = append(conn.ignoredResourcePacks, exemptedResourcePack{
1024-
uuid: pack.UUID,
1025+
uuid: id,
10251026
version: pack.Version,
10261027
})
10271028
conn.packQueue.packAmount--
10281029
continue
10291030
}
10301031
// This UUID_Version is a hack Mojang put in place.
1031-
packsToDownload = append(packsToDownload, pack.UUID+"_"+pack.Version)
1032-
conn.packQueue.downloadingPacks[pack.UUID] = downloadingPack{
1032+
packsToDownload = append(packsToDownload, id+"_"+pack.Version)
1033+
conn.packQueue.downloadingPacks[id] = downloadingPack{
10331034
size: pack.Size,
10341035
buf: bytes.NewBuffer(make([]byte, 0, pack.Size)),
10351036
newFrag: make(chan []byte),
@@ -1098,7 +1099,7 @@ func (conn *Conn) hasPack(uuid string, version string, hasBehaviours bool) bool
10981099
}
10991100
}
11001101
for _, pack := range conn.resourcePacks {
1101-
if pack.UUID() == uuid && pack.Version() == version && pack.HasBehaviours() == hasBehaviours {
1102+
if pack.UUID().String() == uuid && pack.Version() == version && pack.HasBehaviours() == hasBehaviours {
11021103
return true
11031104
}
11041105
}
@@ -1130,7 +1131,7 @@ func (conn *Conn) handleResourcePackClientResponse(pk *packet.ResourcePackClient
11301131
case packet.PackResponseAllPacksDownloaded:
11311132
pk := &packet.ResourcePackStack{BaseGameVersion: protocol.CurrentVersion, Experiments: []protocol.ExperimentData{{Name: "cameras", Enabled: true}}}
11321133
for _, pack := range conn.resourcePacks {
1133-
resourcePack := protocol.StackResourcePack{UUID: pack.UUID(), Version: pack.Version()}
1134+
resourcePack := protocol.StackResourcePack{UUID: pack.UUID().String(), Version: pack.Version()}
11341135
// If it has behaviours, add it to the behaviour pack list. If not, we add it to the texture packs
11351136
// list.
11361137
if pack.HasBehaviours() {
@@ -1317,7 +1318,7 @@ func (conn *Conn) handleResourcePackChunkData(pk *packet.ResourcePackChunkData)
13171318
// pack to be downloaded.
13181319
func (conn *Conn) handleResourcePackChunkRequest(pk *packet.ResourcePackChunkRequest) error {
13191320
current := conn.packQueue.currentPack
1320-
if current.UUID() != pk.UUID {
1321+
if current.UUID().String() != pk.UUID {
13211322
return fmt.Errorf("expected pack UUID %v, but got %v", current.UUID(), pk.UUID)
13221323
}
13231324
if conn.packQueue.currentOffset != uint64(pk.ChunkIndex)*packChunkSize {

minecraft/listener.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (listener *Listener) AddResourcePack(pack *resource.Pack) {
197197
func (listener *Listener) RemoveResourcePack(uuid string) {
198198
listener.packsMu.Lock()
199199
listener.packs = slices.DeleteFunc(listener.packs, func(pack *resource.Pack) bool {
200-
return pack.UUID() == uuid
200+
return pack.UUID().String() == uuid
201201
})
202202
listener.packsMu.Unlock()
203203
}

minecraft/protocol/bitset.go

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package protocol
2+
3+
import "math/big"
4+
5+
// Bitset is a representation of std::bitset<size> being sent over the network, allowing for more than 64 bits
6+
// to be stored in a single integer. A Bitset has a fixed size, which is set at creation time.
7+
type Bitset struct {
8+
size int
9+
int *big.Int
10+
}
11+
12+
// NewBitset creates a new Bitset with a specific size. The size is the amount of bits that the Bitset can
13+
// store. Attempting to set a bit at an index higher than the size will panic.
14+
func NewBitset(size int) Bitset {
15+
return Bitset{size: size, int: new(big.Int)}
16+
}
17+
18+
// Set sets a bit at a specific index in the Bitset. If the index is higher than the size of the Bitset, a
19+
// panic will occur.
20+
func (b Bitset) Set(i int) {
21+
if i >= b.size {
22+
panic("index out of bounds")
23+
}
24+
b.int.SetBit(b.int, i, 1)
25+
}
26+
27+
// Unset unsets a bit at a specific index in the Bitset. If the index is higher than the size of the Bitset,
28+
// a panic will occur.
29+
func (b Bitset) Unset(i int) {
30+
if i >= b.size {
31+
panic("index out of bounds")
32+
}
33+
b.int.SetBit(b.int, i, 0)
34+
}
35+
36+
// Load returns if a bit at a specific index in the Bitset is set. If the index is higher than the size of the
37+
// Bitset, a panic will occur.
38+
func (b Bitset) Load(i int) bool {
39+
if i >= b.size {
40+
panic("index out of bounds")
41+
}
42+
return b.int.Bit(i) == 1
43+
}

minecraft/protocol/camera.go

+147-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import (
55
"image/color"
66
)
77

8+
const (
9+
AimAssistTargetModeAngle = iota
10+
AimAssistTargetModeDistance
11+
)
12+
813
const (
914
AudioListenerCamera = iota
1015
AudioListenerPlayer
@@ -163,8 +168,10 @@ type CameraPreset struct {
163168
HorizontalRotationLimit Optional[mgl32.Vec2]
164169
// VerticalRotationLimit is the vertical rotation limit of the camera.
165170
VerticalRotationLimit Optional[mgl32.Vec2]
166-
// ContinueTargeting determines whether the camera should continue targeting the entity or not.
171+
// ContinueTargeting determines whether the camera should continue targeting when using aim assist.
167172
ContinueTargeting Optional[bool]
173+
// TrackingRadius is the radius around the camera that the aim assist should track targets.
174+
TrackingRadius Optional[float32]
168175
// ViewOffset is only used in a follow_orbit camera and controls an offset based on a pivot point to the
169176
// player, causing it to be shifted in a certain direction.
170177
ViewOffset Optional[mgl32.Vec2]
@@ -181,6 +188,8 @@ type CameraPreset struct {
181188
// AlignTargetAndCameraForward determines whether the camera should align the target and the camera forward
182189
// or not.
183190
AlignTargetAndCameraForward Optional[bool]
191+
// AimAssist defines the aim assist to use when using this preset.
192+
AimAssist Optional[CameraPresetAimAssist]
184193
}
185194

186195
// Marshal encodes/decodes a CameraPreset.
@@ -197,10 +206,147 @@ func (x *CameraPreset) Marshal(r IO) {
197206
OptionalFunc(r, &x.HorizontalRotationLimit, r.Vec2)
198207
OptionalFunc(r, &x.VerticalRotationLimit, r.Vec2)
199208
OptionalFunc(r, &x.ContinueTargeting, r.Bool)
209+
OptionalFunc(r, &x.TrackingRadius, r.Float32)
200210
OptionalFunc(r, &x.ViewOffset, r.Vec2)
201211
OptionalFunc(r, &x.EntityOffset, r.Vec3)
202212
OptionalFunc(r, &x.Radius, r.Float32)
203213
OptionalFunc(r, &x.AudioListener, r.Uint8)
204214
OptionalFunc(r, &x.PlayerEffects, r.Bool)
205215
OptionalFunc(r, &x.AlignTargetAndCameraForward, r.Bool)
206216
}
217+
218+
// CameraPresetAimAssist represents a preset for aim assist settings.
219+
type CameraPresetAimAssist struct {
220+
// Preset is the ID of the preset that has previously been defined in the CameraAimAssistPresets packet.
221+
Preset Optional[string]
222+
// TargetMode is the mode that the camera should use for detecting targets. This is one of the constants
223+
// above.
224+
TargetMode Optional[int32]
225+
// Angle is the maximum angle around the playes's cursor that the aim assist should check for a target,
226+
// if TargetMode is set to protocol.AimAssistTargetModeAngle.
227+
Angle Optional[mgl32.Vec2]
228+
// Distance is the maximum distance from the player's cursor should check for a target, if TargetMode is
229+
// set to protocol.AimAssistTargetModeDistance.
230+
Distance Optional[float32]
231+
}
232+
233+
// Marshal encodes/decodes a CameraPresetAimAssist.
234+
func (x *CameraPresetAimAssist) Marshal(r IO) {
235+
OptionalFunc(r, &x.Preset, r.String)
236+
OptionalFunc(r, &x.TargetMode, r.Int32)
237+
OptionalFunc(r, &x.Angle, r.Vec2)
238+
OptionalFunc(r, &x.Distance, r.Float32)
239+
}
240+
241+
// CameraAimAssistCategoryGroup is a group of categories which can be used by a CameraAimAssistPreset.
242+
type CameraAimAssistCategoryGroup struct {
243+
// Identifier is the unique identifier of the group.
244+
Identifier string
245+
// Categories is a list of categories within this group.
246+
Categories []CameraAimAssistCategory
247+
}
248+
249+
// Marshal encodes/decodes a CameraAimAssistCategoryGroup.
250+
func (x *CameraAimAssistCategoryGroup) Marshal(r IO) {
251+
r.String(&x.Identifier)
252+
Slice(r, &x.Categories)
253+
}
254+
255+
// CameraAimAssistCategory is an aim assist category that defines priorities for specific blocks and entities.
256+
type CameraAimAssistCategory struct {
257+
// Name is the name of the category which can be used by a CameraAimAssistPreset.
258+
Name string
259+
// Priorities represents the block and entity specific priorities as well as the default priorities for
260+
// this category.
261+
Priorities CameraAimAssistPriorities
262+
}
263+
264+
// Marshal encodes/decodes a CameraAimAssistCategory.
265+
func (x *CameraAimAssistCategory) Marshal(r IO) {
266+
r.String(&x.Name)
267+
Single(r, &x.Priorities)
268+
}
269+
270+
// CameraAimAssistPriorities represents the block and entity specific priorities for targetting. The aim
271+
// assist will select the block or entity with the highest priority within the specified thresholds.
272+
type CameraAimAssistPriorities struct {
273+
// Entities is a list of priorities for specific entity identifiers.
274+
Entities []CameraAimAssistPriority
275+
// Blocks is a list of priorities for specific block identifiers.
276+
Blocks []CameraAimAssistPriority
277+
// EntityDefault is the default priority for entities.
278+
EntityDefault Optional[int32]
279+
// BlockDefault is the default priority for blocks.
280+
BlockDefault Optional[int32]
281+
}
282+
283+
// Marshal encodes/decodes a CameraAimAssistPriorities.
284+
func (x *CameraAimAssistPriorities) Marshal(r IO) {
285+
Slice(r, &x.Entities)
286+
Slice(r, &x.Blocks)
287+
OptionalFunc(r, &x.EntityDefault, r.Int32)
288+
OptionalFunc(r, &x.BlockDefault, r.Int32)
289+
}
290+
291+
// CameraAimAssistPriority represents a non-default priority for a specific target.
292+
type CameraAimAssistPriority struct {
293+
// Identifier is the identifier of a target to define the priority for.
294+
Identifier string
295+
// Priority is the priority for this specific target.
296+
Priority int32
297+
}
298+
299+
// Marshal encodes/decodes a CameraAimAssistPriority.
300+
func (x *CameraAimAssistPriority) Marshal(r IO) {
301+
r.String(&x.Identifier)
302+
r.Int32(&x.Priority)
303+
}
304+
305+
// CameraAimAssistPreset defines a base preset that can be extended upon when sending an aim assist.
306+
type CameraAimAssistPreset struct {
307+
// Identifier represents the identifier of this preset.
308+
Identifier string
309+
// CategoryGroup is the name of a CameraAimAssistCategoryGroup to use for the preset.
310+
CategoryGroup string
311+
// BlockExclusions is a list of block identifiers that should be ignored by the aim assist.
312+
BlockExclusions []string
313+
// LiquidTargets is a list of entity identifiers that should be targetted when inside of a liquid.
314+
LiquidTargets []string
315+
// ItemSettings is a list of settings for specific item identifiers. If an item is not listed here, it
316+
// will fallback to DefaultItemSettings or HandSettings if no item is held.
317+
ItemSettings []CameraAimAssistItemSettings
318+
// DefaultItemSettings is the identifier of a category to use when the player is not holding an item
319+
// listed in ItemSettings. This must be the identifier of a category within the
320+
// CameraAimAssistCategoryGroup references by CategoryGroup.
321+
DefaultItemSettings Optional[string]
322+
// HandSettings is the identifier of a category to use when the player is not holding an item. This must
323+
// be the identifier of a category within the CameraAimAssistCategoryGroup references by CategoryGroup.
324+
HandSettings Optional[string]
325+
}
326+
327+
// Marshal encodes/decodes a CameraAimAssistPreset.
328+
func (x *CameraAimAssistPreset) Marshal(r IO) {
329+
r.String(&x.Identifier)
330+
r.String(&x.CategoryGroup)
331+
FuncSlice(r, &x.BlockExclusions, r.String)
332+
FuncSlice(r, &x.LiquidTargets, r.String)
333+
Slice(r, &x.ItemSettings)
334+
OptionalFunc(r, &x.DefaultItemSettings, r.String)
335+
OptionalFunc(r, &x.HandSettings, r.String)
336+
}
337+
338+
// CameraAimAssistItemSettings defines settings for how specific items should behave when using aim assist.
339+
type CameraAimAssistItemSettings struct {
340+
// Item is the identifier of the item to apply the settings to.
341+
Item string
342+
// Category is the identifier of a category to use which has been defined by a CameraAimAssistCategory.
343+
// Only categories defined in the CameraAimAssistCategoryGroup used by the CameraAimAssistPreset can be
344+
// used here.
345+
Category string
346+
}
347+
348+
// Marshal encodes/decodes a CameraAimAssistItemSettings.
349+
func (x *CameraAimAssistItemSettings) Marshal(r IO) {
350+
r.String(&x.Item)
351+
r.String(&x.Category)
352+
}

minecraft/protocol/info.go

+2-2
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 = 748
5+
CurrentProtocol = 766
66
// CurrentVersion is the current version of Minecraft as supported by the `packet` package.
7-
CurrentVersion = "1.21.40"
7+
CurrentVersion = "1.21.50"
88
)

minecraft/protocol/io.go

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type IO interface {
5858
GameRule(x *GameRule)
5959
AbilityValue(x *any)
6060
CompressedBiomeDefinitions(x *map[string]any)
61+
Bitset(x *Bitset, size int)
6162

6263
ShieldID() int32
6364
UnknownEnumOption(value any, enum string)

minecraft/protocol/item_stack.go

+4
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ type StackResponseSlotInfo struct {
259259
StackNetworkID int32
260260
// CustomName is the custom name of the item stack. It is used in relation to text filtering.
261261
CustomName string
262+
// FilteredCustomName is a filtered version of CustomName with all the profanity removed. The client will
263+
// use this over CustomName if this field is not empty and they have the "Filter Profanity" setting enabled.
264+
FilteredCustomName string
262265
// DurabilityCorrection is the current durability of the item stack. This durability will be shown
263266
// client-side after the response is sent to the client.
264267
DurabilityCorrection int32
@@ -274,6 +277,7 @@ func (x *StackResponseSlotInfo) Marshal(r IO) {
274277
r.InvalidValue(x.HotbarSlot, "hotbar slot", "hot bar slot must be equal to normal slot")
275278
}
276279
r.String(&x.CustomName)
280+
r.String(&x.FilteredCustomName)
277281
r.Varint32(&x.DurabilityCorrection)
278282
}
279283

minecraft/protocol/os.go

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const (
99
DeviceIOS
1010
DeviceOSX
1111
DeviceFireOS
12+
// Deprecated: DeviceGearVR is deprecated as of 1.21.50.
1213
DeviceGearVR
1314
DeviceHololens
1415
DeviceWin10

minecraft/protocol/packet/camera_aim_assist.go

+11-13
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@ const (
1010
CameraAimAssistActionClear
1111
)
1212

13-
const (
14-
CameraAimAssistTargetModeAngle = iota
15-
CameraAimAssistTargetModeDistance
16-
)
17-
1813
// CameraAimAssist is sent by the server to the client to set up aim assist for the client's camera.
1914
type CameraAimAssist struct {
20-
// ViewAngle is the angle that the camera should aim at, if TargetMode is set to
21-
// CameraAimAssistTargetModeAngle.
22-
ViewAngle mgl32.Vec2
23-
// Distance is the distance that the camera should keep from the target, if TargetMode is set to
24-
// CameraAimAssistTargetModeDistance.
15+
// Preset is the ID of the preset that has previously been defined in the CameraAimAssistPresets packet.
16+
Preset string
17+
// Angle is the maximum angle around the playes's cursor that the aim assist should check for a target,
18+
// if TargetMode is set to protocol.AimAssistTargetModeAngle.
19+
Angle mgl32.Vec2
20+
// Distance is the maximum distance from the player's cursor should check for a target, if TargetMode is
21+
// set to protocol.AimAssistTargetModeDistance.
2522
Distance float32
26-
// TargetMode is the mode that the camera should use to aim at the target. This is one of the constants
27-
// above.
23+
// TargetMode is the mode that the camera should use for detecting targets. This is currently one of
24+
// protocol.AimAssistTargetModeAngle or protocol.AimAssistTargetModeDistance.
2825
TargetMode byte
2926
// Action is the action that should be performed with the aim assist. This is one of the constants above.
3027
Action byte
@@ -36,7 +33,8 @@ func (*CameraAimAssist) ID() uint32 {
3633
}
3734

3835
func (pk *CameraAimAssist) Marshal(io protocol.IO) {
39-
io.Vec2(&pk.ViewAngle)
36+
io.String(&pk.Preset)
37+
io.Vec2(&pk.Angle)
4038
io.Float32(&pk.Distance)
4139
io.Uint8(&pk.TargetMode)
4240
io.Uint8(&pk.Action)

0 commit comments

Comments
 (0)