From 9c0244c8692c4137a600d8cf2d0e1106c20b37d8 Mon Sep 17 00:00:00 2001 From: extremeheat Date: Tue, 2 Jul 2024 06:59:06 +0000 Subject: [PATCH] 1.20.5 --- .github/workflows/ci.yml | 1 + docs/README.md | 2 +- lib/plugins/breath.js | 21 +++++++++++---------- lib/plugins/entities.js | 5 +++++ lib/plugins/fishing.js | 9 +++++++-- lib/plugins/game.js | 5 +++-- 6 files changed, 28 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dbcffcf15..477c0f7f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,5 +56,6 @@ jobs: java-package: jre - name: Install Dependencies run: npm install + - run: cd node_modules && cd minecraft-data && mv minecraft-data minecraft-data-old && git clone -b 1.20.5protocol https://github.com/extremeheat/minecraft-data/ --depth 1 && node bin/generate_data.js - name: Start Tests run: npm run mocha_test -- -g ${{ matrix.mcVersion }}v diff --git a/docs/README.md b/docs/README.md index 1888ce4d1..20c179e77 100644 --- a/docs/README.md +++ b/docs/README.md @@ -17,7 +17,7 @@ First time using Node.js? You may want to start with the [tutorial](tutorial.md) ## Features - * Supports Minecraft 1.8 to 1.20.4 (1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19 and 1.20) + * Supports Minecraft 1.8 to 1.20.5 (1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19 and 1.20 upto 1.20.5) * Entity knowledge and tracking. * Block knowledge. You can query the world around you. Milliseconds to find any block. * Physics and movement - handle all bounding boxes diff --git a/lib/plugins/breath.js b/lib/plugins/breath.js index a112b99fc..253dbfe83 100644 --- a/lib/plugins/breath.js +++ b/lib/plugins/breath.js @@ -1,17 +1,18 @@ module.exports = inject function inject (bot) { + if (bot.supportFeature('mcDataHasEntityMetadata')) { + // this is handled inside entities.js. We don't yet have entity metadataKeys for all versions but once we do + // we can delete the numerical checks here and in entities.js https://github.com/extremeheat/mineflayer/blob/eb9982aa04973b0086aac68a2847005d77f01a3d/lib/plugins/entities.js#L469 + return + } bot._client.on('entity_metadata', (packet) => { - if (!bot?.entity?.id === packet?.entityId) return - if (packet?.metadata[1]?.key === 1) { - if (!packet?.metadata[1]?.value) return - bot.oxygenLevel = Math.round(packet.metadata[1].value / 15) - bot.emit('breath') - } - if (packet?.metadata[0]?.key === 1) { - if (!packet?.metadata[0]?.value) return - bot.oxygenLevel = Math.round(packet.metadata[0].value / 15) - bot.emit('breath') + if (bot.entity.id !== packet.entityId) return + for (const metadata of packet.metadata) { + if (metadata.key === 1) { + bot.oxygenLevel = Math.round(packet.metadata[1].value / 15) + bot.emit('breath') + } } }) } diff --git a/lib/plugins/entities.js b/lib/plugins/entities.js index e5eb918f4..90e805244 100644 --- a/lib/plugins/entities.js +++ b/lib/plugins/entities.js @@ -460,6 +460,11 @@ function inject (bot) { bot.emit('entityUncrouch', entity) } } + + // Breathing (formerly in breath.js) + if (metas.air_supply != null) { + bot.oxygenLevel = Math.round(metas.air_supply / 15) + } } else { const typeSlot = (bot.supportFeature('itemsAreAlsoBlocks') ? 5 : 6) + (bot.supportFeature('entityMetadataHasLong') ? 1 : 0) const slot = packet.metadata.find(e => e.type === typeSlot) diff --git a/lib/plugins/fishing.js b/lib/plugins/fishing.js index 3a965a61d..d0594f07d 100644 --- a/lib/plugins/fishing.js +++ b/lib/plugins/fishing.js @@ -25,8 +25,13 @@ function inject (bot) { if (!lastBobber || fishingTask.done) return const pos = lastBobber.position - const parts = bot.registry.particlesByName - if (packet.particleId === (parts?.fishing ?? parts.bubble).id && packet.particles === 6 && pos.distanceTo(new Vec3(packet.x, pos.y, packet.z)) <= 1.23) { + + const bobberCondition = bot.registry.supportFeature('updatedParticlesPacket') + ? ((packet.particle.type === 'fishing' || packet.particle.type === 'bubble') && packet.amount === 6 && pos.distanceTo(new Vec3(packet.x, pos.y, packet.z)) <= 1.23) + // This "(fishing ?? bubble).id" condition doesn't make sense + : (packet.particleId === (bot.registry.particlesByName.fishing ?? bot.registry.particlesByName.bubble).id && packet.particles === 6 && pos.distanceTo(new Vec3(packet.x, pos.y, packet.z)) <= 1.23) + + if (bobberCondition) { bot.activateItem() lastBobber = undefined fishingTask.finish() diff --git a/lib/plugins/game.js b/lib/plugins/game.js index 4006d145f..03444802f 100644 --- a/lib/plugins/game.js +++ b/lib/plugins/game.js @@ -77,7 +77,7 @@ function inject (bot, options) { }) bot._client.on('login', (packet) => { - handleRespawnPacketData(packet) + handleRespawnPacketData(packet.worldState || packet) bot.game.maxPlayers = packet.maxPlayers if (packet.enableRespawnScreen) { @@ -95,7 +95,8 @@ function inject (bot, options) { }) bot._client.on('respawn', (packet) => { - handleRespawnPacketData(packet) + // in 1.20.5+ protocol we move the shared data into one WorldState type + handleRespawnPacketData(packet.worldState || packet) bot.emit('game') })