Skip to content

Commit

Permalink
minecraft/protocol: Support 1.20.60
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Feb 7, 2024
1 parent 36e5147 commit b97dc0c
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 178 deletions.
4 changes: 2 additions & 2 deletions minecraft/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ func (conn *Conn) handleRequestNetworkSettings(pk *packet.RequestNetworkSettings
}
_ = conn.Flush()
conn.enc.EnableCompression(conn.compression)
conn.dec.EnableCompression(conn.compression)
conn.dec.EnableCompression()
return nil
}

Expand All @@ -708,7 +708,7 @@ func (conn *Conn) handleNetworkSettings(pk *packet.NetworkSettings) error {
return fmt.Errorf("unknown compression algorithm: %v", pk.CompressionAlgorithm)
}
conn.enc.EnableCompression(alg)
conn.dec.EnableCompression(alg)
conn.dec.EnableCompression()
conn.readyToLogin = true
return nil
}
Expand Down
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 = 630
CurrentProtocol = 649
// CurrentVersion is the current version of Minecraft as supported by the `packet` package.
CurrentVersion = "1.20.50"
CurrentVersion = "1.20.60"
)
21 changes: 0 additions & 21 deletions minecraft/protocol/packet/add_entity.go

This file was deleted.

24 changes: 16 additions & 8 deletions minecraft/protocol/packet/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type Decoder struct {
// NewDecoder implements the packetReader interface.
pr packetReader

compression Compression
encrypt *encrypt
decompress bool
encrypt *encrypt

checkPacketLimit bool
}
Expand Down Expand Up @@ -56,8 +56,8 @@ func (decoder *Decoder) EnableEncryption(keyBytes [32]byte) {
}

// EnableCompression enables compression for the Decoder.
func (decoder *Decoder) EnableCompression(compression Compression) {
decoder.compression = compression
func (decoder *Decoder) EnableCompression() {
decoder.decompress = true
}

// DisableBatchPacketLimit disables the check that limits the number of packets allowed in a single packet
Expand Down Expand Up @@ -104,10 +104,18 @@ func (decoder *Decoder) Decode() (packets [][]byte, err error) {
data = data[:len(data)-8]
}

if decoder.compression != nil {
data, err = decoder.compression.Decompress(data)
if err != nil {
return nil, fmt.Errorf("error decompressing packet: %v", err)
if decoder.decompress {
if data[0] == 0xff {
data = data[1:]
} else {
compression, ok := CompressionByID(uint16(data[0]))
if !ok {
return nil, fmt.Errorf("error decompressing packet: unknown compression algorithm %v", data[0])
}
data, err = compression.Decompress(data[1:])
if err != nil {
return nil, fmt.Errorf("error decompressing packet: %v", err)
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion minecraft/protocol/packet/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ func (encoder *Encoder) Encode(packets [][]byte) error {
}

data := buf.Bytes()
prepend := []byte{header}
if encoder.compression != nil {
prepend = append(prepend, byte(encoder.compression.EncodeCompression()))
var err error
data, err = encoder.compression.Compress(data)
if err != nil {
return fmt.Errorf("error compressing packet: %v", err)
}
}

data = append([]byte{header}, data...)
data = append(prepend, data...)
if encoder.encrypt != nil {
// If the encryption session is not nil, encryption is enabled, meaning we should encrypt the
// compressed data of this packet.
Expand Down
5 changes: 3 additions & 2 deletions minecraft/protocol/packet/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ const (
IDLevelEventGeneric
IDLecternUpdate
_
IDAddEntity
IDRemoveEntity
_
_
IDClientCacheStatus
IDMapCreateLockedCopy
IDOnScreenTextureAnimation
Expand Down Expand Up @@ -208,4 +208,5 @@ const (
IDRefreshEntitlements
IDPlayerToggleCrafterSlotRequest
IDSetPlayerInventoryOptions
IDSetHud
)
4 changes: 4 additions & 0 deletions minecraft/protocol/packet/level_chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type LevelChunk struct {
// Position contains the X and Z coordinates of the chunk sent. You can convert a block coordinate to a chunk
// coordinate by right-shifting it four bits.
Position protocol.ChunkPos
// Dimension is the ID of the dimension that the chunk belongs to. This must always be set otherwise the
// client will always assume the chunk is part of the overworld dimension.
Dimension int32
// HighestSubChunk is the highest sub-chunk at the position that is not all air. It is only set if the
// SubChunkCount is set to protocol.SubChunkRequestModeLimited.
HighestSubChunk uint16
Expand Down Expand Up @@ -46,6 +49,7 @@ func (*LevelChunk) ID() uint32 {

func (pk *LevelChunk) Marshal(io protocol.IO) {
io.ChunkPos(&pk.Position)
io.Varint32(&pk.Dimension)
io.Varuint32(&pk.SubChunkCount)
if pk.SubChunkCount == protocol.SubChunkRequestModeLimited {
io.Uint16(&pk.HighestSubChunk)
Expand Down
238 changes: 121 additions & 117 deletions minecraft/protocol/packet/level_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,123 +7,127 @@ import (

// noinspection SpellCheckingInspection
const (
LevelEventSoundClick = 1000
LevelEventSoundClickFail = 1001
LevelEventSoundLaunch = 1002
LevelEventSoundOpenDoor = 1003
LevelEventSoundFizz = 1004
LevelEventSoundFuse = 1005
LevelEventSoundPlayRecording = 1006
LevelEventSoundGhastWarning = 1007
LevelEventSoundGhastFireball = 1008
LevelEventSoundBlazeFireball = 1009
LevelEventSoundZombieWoodenDoor = 1010
LevelEventSoundZombieDoorCrash = 1012
LevelEventSoundZombieInfected = 1016
LevelEventSoundZombieConverted = 1017
LevelEventSoundEndermanTeleport = 1018
LevelEventSoundAnvilBroken = 1020
LevelEventSoundAnvilUsed = 1021
LevelEventSoundAnvilLand = 1022
LevelEventSoundInfinityArrowPickup = 1030
LevelEventSoundTeleportEnderPearl = 1032
LevelEventSoundAddItem = 1040
LevelEventSoundItemFrameBreak = 1041
LevelEventSoundItemFramePlace = 1042
LevelEventSoundItemFrameRemoveItem = 1043
LevelEventSoundItemFrameRotateItem = 1044
LevelEventSoundExperienceOrbPickup = 1051
LevelEventSoundTotemUsed = 1052
LevelEventSoundArmorStandBreak = 1060
LevelEventSoundArmorStandHit = 1061
LevelEventSoundArmorStandLand = 1062
LevelEventSoundArmorStandPlace = 1063
LevelEventSoundPointedDripstoneLand = 1064
LevelEventSoundDyeUsed = 1065
LevelEventSoundInkSacUsed = 1066
LevelEventSoundAmethystResonate = 1067
LevelEventQueueCustomMusic = 1900
LevelEventPlayCustomMusic = 1901
LevelEventStopCustomMusic = 1902
LevelEventSetMusicVolume = 1903
LevelEventParticlesShoot = 2000
LevelEventParticlesDestroyBlock = 2001
LevelEventParticlesPotionSplash = 2002
LevelEventParticlesEyeOfEnderDeath = 2003
LevelEventParticlesMobBlockSpawn = 2004
LevelEventParticleCropGrowth = 2005
LevelEventParticleSoundGuardianGhost = 2006
LevelEventParticleDeathSmoke = 2007
LevelEventParticleDenyBlock = 2008
LevelEventParticleGenericSpawn = 2009
LevelEventParticlesDragonEgg = 2010
LevelEventParticlesCropEaten = 2011
LevelEventParticlesCritical = 2012
LevelEventParticlesTeleport = 2013
LevelEventParticlesCrackBlock = 2014
LevelEventParticlesBubble = 2015
LevelEventParticlesEvaporate = 2016
LevelEventParticlesDestroyArmorStand = 2017
LevelEventParticlesBreakingEgg = 2018
LevelEventParticleDestroyEgg = 2019
LevelEventParticlesEvaporateWater = 2020
LevelEventParticlesDestroyBlockNoSound = 2021
LevelEventParticlesKnockbackRoar = 2022
LevelEventParticlesTeleportTrail = 2023
LevelEventParticlesPointCloud = 2024
LevelEventParticlesExplosion = 2025
LevelEventParticlesBlockExplosion = 2026
LevelEventParticlesVibrationSignal = 2027
LevelEventParticlesDripstoneDrip = 2028
LevelEventParticlesFizzEffect = 2029
LevelEventWaxOn = 2030
LevelEventWaxOff = 2031
LevelEventScrape = 2032
LevelEventParticlesElectricSpark = 2033
LevelEventParticleTurtleEgg = 2034
LevelEventParticleSculkShriek = 2035
LevelEventSculkCatalystBloom = 2036
LevelEventSculkCharge = 2037
LevelEventSculkChargePop = 2038
LevelEventSonicExplosion = 2039
LevelEventDustPlume = 2040
LevelEventStartRaining = 3001
LevelEventStartThunderstorm = 3002
LevelEventStopRaining = 3003
LevelEventStopThunderstorm = 3004
LevelEventGlobalPause = 3005
LevelEventSimTimeStep = 3006
LevelEventSimTimeScale = 3007
LevelEventActivateBlock = 3500
LevelEventCauldronExplode = 3501
LevelEventCauldronDyeArmor = 3502
LevelEventCauldronCleanArmor = 3503
LevelEventCauldronFillPotion = 3504
LevelEventCauldronTakePotion = 3505
LevelEventCauldronFillWater = 3506
LevelEventCauldronTakeWater = 3507
LevelEventCauldronAddDye = 3508
LevelEventCauldronCleanBanner = 3509
LevelEventCauldronFlush = 3510
LevelEventAgentSpawnEffect = 3511
LevelEventCauldronFillLava = 3512
LevelEventCauldronTakeLava = 3513
LevelEventCauldronFillPowderSnow = 3514
LevelEventCauldronTakePowderSnow = 3515
LevelEventStartBlockCracking = 3600
LevelEventStopBlockCracking = 3601
LevelEventUpdateBlockCracking = 3602
LevelEventParticlesCrackBlockDown = 3603
LevelEventParticlesCrackBlockUp = 3604
LevelEventParticlesCrackBlockNorth = 3605
LevelEventParticlesCrackBlockSouth = 3606
LevelEventParticlesCrackBlockWest = 3607
LevelEventParticlesCrackBlockEast = 3608
LevelEventParticlesShootWhiteSmoke = 3609
LevelEventAllPlayersSleeping = 9800
LevelEventSleepingPlayers = 9801
LevelEventJumpPrevented = 9810
LevelEventParticleLegacyEvent = 0x4000
LevelEventSoundClick = 1000
LevelEventSoundClickFail = 1001
LevelEventSoundLaunch = 1002
LevelEventSoundOpenDoor = 1003
LevelEventSoundFizz = 1004
LevelEventSoundFuse = 1005
LevelEventSoundPlayRecording = 1006
LevelEventSoundGhastWarning = 1007
LevelEventSoundGhastFireball = 1008
LevelEventSoundBlazeFireball = 1009
LevelEventSoundZombieWoodenDoor = 1010
LevelEventSoundZombieDoorCrash = 1012
LevelEventSoundZombieInfected = 1016
LevelEventSoundZombieConverted = 1017
LevelEventSoundEndermanTeleport = 1018
LevelEventSoundAnvilBroken = 1020
LevelEventSoundAnvilUsed = 1021
LevelEventSoundAnvilLand = 1022
LevelEventSoundInfinityArrowPickup = 1030
LevelEventSoundTeleportEnderPearl = 1032
LevelEventSoundAddItem = 1040
LevelEventSoundItemFrameBreak = 1041
LevelEventSoundItemFramePlace = 1042
LevelEventSoundItemFrameRemoveItem = 1043
LevelEventSoundItemFrameRotateItem = 1044
LevelEventSoundExperienceOrbPickup = 1051
LevelEventSoundTotemUsed = 1052
LevelEventSoundArmorStandBreak = 1060
LevelEventSoundArmorStandHit = 1061
LevelEventSoundArmorStandLand = 1062
LevelEventSoundArmorStandPlace = 1063
LevelEventSoundPointedDripstoneLand = 1064
LevelEventSoundDyeUsed = 1065
LevelEventSoundInkSacUsed = 1066
LevelEventSoundAmethystResonate = 1067
LevelEventQueueCustomMusic = 1900
LevelEventPlayCustomMusic = 1901
LevelEventStopCustomMusic = 1902
LevelEventSetMusicVolume = 1903
LevelEventParticlesShoot = 2000
LevelEventParticlesDestroyBlock = 2001
LevelEventParticlesPotionSplash = 2002
LevelEventParticlesEyeOfEnderDeath = 2003
LevelEventParticlesMobBlockSpawn = 2004
LevelEventParticleCropGrowth = 2005
LevelEventParticleSoundGuardianGhost = 2006
LevelEventParticleDeathSmoke = 2007
LevelEventParticleDenyBlock = 2008
LevelEventParticleGenericSpawn = 2009
LevelEventParticlesDragonEgg = 2010
LevelEventParticlesCropEaten = 2011
LevelEventParticlesCritical = 2012
LevelEventParticlesTeleport = 2013
LevelEventParticlesCrackBlock = 2014
LevelEventParticlesBubble = 2015
LevelEventParticlesEvaporate = 2016
LevelEventParticlesDestroyArmorStand = 2017
LevelEventParticlesBreakingEgg = 2018
LevelEventParticleDestroyEgg = 2019
LevelEventParticlesEvaporateWater = 2020
LevelEventParticlesDestroyBlockNoSound = 2021
LevelEventParticlesKnockbackRoar = 2022
LevelEventParticlesTeleportTrail = 2023
LevelEventParticlesPointCloud = 2024
LevelEventParticlesExplosion = 2025
LevelEventParticlesBlockExplosion = 2026
LevelEventParticlesVibrationSignal = 2027
LevelEventParticlesDripstoneDrip = 2028
LevelEventParticlesFizzEffect = 2029
LevelEventWaxOn = 2030
LevelEventWaxOff = 2031
LevelEventScrape = 2032
LevelEventParticlesElectricSpark = 2033
LevelEventParticleTurtleEgg = 2034
LevelEventParticleSculkShriek = 2035
LevelEventSculkCatalystBloom = 2036
LevelEventSculkCharge = 2037
LevelEventSculkChargePop = 2038
LevelEventSonicExplosion = 2039
LevelEventDustPlume = 2040
LevelEventStartRaining = 3001
LevelEventStartThunderstorm = 3002
LevelEventStopRaining = 3003
LevelEventStopThunderstorm = 3004
LevelEventGlobalPause = 3005
LevelEventSimTimeStep = 3006
LevelEventSimTimeScale = 3007
LevelEventActivateBlock = 3500
LevelEventCauldronExplode = 3501
LevelEventCauldronDyeArmor = 3502
LevelEventCauldronCleanArmor = 3503
LevelEventCauldronFillPotion = 3504
LevelEventCauldronTakePotion = 3505
LevelEventCauldronFillWater = 3506
LevelEventCauldronTakeWater = 3507
LevelEventCauldronAddDye = 3508
LevelEventCauldronCleanBanner = 3509
LevelEventCauldronFlush = 3510
LevelEventAgentSpawnEffect = 3511
LevelEventCauldronFillLava = 3512
LevelEventCauldronTakeLava = 3513
LevelEventCauldronFillPowderSnow = 3514
LevelEventCauldronTakePowderSnow = 3515
LevelEventStartBlockCracking = 3600
LevelEventStopBlockCracking = 3601
LevelEventUpdateBlockCracking = 3602
LevelEventParticlesCrackBlockDown = 3603
LevelEventParticlesCrackBlockUp = 3604
LevelEventParticlesCrackBlockNorth = 3605
LevelEventParticlesCrackBlockSouth = 3606
LevelEventParticlesCrackBlockWest = 3607
LevelEventParticlesCrackBlockEast = 3608
LevelEventParticlesShootWhiteSmoke = 3609
LevelEventParticlesWindExplosion = 3610
LevelEventParticlesTrialSpawnerDetection = 3611
LevelEventParticlesTrialSpawnerSpawning = 3612
LevelEventParticlesTrialSpawnerEjecting = 3613
LevelEventAllPlayersSleeping = 9800
LevelEventSleepingPlayers = 9801
LevelEventJumpPrevented = 9810
LevelEventParticleLegacyEvent = 0x4000
)

// LevelEvent is sent by the server to make a certain event in the level occur. It ranges from particles, to
Expand Down
Loading

0 comments on commit b97dc0c

Please sign in to comment.