Skip to content

Commit f0afaf7

Browse files
rom1504botgithub-actions[bot]rom1504extremeheatSuperGamerTron
authored
🎈 1.21.9/1.21.10 support (#3754)
* Update to version 1.21.9 * Fix branch name in minecraft-data clone command * 1.21.9: velocity field changes (#3807) * Update to version 1.21.10 * Update ci.yml * Update ci.yml * Update package.json * Update velocity handling in entities.js plugin and internalTest.js to use new feature * Update spawn_point.js plugin to use new feature * Fix incrorrect event listener in nether.js test * Add delays to flaky tests * Use new gamerule to prevent monsters spawning during tests and killing the bot * Update ci.yml * Update package.json * remove feature flags on packet writes * rename .movement to .velocity * Update entities.js --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: extremeheat <extreme@protonmail.ch> * fix version check * ver fix * update internaltest * add clearInventory delay * Update ci.yml * Update minecraft-protocol dependency version --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Romain Beaumont <romain.rom1@gmail.com> Co-authored-by: extremeheat <extreme@protonmail.ch> Co-authored-by: SuperGamerTron <45374546+SuperGamerTron@users.noreply.github.com>
1 parent e5fcf1f commit f0afaf7

14 files changed

Lines changed: 33 additions & 8 deletions

File tree

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ First time using Node.js? You may want to start with the [tutorial](tutorial.md)
1717

1818
## Features
1919

20-
* Supports Minecraft 1.8 to 1.21.8 (1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19, 1.20, 1.21.8) <!--version-->
20+
* Supports Minecraft 1.8 to 1.21.9 (1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19, 1.20, 1.21, 1.21.9) <!--version-->
2121
* Entity knowledge and tracking.
2222
* Block knowledge. You can query the world around you. Milliseconds to find any block.
2323
* Physics and movement - handle all bounding boxes

lib/loader.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const plugins = {
4747

4848
const minecraftData = require('minecraft-data')
4949
const { testedVersions, latestSupportedVersion, oldestSupportedVersion } = require('./version')
50+
const latestSupportedProtocolVersion = minecraftData.versionsByMinecraftVersion.pc[latestSupportedVersion].version
51+
if (!latestSupportedProtocolVersion) throw new Error(`Version '${latestSupportedVersion}' not supported by minecraft-data - is it up to date?`)
5052

5153
module.exports = {
5254
createBot,
@@ -118,7 +120,7 @@ function createBot (options = {}) {
118120
if (!bot.registry?.version) throw new Error(`Server version '${serverPingVersion}' is not supported, no data for version`)
119121

120122
const versionData = bot.registry.version
121-
if (versionData['>'](latestSupportedVersion)) {
123+
if (versionData['>'](latestSupportedVersion) && (versionData.version !== latestSupportedProtocolVersion)) {
122124
throw new Error(`Server version '${serverPingVersion}' is not supported. Latest supported version is '${latestSupportedVersion}'.`)
123125
} else if (versionData['<'](oldestSupportedVersion)) {
124126
throw new Error(`Server version '${serverPingVersion}' is not supported. Oldest supported version is '${oldestSupportedVersion}'.`)

lib/plugins/entities.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,12 @@ function inject (bot) {
271271
entity.pitch = conv.fromNotchianPitchByte(packet.pitch)
272272
entity.headPitch = conv.fromNotchianPitchByte(packet.headPitch)
273273

274-
const notchVel = new Vec3(packet.velocityX, packet.velocityY, packet.velocityZ)
274+
let notchVel
275+
if (bot.supportFeature('entityVelocityIsLpVec3')) {
276+
notchVel = new Vec3(packet.velocity.x, packet.velocity.y, packet.velocity.z)
277+
} else {
278+
notchVel = new Vec3(packet.velocityX, packet.velocityY, packet.velocityZ)
279+
}
275280
entity.velocity.update(conv.fromNotchVelocity(notchVel))
276281
entity.metadata = parseMetadata(packet.metadata, entity.metadata)
277282

@@ -281,7 +286,12 @@ function inject (bot) {
281286
bot._client.on('entity_velocity', (packet) => {
282287
// entity velocity
283288
const entity = fetchEntity(packet.entityId)
284-
const notchVel = new Vec3(packet.velocityX, packet.velocityY, packet.velocityZ)
289+
let notchVel
290+
if (bot.supportFeature('entityVelocityIsLpVec3')) {
291+
notchVel = new Vec3(packet.velocity.x, packet.velocity.y, packet.velocity.z)
292+
} else {
293+
notchVel = new Vec3(packet.velocityX, packet.velocityY, packet.velocityZ)
294+
}
285295
entity.velocity.update(conv.fromNotchVelocity(notchVel))
286296
})
287297

lib/plugins/spawn_point.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ module.exports = inject
55
function inject (bot) {
66
bot.spawnPoint = new Vec3(0, 0, 0)
77
bot._client.on('spawn_position', (packet) => {
8-
bot.spawnPoint = new Vec3(packet.location.x, packet.location.y, packet.location.z)
8+
const pos = bot.supportFeature('spawnPositionIsGlobal') ? packet.globalPos.location : packet.location
9+
bot.spawnPoint = new Vec3(pos.x, pos.y, pos.z)
910
bot.emit('game')
1011
})
1112
}

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.21.6', '1.21.8']
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', '1.21.8', '1.21.9']
22
module.exports = {
33

44
testedVersions,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"license": "MIT",
2323
"dependencies": {
2424
"minecraft-data": "^3.98.0",
25-
"minecraft-protocol": "^1.61.0",
25+
"minecraft-protocol": "^1.63.0",
2626
"prismarine-biome": "^1.1.1",
2727
"prismarine-block": "^1.22.0",
2828
"prismarine-chat": "^1.7.1",

test/externalTest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ for (const supportedVersion of mineflayer.testedVersions) {
6868
bot.once('spawn', () => {
6969
console.log('bot spawned, opping...')
7070
wrap.writeServer('op flatbot\n')
71+
wrap.writeServer('gamerule spawnMonsters false\n')
7172
bot.once('messagestr', msg => {
7273
if (msg.includes('Made flatbot a server operator') || msg === '[Server: Opped flatbot]') {
7374
done()

test/externalTests/crafting.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ module.exports = () => async (bot) => {
5353
await bot.test.setBlock({ x: 1, y: 0, z: 0, relative: true, blockName: 'crafting_table' })
5454
bot.chat('/give @p stick 7')
5555
await once(bot.inventory, 'updateSlot')
56+
await bot.test.wait(500)
5657
const craftingTable = bot.findBlock({ matching: blocksByName.crafting_table.id })
5758
await bot.craft(bot.recipesFor(itemsByName.ladder.id, null, null, true)[0], 1, craftingTable)
5859
}

test/externalTests/enchanting.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ module.exports = () => async (bot) => {
5454

5555
console.log('Table ready')
5656
await enchantingTable.enchant(enchantSlot)
57+
await bot.test.wait(500)
5758
const result = await enchantingTable.takeTargetItem()
5859

5960
assert.notStrictEqual(result.nbt, undefined)

test/externalTests/nether.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = () => async (bot) => {
1313
assert.notStrictEqual(signItem, null)
1414

1515
const p = new Promise((resolve, reject) => {
16-
bot._client.on('open_sign_entity', (packet) => {
16+
bot._client.once('open_sign_entity', (packet) => {
1717
console.log('Open sign', packet)
1818
const sign = bot.blockAt(new Vec3(packet.location))
1919
bot.updateSign(sign, '1\n2\n3\n')

0 commit comments

Comments
 (0)