Skip to content

Commit eeb5e47

Browse files
1.21.60 support (#570)
* Add support for ItemRegistryPacket (for shield item ID) * simplify * lint * internal test * update start_game handling * test: capture events rejections --------- Co-authored-by: extremeheat <[email protected]>
1 parent 2d7d32d commit eeb5e47

File tree

7 files changed

+24
-8
lines changed

7 files changed

+24
-8
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Minecraft Bedrock Edition (aka MCPE) protocol library, supporting authentication
1111

1212
## Features
1313

14-
- Supports Minecraft Bedrock version 1.16.201, 1.16.210, 1.16.220, 1.17.0, 1.17.10, 1.17.30, 1.17.40, 1.18.0, 1.18.11, 1.18.30, 1.19.1, 1.19.10, 1.19.20, 1.19.21, 1.19.30, 1.19.40, 1.19.41, 1.19.50, 1.19.60, 1.19.62, 1.19.63, 1.19.70, 1.19.80, 1.20.0, 1.20.10, 1.20.30, 1.20.40, 1.20.50, 1.20.61, 1.20.71, 1.20.80, 1.21.0, 1.21.2, 1.21.21, 1.21.30, 1.21.42, 1.21.50
14+
- Supports Minecraft Bedrock version 1.16.201, 1.16.210, 1.16.220, 1.17.0, 1.17.10, 1.17.30, 1.17.40, 1.18.0, 1.18.11, 1.18.30, 1.19.1, 1.19.10, 1.19.20, 1.19.21, 1.19.30, 1.19.40, 1.19.41, 1.19.50, 1.19.60, 1.19.62, 1.19.63, 1.19.70, 1.19.80, 1.20.0, 1.20.10, 1.20.30, 1.20.40, 1.20.50, 1.20.61, 1.20.71, 1.20.80, 1.21.0, 1.21.2, 1.21.21, 1.21.30, 1.21.42, 1.21.50, 1.21.60
1515
- Parse and serialize packets as JavaScript objects
1616
- Automatically respond to keep-alive packets
1717
- [Proxy and mitm connections](docs/API.md#proxy-docs)

index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Realm } from 'prismarine-realms'
33
import { ServerDeviceCodeResponse } from 'prismarine-auth'
44

55
declare module 'bedrock-protocol' {
6-
type Version = '1.21.42' | '1.21.30' | '1.21.2' | '1.21.0' | '1.20.80' | '1.20.71' | '1.20.61' | '1.20.50' | '1.20.40' | '1.20.30' | '1.20.10' | '1.20.0' | '1.19.80' | '1.19.70' | '1.19.63' | '1.19.62' | '1.19.60' | '1.19.51' | '1.19.50' | '1.19.41' | '1.19.40' | '1.19.31' | '1.19.30' | '1.19.22' | '1.19.21' | '1.19.20' | '1.19.11' | '1.19.10' | '1.19.2' | '1.19.1' | '1.18.31' | '1.18.30' | '1.18.12' | '1.18.11' | '1.18.10' | '1.18.2' | '1.18.1' | '1.18.0' | '1.17.41' | '1.17.40' | '1.17.34' | '1.17.30' | '1.17.11' | '1.17.10' | '1.17.0' | '1.16.220' | '1.16.210' | '1.16.201'
6+
type Version = '1.21.60' | '1.21.50' | '1.21.42' | '1.21.30' | '1.21.2' | '1.21.0' | '1.20.80' | '1.20.71' | '1.20.61' | '1.20.50' | '1.20.40' | '1.20.30' | '1.20.10' | '1.20.0' | '1.19.80' | '1.19.70' | '1.19.63' | '1.19.62' | '1.19.60' | '1.19.51' | '1.19.50' | '1.19.41' | '1.19.40' | '1.19.31' | '1.19.30' | '1.19.22' | '1.19.21' | '1.19.20' | '1.19.11' | '1.19.10' | '1.19.2' | '1.19.1' | '1.18.31' | '1.18.30' | '1.18.12' | '1.18.11' | '1.18.10' | '1.18.2' | '1.18.1' | '1.18.0' | '1.17.41' | '1.17.40' | '1.17.34' | '1.17.30' | '1.17.11' | '1.17.10' | '1.17.0' | '1.16.220' | '1.16.210' | '1.16.201'
77

88
export interface Options {
99
// The string version to start the client or server as

src/client.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class Client extends Connection {
6161
try {
6262
const mcData = require('minecraft-data')('bedrock_' + this.options.version)
6363
this.features = {
64-
compressorInHeader: mcData.supportFeature('compressorInPacketHeader')
64+
compressorInHeader: mcData.supportFeature('compressorInPacketHeader'),
65+
itemRegistryPacket: mcData.supportFeature('itemRegistryPacket')
6566
}
6667
} catch (e) {
6768
throw new Error(`Unsupported version: '${this.options.version}', no data available`)
@@ -241,7 +242,9 @@ class Client extends Connection {
241242
break
242243
case 'start_game':
243244
this.startGameData = pakData.params
244-
this.startGameData.itemstates.forEach(state => {
245+
// fallsthrough
246+
case 'item_registry': // 1.21.60+ send itemstates in item_registry packet
247+
pakData.params.itemstates?.forEach(state => {
245248
if (state.name === 'minecraft:shield') {
246249
this.serializer.proto.setVariable('ShieldItemID', state.runtime_id)
247250
this.deserializer.proto.setVariable('ShieldItemID', state.runtime_id)

src/connection.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,17 @@ class Connection extends EventEmitter {
7070
}
7171
}
7272

73+
_processOutbound (name, params) {
74+
if (name === 'item_registry') {
75+
this.updateItemPalette(params.itemstates)
76+
} else if (name === 'start_game' && params.itemstates) {
77+
this.updateItemPalette(params.itemstates)
78+
}
79+
}
80+
7381
write (name, params) {
7482
this.outLog?.(name, params)
75-
if (name === 'start_game') this.updateItemPalette(params.itemstates)
83+
this._processOutbound(name, params)
7684
const batch = new Framer(this)
7785
const packet = this.serializer.createPacketBuffer({ name, params })
7886
batch.addEncodedPacket(packet)
@@ -86,7 +94,7 @@ class Connection extends EventEmitter {
8694

8795
queue (name, params) {
8896
this.outLog?.('Q <- ', name, params)
89-
if (name === 'start_game') this.updateItemPalette(params.itemstates)
97+
this._processOutbound(name, params)
9098
const packet = this.serializer.createPacketBuffer({ name, params })
9199
if (name === 'level_chunk') {
92100
// Skip queue, send ASAP

src/options.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const mcData = require('minecraft-data')
33
// Minimum supported version (< will be kicked)
44
const MIN_VERSION = '1.16.201'
55
// Currently supported verson. Note, clients with newer versions can still connect as long as data is in minecraft-data
6-
const CURRENT_VERSION = '1.21.50'
6+
const CURRENT_VERSION = '1.21.60'
77

88
const Versions = Object.fromEntries(mcData.versions.bedrock.filter(e => e.releaseType === 'release').map(e => [e.minecraftVersion, e.version]))
99

test/internal.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ async function startTest (version = CURRENT_VERSION, ok) {
6363
// client.queue('inventory_transaction', get('packets/inventory_transaction.json'))
6464
client.queue('player_list', get('packets/player_list.json'))
6565
client.queue('start_game', get('packets/start_game.json'))
66-
client.queue('item_component', { entries: [] })
66+
if (client.versionLessThan('1.21.60')) {
67+
client.queue('item_component', { entries: [] })
68+
} else {
69+
client.queue('item_registry', get('packets/item_registry.json'))
70+
}
6771
client.queue('set_spawn_position', get('packets/set_spawn_position.json'))
6872
client.queue('set_time', { time: 5433771 })
6973
client.queue('set_difficulty', { difficulty: 1 })

test/internal.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const { timedTest } = require('./internal')
44
const { testedVersions } = require('../src/options')
55
const { sleep } = require('../src/datatypes/util')
6+
require('events').captureRejections = true
67

78
describe('internal client/server test', function () {
89
const vcount = testedVersions.length

0 commit comments

Comments
 (0)