diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2023-02-16 23:25:18 +0100 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2023-02-16 23:25:18 +0100 |
commit | c845161f10a40f9b6a73e32e2224a3b7a685f650 (patch) | |
tree | 1a42c6065ae6a23521c8608e505c97e17526fd25 | |
parent | Initial commit (diff) | |
download | mineflayer-antihunger-c845161f10a40f9b6a73e32e2224a3b7a685f650.tar.gz mineflayer-antihunger-c845161f10a40f9b6a73e32e2224a3b7a685f650.tar.bz2 mineflayer-antihunger-c845161f10a40f9b6a73e32e2224a3b7a685f650.zip |
Make antihunger work when breaking/falling
Some changes were indeed needed :)
-rw-r--r-- | index.js | 54 | ||||
-rw-r--r-- | package.json | 2 |
2 files changed, 40 insertions, 16 deletions
diff --git a/index.js b/index.js index e5d23d9..7b654da 100644 --- a/index.js +++ b/index.js @@ -1,20 +1,44 @@ exports.plugin = (bot) => { - var originalFunction = bot._client.write; + var originalFunction = bot._client.write; - // Create a new function that wraps the original function - var newFunction = function (name, params) { - if (name === "entity_action") { - if (params.actionId === 3 || params.actionId === 4) { - // cancel sprint start and sprint stop packets - return; - } - } - if (params.onGround !== undefined) { - params.onGround = false - } - return originalFunction.apply(this, [...arguments]) + // Create a new function that wraps the original function + var newFunction = function (name, params) { + if (name === "entity_action") { + if (params.actionId === 3 || params.actionId === 4) { + // cancel sprint start and sprint stop packets + return; + } } + if (params.onGround !== undefined) { + if (bot.targetDigBlock === null && yDistanceFallen <= 0.0) { + params.onGround = false + } + else + params.onGround = true + } + return originalFunction.apply(this, [...arguments]) + } + + // Replace the original function with the new function + bot._client.write = newFunction; + + let startingFallingPosition = null + let yDistanceFallen = 0.0 + bot.on('move', () => { + //we are falling (or going up) + if (bot.entity.onGround === false) { + //console.log("not on ground!") + if (startingFallingPosition === null) { + startingFallingPosition = bot.entity.position.clone() + //console.log("just started falling, so setting starting position: " + startingFallingPosition) + } - // Replace the original function with the new function - bot._client.write = newFunction; + yDistanceFallen = Math.abs(startingFallingPosition.y - bot.entity.position.y) + //console.log("Y distance fallen:" + yDistanceFallen + " -- curr pos: " + bot.entity.position) + } + else if (bot.entity.onGround === true) { + startingFallingPosition = null; + yDistanceFallen = 0.0 + } + }) } diff --git a/package.json b/package.json index f4eac0e..aca1c1e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mineflayer-antihunger", - "version": "1.0.5", + "version": "1.0.6", "description": "Adds antihunger functionality to your mineflayer bot (Tested on 1.12)", "main": "index.js", "scripts": { |