Skip to content

Commit 01f537c

Browse files
extremeheatrom1504claude
authored
1.21.6 (#3713)
* 1.21.6 * update ci * Update ci.yml to add debug * Fix entity_action packet compatibility for Minecraft 1.21.6 - Update elytra flying to use string mapping 'start_elytra_flying' for 1.21.6+ - Update sprint actions to use string mappings for 1.21.6+ - Move sneak handling to player_input packet for 1.21.6+ - Maintain backward compatibility with older versions using feature detection Fixes compatibility with Minecraft 1.21.6 protocol changes where: - entity_action packets now use string mappers instead of numeric IDs - sneak functionality moved from entity_action to player_input packet Co-authored-by: Claude <noreply@anthropic.com> * fix lint * Update ci.yml * Update team.js Add logging * Update team.js * Update ci.yml remove bail * swtich in team.js * Fix teams * schema updates * Revert "schema updates" This reverts commit 0518d08. * Update ci.yml --------- Co-authored-by: Romain Beaumont <romain.rom1@gmail.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent e3f89d1 commit 01f537c

8 files changed

Lines changed: 86 additions & 55 deletions

File tree

lib/loader.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ function createBot (options = {}) {
7474
const bot = new EventEmitter()
7575
bot._client = options.client
7676
bot.end = (reason) => bot._client.end(reason)
77+
bot._warn = function (...message) {
78+
if (options.hideErrors) return
79+
console.warn('[mineflayer]', ...message)
80+
}
7781
if (options.logErrors) {
7882
bot.on('error', err => {
7983
if (!options.hideErrors) {

lib/plugins/bed.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function inject (bot) {
167167
}
168168

169169
bot._client.on('game_state_change', (packet) => {
170-
if (packet.reason === 0) {
170+
if (packet.reason === 0 || packet.reason === 'no_respawn_block_available') {
171171
// occurs when you can't spawn in your bed and your spawn point gets reset
172172
bot.emit('spawnReset')
173173
}

lib/plugins/game.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ function inject (bot, options) {
116116
})
117117

118118
bot._client.on('game_state_change', (packet) => {
119-
if (packet?.reason === 4 && packet?.gameMode === 1) {
119+
if ((packet.reason === 4 || packet.reason === 'win_game') && packet.gameMode === 1) {
120120
bot._client.write('client_command', { action: 0 })
121121
}
122-
if (packet.reason === 3) {
122+
if ((packet.reason === 3) || (packet.reason === 'change_game_mode')) {
123123
bot.game.gameMode = parseGameMode(packet.gameMode)
124124
bot.emit('game')
125125
}

lib/plugins/physics.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function inject (bot, { physicsEnabled, maxCatchupTicks }) {
232232
}
233233
bot._client.write('entity_action', {
234234
entityId: bot.entity.id,
235-
actionId: 8,
235+
actionId: bot.supportFeature('entityActionUsesStringMapper') ? 'start_elytra_flying' : 8,
236236
jumpBoost: 0
237237
})
238238
}
@@ -247,15 +247,27 @@ function inject (bot, { physicsEnabled, maxCatchupTicks }) {
247247
} else if (control === 'sprint') {
248248
bot._client.write('entity_action', {
249249
entityId: bot.entity.id,
250-
actionId: state ? 3 : 4,
250+
actionId: bot.supportFeature('entityActionUsesStringMapper')
251+
? (state ? 'start_sprinting' : 'stop_sprinting')
252+
: (state ? 3 : 4),
251253
jumpBoost: 0
252254
})
253255
} else if (control === 'sneak') {
254-
bot._client.write('entity_action', {
255-
entityId: bot.entity.id,
256-
actionId: state ? 0 : 1,
257-
jumpBoost: 0
258-
})
256+
if (bot.supportFeature('newPlayerInputPacket')) {
257+
// In 1.21.6+, sneak is handled via player_input packet
258+
bot._client.write('player_input', {
259+
inputs: {
260+
shift: state
261+
}
262+
})
263+
} else {
264+
// Legacy entity_action approach for older versions
265+
bot._client.write('entity_action', {
266+
entityId: bot.entity.id,
267+
actionId: state ? 0 : 1,
268+
jumpBoost: 0
269+
})
270+
}
259271
}
260272
}
261273

lib/plugins/rain.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
module.exports = inject
2+
const states = ['no_respawn_block_available', 'start_raining', 'stop_raining', 'change_game_mode', 'win_game', 'demo_event', 'play_arrow_hit_sound', 'rain_level_change', 'thunder_level_change', 'puffer_fish_sting', 'guardian_elder_effect', 'immediate_respawn', 'limited_crafting', 'level_chunks_load_start']
23

34
function inject (bot) {
45
bot.isRaining = false
56
bot.thunderState = 0
67
bot.rainState = 0
78
bot._client.on('game_state_change', (packet) => {
8-
if (packet.reason === 1) {
9+
const reason = states[packet.reason] ?? packet.reason
10+
if (reason === 'start_raining') {
911
bot.isRaining = true
1012
bot.emit('rain')
11-
} else if (packet.reason === 2) {
13+
} else if (reason === 'stop_raining') {
1214
bot.isRaining = false
1315
bot.emit('rain')
14-
} else if (packet.reason === 7) {
16+
} else if (reason === 'rain_level_change') {
1517
bot.rainState = packet.gameMode
1618
bot.emit('weatherUpdate')
17-
} else if (packet.reason === 8) {
19+
} else if (reason === 'thunder_level_change') {
1820
bot.thunderState = packet.gameMode
1921
bot.emit('weatherUpdate')
2022
}

lib/plugins/team.js

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,49 @@
11
module.exports = inject
22

3+
// TODO: apply this to all versions and rename scoreboard_team -> teams in minecraft-data
4+
const TEAM_MODES = ['add', 'remove', 'change', 'join', 'leave']
5+
36
function inject (bot) {
47
const Team = require('../team')(bot.registry)
58
const teams = {}
69

710
function teamHandler (packet) {
8-
const { team: teamName, mode } = packet
11+
const { team: teamName, players = [] } = packet
12+
const mode = typeof packet.mode === 'number' ? TEAM_MODES[packet.mode] : packet.mode
13+
914
let team = teams[teamName]
10-
if (mode === 0) {
11-
team = new Team(
12-
packet.team,
13-
packet.name,
14-
packet.friendlyFire,
15-
packet.nameTagVisibility,
16-
packet.collisionRule,
17-
packet.formatting,
18-
packet.prefix,
19-
packet.suffix
20-
)
21-
if (Array.isArray(packet.players)) {
22-
packet.players.forEach(player => {
15+
16+
switch (mode) {
17+
case 'add':
18+
team = new Team(
19+
teamName,
20+
packet.name,
21+
packet.friendlyFire,
22+
packet.nameTagVisibility,
23+
packet.collisionRule,
24+
packet.formatting,
25+
packet.prefix,
26+
packet.suffix
27+
)
28+
for (const player of players) {
2329
team.add(player)
2430
bot.teamMap[player] = team
25-
})
26-
}
27-
teams[teamName] = team
28-
bot.emit('teamCreated', teams[teamName])
29-
}
30-
if (team !== undefined) {
31-
if (mode === 1) {
32-
team.members.forEach(member => {
31+
}
32+
teams[teamName] = team
33+
bot.emit('teamCreated', teams[teamName])
34+
break
35+
36+
case 'remove':
37+
if (!team) break
38+
team.members.forEach((member) => {
3339
delete bot.teamMap[member]
3440
})
3541
delete teams[teamName]
3642
bot.emit('teamRemoved', teams[teamName])
37-
}
38-
if (mode === 2) {
43+
break
44+
45+
case 'change':
46+
if (!team) break
3947
team.update(
4048
packet.name,
4149
packet.friendlyFire,
@@ -46,23 +54,28 @@ function inject (bot) {
4654
packet.suffix
4755
)
4856
bot.emit('teamUpdated', teams[teamName])
49-
}
50-
if (Array.isArray(packet.players)) {
51-
if (mode === 3) {
52-
packet.players.forEach((player) => {
53-
team.add(player)
54-
bot.teamMap[player] = team
55-
})
56-
bot.emit('teamMemberAdded', teams[teamName])
57+
break
58+
59+
case 'join':
60+
if (!team) break
61+
for (const player of players) {
62+
team.add(player)
63+
bot.teamMap[player] = team
5764
}
58-
if (mode === 4) {
59-
packet.players.forEach((player) => {
60-
team.remove(player)
61-
delete bot.teamMap[player]
62-
})
63-
bot.emit('teamMemberRemoved', teams[teamName])
65+
bot.emit('teamMemberAdded', teams[teamName])
66+
break
67+
68+
case 'leave':
69+
if (!team) break
70+
for (const player of players) {
71+
team.remove(player)
72+
delete bot.teamMap[player]
6473
}
65-
}
74+
bot.emit('teamMemberRemoved', teams[teamName])
75+
break
76+
77+
default:
78+
bot._warn(`Unknown team mode handling team update: ${mode}`)
6679
}
6780
}
6881

lib/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const testedVersions = ['1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20.1', '1.20.2', '1.20.4', '1.20.6', '1.21.1', '1.21.3', '1.21.4', '1.21.5']
1+
const testedVersions = ['1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20.1', '1.20.2', '1.20.4', '1.20.6', '1.21.1', '1.21.3', '1.21.4', '1.21.5', '1.21.6']
22
module.exports = {
33

44
testedVersions,

test/externalTests/trade.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = () => async (bot) => {
4242

4343
const villager = await bot.openVillager(entity)
4444
console.log('Opened villager')
45-
console.dir(villager, { depth: null })
45+
// console.dir(villager, { depth: null })
4646

4747
// Handle trade #1 -- takes 2x emerald and returns 2x pumpkin_pie
4848
{

0 commit comments

Comments
 (0)