1.21.60 support

This commit is contained in:
AkmalFairuz
2025-02-13 10:42:17 +07:00
parent 1eea0360a5
commit f424b90afd
28 changed files with 10000 additions and 96 deletions

108
legacyver/proto/ability.go Normal file
View File

@@ -0,0 +1,108 @@
package proto
import (
"github.com/sandertv/gophertunnel/minecraft/protocol"
)
// AbilityData represents various data about the abilities of a player, such as ability layers or permissions.
type AbilityData struct {
// EntityUniqueID is a unique identifier of the player. It appears it is not required to fill this field
// out with a correct value. Simply writing 0 seems to work.
EntityUniqueID int64
// PlayerPermissions is the permission level of the player as it shows up in the player list built up using
// the PlayerList packet.
PlayerPermissions byte
// CommandPermissions is a set of permissions that specify what commands a player is allowed to execute.
CommandPermissions byte
// Layers contains all ability layers and their potential values. This should at least have one entry, being the
// base layer.
Layers []AbilityLayer
}
// Marshal encodes/decodes an AbilityData.
func (x *AbilityData) Marshal(r protocol.IO) {
r.Int64(&x.EntityUniqueID)
r.Uint8(&x.PlayerPermissions)
r.Uint8(&x.CommandPermissions)
protocol.SliceUint8Length(r, &x.Layers)
}
// ToLatest ...
func (x *AbilityData) ToLatest() protocol.AbilityData {
layers := make([]protocol.AbilityLayer, len(x.Layers))
for i, layer := range x.Layers {
layers[i] = layer.ToLatest()
}
return protocol.AbilityData{
EntityUniqueID: x.EntityUniqueID,
PlayerPermissions: x.PlayerPermissions,
CommandPermissions: x.CommandPermissions,
Layers: layers,
}
}
// FromLatest ...
func (x *AbilityData) FromLatest(y protocol.AbilityData) AbilityData {
layers := make([]AbilityLayer, len(y.Layers))
for i, layer := range y.Layers {
layers[i] = (&AbilityLayer{}).FromLatest(layer)
}
x.EntityUniqueID = y.EntityUniqueID
x.PlayerPermissions = y.PlayerPermissions
x.CommandPermissions = y.CommandPermissions
x.Layers = layers
return *x
}
// AbilityLayer represents the abilities of a specific layer, such as the base layer or the spectator layer.
type AbilityLayer struct {
// Type represents the type of the layer. This is one of the AbilityLayerType constants defined above.
Type uint16
// Abilities is a set of abilities that are enabled for the layer. This is one of the Ability constants defined
// above.
Abilities uint32
// 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 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
}
// Marshal encodes/decodes an AbilityLayer.
func (x *AbilityLayer) Marshal(r protocol.IO) {
r.Uint16(&x.Type)
r.Uint32(&x.Abilities)
r.Uint32(&x.Values)
r.Float32(&x.FlySpeed)
if IsProtoGTE(r, ID776) {
r.Float32(&x.VerticalFlySpeed)
}
r.Float32(&x.WalkSpeed)
}
// ToLatest ...
func (x *AbilityLayer) ToLatest() protocol.AbilityLayer {
return protocol.AbilityLayer{
Type: x.Type,
Abilities: x.Abilities,
Values: x.Values,
FlySpeed: x.FlySpeed,
VerticalFlySpeed: x.VerticalFlySpeed,
WalkSpeed: x.WalkSpeed,
}
}
// FromLatest ...
func (x *AbilityLayer) FromLatest(y protocol.AbilityLayer) AbilityLayer {
x.Type = y.Type
x.Abilities = y.Abilities
x.Values = y.Values
x.FlySpeed = y.FlySpeed
x.VerticalFlySpeed = y.VerticalFlySpeed
x.WalkSpeed = y.WalkSpeed
return *x
}

View File

@@ -41,6 +41,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 protocol.Optional[float32]
// MinYawLimit is the minimum yaw limit of the camera.
MinYawLimit protocol.Optional[float32]
// MaxYawLimit is the maximum yaw limit of the camera.
MaxYawLimit protocol.Optional[float32]
// AudioListener defines where the audio should be played from when using this preset. This is one of the
// constants above.
AudioListener protocol.Optional[byte]
@@ -95,6 +99,8 @@ func (x *CameraPreset) ToLatest() protocol.CameraPreset {
ViewOffset: x.ViewOffset,
EntityOffset: x.EntityOffset,
Radius: x.Radius,
MinYawLimit: x.MinYawLimit,
MaxYawLimit: x.MaxYawLimit,
AudioListener: x.AudioListener,
PlayerEffects: x.PlayerEffects,
AlignTargetAndCameraForward: x.AlignTargetAndCameraForward,
@@ -123,6 +129,10 @@ func (x *CameraPreset) Marshal(r protocol.IO) {
if IsProtoGTE(r, ID766) {
protocol.OptionalFunc(r, &x.TrackingRadius, r.Float32)
}
if IsProtoGTE(r, ID776) {
protocol.OptionalFunc(r, &x.MinYawLimit, r.Float32)
protocol.OptionalFunc(r, &x.MaxYawLimit, r.Float32)
}
protocol.OptionalFunc(r, &x.ViewOffset, r.Vec2)
if IsProtoGTE(r, ID729) {
protocol.OptionalFunc(r, &x.EntityOffset, r.Vec3)

View File

@@ -0,0 +1,41 @@
package proto
import "github.com/sandertv/gophertunnel/minecraft/protocol"
// 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 protocol.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
}
// ToLatest ...
func (x *CreativeItem) ToLatest() protocol.CreativeItem {
return protocol.CreativeItem{
CreativeItemNetworkID: x.CreativeItemNetworkID,
Item: x.Item,
GroupIndex: x.GroupIndex,
}
}
// FromLatest ...
func (x *CreativeItem) FromLatest(y protocol.CreativeItem) CreativeItem {
x.CreativeItemNetworkID = y.CreativeItemNetworkID
x.Item = y.Item
x.GroupIndex = y.GroupIndex
return *x
}
// Marshal encodes/decodes a CreativeItem.
func (x *CreativeItem) Marshal(r protocol.IO) {
r.Varuint32(&x.CreativeItemNetworkID)
r.Item(&x.Item)
if IsProtoGTE(r, ID776) {
r.Varuint32(&x.GroupIndex)
}
}

View File

@@ -3,6 +3,7 @@ package proto
import "github.com/sandertv/gophertunnel/minecraft/protocol"
const (
ID776 = 776 // v1.21.60
ID766 = 766 // v1.21.50
ID748 = 748 // v1.21.40
ID729 = 729 // v1.21.30

92
legacyver/proto/item.go Normal file
View File

@@ -0,0 +1,92 @@
package proto
import (
"github.com/sandertv/gophertunnel/minecraft/nbt"
"github.com/sandertv/gophertunnel/minecraft/protocol"
)
// LegacyItemRegistryEntry is an item sent in the StartGame item table. It holds a name and a legacy ID, which is used to
// point back to that name.
type LegacyItemRegistryEntry struct {
// Name if the name of the item, which is a name like 'minecraft:stick'.
Name string
// RuntimeID is the ID that is used to identify the item over network. After sending all items in the
// StartGame packet, items will then be identified using these numerical IDs.
RuntimeID int16
// ComponentBased specifies if the item was created using components, meaning the item is a custom item.
ComponentBased bool
}
// Marshal encodes/decodes an LegacyItemRegistryEntry.
func (x *LegacyItemRegistryEntry) Marshal(r protocol.IO) {
r.String(&x.Name)
r.Int16(&x.RuntimeID)
r.Bool(&x.ComponentBased)
}
// FromLatest ...
func (x *LegacyItemRegistryEntry) FromLatest(y protocol.ItemEntry) LegacyItemRegistryEntry {
x.Name = y.Name
x.RuntimeID = y.RuntimeID
x.ComponentBased = y.ComponentBased
return *x
}
// ToLatest ...
func (x *LegacyItemRegistryEntry) ToLatest() protocol.ItemEntry {
return protocol.ItemEntry{
Name: x.Name,
RuntimeID: x.RuntimeID,
ComponentBased: x.ComponentBased,
Version: 2,
}
}
// ItemEntry is an item sent in the StartGame item table. It holds a name and a legacy ID, which is used to
// point back to that name.
type ItemEntry struct {
// Name if the name of the item, which is a name like 'minecraft:stick'.
Name string
// RuntimeID is the ID that is used to identify the item over network. After sending all items in the
// StartGame packet, items will then be identified using these numerical IDs.
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
}
// ToLatest ...
func (x *ItemEntry) ToLatest() protocol.ItemEntry {
return protocol.ItemEntry{
Name: x.Name,
RuntimeID: x.RuntimeID,
ComponentBased: x.ComponentBased,
Version: x.Version,
Data: x.Data,
}
}
// FromLatest ...
func (x *ItemEntry) FromLatest(y protocol.ItemEntry) ItemEntry {
x.Name = y.Name
x.RuntimeID = y.RuntimeID
x.ComponentBased = y.ComponentBased
x.Version = y.Version
x.Data = y.Data
return *x
}
// Marshal encodes/decodes an ItemEntry.
func (x *ItemEntry) Marshal(r protocol.IO) {
r.String(&x.Name)
if IsProtoGTE(r, ID776) {
r.Int16(&x.RuntimeID)
r.Bool(&x.ComponentBased)
r.Varint32(&x.Version)
}
r.NBT(&x.Data, nbt.NetworkLittleEndian)
}