Skip to content

Commit

Permalink
1.20.5
Browse files Browse the repository at this point in the history
  • Loading branch information
extremeheat committed Jul 2, 2024
1 parent eb9982a commit a84ddcb
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 28 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 21 additions & 9 deletions lib/particle.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = loader
function loader (registry) {
class Particle {
constructor (id, position, offset, count = 1, movementSpeed = 0, longDistanceRender = false) {
Object.assign(this, registry.particles[id])
Object.assign(this, registry.particles[id] || registry.particlesByName[id])
this.id = id
this.position = position
this.offset = offset
Expand All @@ -15,14 +15,26 @@ function loader (registry) {
}

static fromNetwork (packet) {
return new Particle(
packet.particleId,
new Vec3(packet.x, packet.y, packet.z),
new Vec3(packet.offsetX, packet.offsetY, packet.offsetZ),
packet.particles,
packet.particleData,
packet.longDistance
)
if (registry.supportFeature('updatedParticlesPacket')) {
// TODO: We add extra data that's inside packet.particle.data that varies by the particle's .type
return new Particle(
packet.particle.type,
new Vec3(packet.x, packet.y, packet.z),
new Vec3(packet.offsetX, packet.offsetY, packet.offsetZ),
packet.amount,
packet.velocityOffset,
packet.longDistance
)
} else {
return new Particle(
packet.particleId,
new Vec3(packet.x, packet.y, packet.z),
new Vec3(packet.offsetX, packet.offsetY, packet.offsetZ),
packet.particles,
packet.particleData,
packet.longDistance
)
}
}
}

Expand Down
21 changes: 11 additions & 10 deletions lib/plugins/breath.js
Original file line number Diff line number Diff line change
@@ -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')
}
}
})
}
5 changes: 5 additions & 0 deletions lib/plugins/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions lib/plugins/fishing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 "(particles.fishing ?? particles.bubble).id" condition doesn't make sense (these are both valid types)
: (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()
Expand Down
11 changes: 7 additions & 4 deletions lib/plugins/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ function inject (bot, options) {
}

if (bot.supportFeature('dimensionDataInCodec')) { // 1.19+
if (packet.worldType) { // login
// pre 1.20.5 before we consolidated login and respawn's SpawnInfo structure into one type,
// "dimension" was called "worldType" in login_packet's payload but not respawn.
if (packet.worldType) {
bot.game.dimension = packet.worldType.replace('minecraft:', '')
const { minY, height } = bot.registry.dimensionsByName[bot.game.dimension]
bot.game.minY = minY
bot.game.height = height
} else if (packet.dimension) { // respawn
} else if (packet.dimension) {
bot.game.dimension = packet.dimension.replace('minecraft:', '')
const { minY, height } = bot.registry.dimensionsByName[bot.game.dimension]
bot.game.minY = minY
Expand Down Expand Up @@ -77,7 +79,7 @@ function inject (bot, options) {
})

bot._client.on('login', (packet) => {
handleRespawnPacketData(packet)
handleRespawnPacketData(packet.worldState || packet)

bot.game.maxPlayers = packet.maxPlayers
if (packet.enableRespawnScreen) {
Expand All @@ -95,7 +97,8 @@ function inject (bot, options) {
})

bot._client.on('respawn', (packet) => {
handleRespawnPacketData(packet)
// in 1.20.5+ protocol we move the shared spawn data into one SpawnInfo type under .worldState
handleRespawnPacketData(packet.worldState || packet)
bot.emit('game')
})

Expand Down
2 changes: 1 addition & 1 deletion lib/version.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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']
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.5']
module.exports = {

testedVersions,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"license": "MIT",
"dependencies": {
"minecraft-data": "^3.56.0",
"minecraft-protocol": "^1.47.0",
"minecraft-protocol": "github:extremeheat/node-minecraft-protocol#1.20.5",
"prismarine-biome": "^1.1.1",
"prismarine-block": "^1.17.0",
"prismarine-chat": "^1.7.1",
Expand Down

0 comments on commit a84ddcb

Please sign in to comment.