@@ -25,8 +25,14 @@ function inject (bot, options) {
25
25
function handleRespawnPacketData ( packet ) {
26
26
bot . game . levelType = packet . levelType ?? ( packet . isFlat ? 'flat' : 'default' )
27
27
bot . game . hardcore = packet . isHardcore ?? Boolean ( packet . gameMode & 0b100 )
28
- bot . game . gameMode = parseGameMode ( packet . gameMode )
29
- if ( bot . supportFeature ( 'dimensionIsAnInt' ) ) {
28
+ bot . game . gameMode = packet . gamemode || parseGameMode ( packet . gameMode )
29
+ if ( bot . supportFeature ( 'segmentedRegistryCodecData' ) ) { // 1.20.5
30
+ if ( typeof packet . dimension === 'number' ) {
31
+ bot . game . dimension = bot . registry . dimensionsArray [ packet . dimension ] ?. name ?. replace ( 'minecraft:' , '' )
32
+ } else if ( typeof packet . dimension === 'string' ) { // iirc, in 1.21 it's back to a string
33
+ bot . game . dimension = packet . dimension . replace ( 'minecraft:' , '' )
34
+ }
35
+ } else if ( bot . supportFeature ( 'dimensionIsAnInt' ) ) {
30
36
bot . game . dimension = dimensionNames [ packet . dimension ]
31
37
} else if ( bot . supportFeature ( 'dimensionIsAString' ) ) {
32
38
bot . game . dimension = packet . dimension . replace ( 'minecraft:' , '' )
@@ -40,25 +46,25 @@ function inject (bot, options) {
40
46
bot . registry . loadDimensionCodec ( packet . dimensionCodec )
41
47
}
42
48
49
+ bot . game . minY = 0
50
+ bot . game . height = 256
51
+
43
52
if ( bot . supportFeature ( 'dimensionDataInCodec' ) ) { // 1.19+
44
- if ( packet . worldType ) { // login
53
+ // pre 1.20.5 before we consolidated login and respawn's SpawnInfo structure into one type,
54
+ // "dimension" was called "worldType" in login_packet's payload but not respawn.
55
+ if ( packet . worldType && ! bot . game . dimension ) {
45
56
bot . game . dimension = packet . worldType . replace ( 'minecraft:' , '' )
46
- const { minY, height } = bot . registry . dimensionsByName [ bot . game . dimension ]
47
- bot . game . minY = minY
48
- bot . game . height = height
49
- } else if ( packet . dimension ) { // respawn
50
- bot . game . dimension = packet . dimension . replace ( 'minecraft:' , '' )
51
- const { minY, height } = bot . registry . dimensionsByName [ bot . game . dimension ]
52
- bot . game . minY = minY
53
- bot . game . height = height
57
+ }
58
+ console . log ( '*Dimension data' , bot . game . dimension , bot . registry . dimensionsByName , packet )
59
+ const dimData = bot . registry . dimensionsByName [ bot . game . dimension ]
60
+ if ( dimData ) {
61
+ bot . game . minY = dimData . minY
62
+ bot . game . height = dimData . height
54
63
}
55
64
} else if ( bot . supportFeature ( 'dimensionDataIsAvailable' ) ) { // 1.18
56
65
const dimensionData = nbt . simplify ( packet . dimension )
57
66
bot . game . minY = dimensionData . min_y
58
67
bot . game . height = dimensionData . height
59
- } else {
60
- bot . game . minY = 0
61
- bot . game . height = 256
62
68
}
63
69
64
70
if ( packet . difficulty ) {
@@ -73,11 +79,12 @@ function inject (bot, options) {
73
79
74
80
// 1.20.2
75
81
bot . _client . on ( 'registry_data' , ( packet ) => {
76
- bot . registry . loadDimensionCodec ( packet . codec )
82
+ console . log ( 'Loading Dimension Codec' , JSON . stringify ( packet ) . slice ( 0 , 100 ) )
83
+ bot . registry . loadDimensionCodec ( packet . codec || packet )
77
84
} )
78
85
79
86
bot . _client . on ( 'login' , ( packet ) => {
80
- handleRespawnPacketData ( packet )
87
+ handleRespawnPacketData ( packet . worldState || packet )
81
88
82
89
bot . game . maxPlayers = packet . maxPlayers
83
90
if ( packet . enableRespawnScreen ) {
@@ -95,7 +102,8 @@ function inject (bot, options) {
95
102
} )
96
103
97
104
bot . _client . on ( 'respawn' , ( packet ) => {
98
- handleRespawnPacketData ( packet )
105
+ // in 1.20.5+ protocol we move the shared spawn data into one SpawnInfo type under .worldState
106
+ handleRespawnPacketData ( packet . worldState || packet )
99
107
bot . emit ( 'game' )
100
108
} )
101
109
0 commit comments