From b80b43b3e177db691a3b0ef7760e7ec68b287f20 Mon Sep 17 00:00:00 2001 From: iroaK <55340002+bastianmarin@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:23:00 -0300 Subject: [PATCH 1/6] Update place_block.js Add optionsPlace - Changeable swingArm - Changeable timeOut --- lib/plugins/place_block.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/plugins/place_block.js b/lib/plugins/place_block.js index fdaec6b55..76e1cea60 100644 --- a/lib/plugins/place_block.js +++ b/lib/plugins/place_block.js @@ -1,17 +1,17 @@ const { onceWithCleanup } = require('../promise_utils') -module.exports = inject +function inject(bot) { + + async function placeBlockWithOptions(referenceBlock, faceVector, optionsPlace) { -function inject (bot) { - async function placeBlockWithOptions (referenceBlock, faceVector, options) { const dest = referenceBlock.position.plus(faceVector) let oldBlock = bot.blockAt(dest) - await bot._genericPlace(referenceBlock, faceVector, options) + await bot._genericPlace(referenceBlock, faceVector, optionsPlace) let newBlock = bot.blockAt(dest) if (oldBlock.type === newBlock.type) { [oldBlock, newBlock] = await onceWithCleanup(bot, `blockUpdate:${dest}`, { - timeout: 5000, + timeout: optionsPlace.timeOut, // Condition to wait to receive block update actually changing the block type, in case the bot receives block updates with no changes // oldBlock and newBlock will both be null when the world unloads checkCondition: (oldBlock, newBlock) => !oldBlock || !newBlock || oldBlock.type !== newBlock.type @@ -29,10 +29,15 @@ function inject (bot) { } } - async function placeBlock (referenceBlock, faceVector) { - await placeBlockWithOptions(referenceBlock, faceVector, { swingArm: 'right' }) + async function placeBlock(referenceBlock, faceVector, optionsPlace) { + await placeBlockWithOptions(referenceBlock, faceVector, { + swingArm: typeof optionsPlace.swingArm == 'string' ? optionsPlace.swingArm : 'right', + timeOut: typeof optionsPlace.timeOut == 'number' ? optionsPlace.timeOut : 5000 + }) } bot.placeBlock = placeBlock bot._placeBlockWithOptions = placeBlockWithOptions + } +module.exports = inject \ No newline at end of file From 092359577999c2b4fef23032d23b6fd6bb13b43c Mon Sep 17 00:00:00 2001 From: iroaK <55340002+bastianmarin@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:27:04 -0300 Subject: [PATCH 2/6] Update api.md --- docs/api.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/docs/api.md b/docs/api.md index 0e09d2da7..9ce739d8c 100644 --- a/docs/api.md +++ b/docs/api.md @@ -302,7 +302,7 @@ - [bot.digTime(block)](#botdigtimeblock) - [bot.acceptResourcePack()](#botacceptresourcepack) - [bot.denyResourcePack()](#botdenyresourcepack) - - [bot.placeBlock(referenceBlock, faceVector)](#botplaceblockreferenceblock-facevector) + - [bot.placeBlock(referenceBlock, faceVector, optionsPlace)](#botplaceblockreferenceblock-facevector) - [bot.placeEntity(referenceBlock, faceVector)](#botplaceentityreferenceblock-facevector) - [bot.activateBlock(block, direction?: Vec3, cursorPos?: Vec3)](#botactivateblockblock-direction-vec3-cursorpos-vec3) - [bot.activateEntity(entity)](#botactivateentityentity) @@ -1912,15 +1912,22 @@ Accepts resource pack. Denies resource pack. -#### bot.placeBlock(referenceBlock, faceVector) +#### bot.placeBlock(referenceBlock, faceVector, optionsPlace) This function returns a `Promise`, with `void` as its argument when the server confirms that the block has indeed been placed. * `referenceBlock` - the block you want to place a new block next to * `faceVector` - one of the six cardinal directions, such as `new Vec3(0, 1, 0)` for the top face, indicating which face of the `referenceBlock` to place the block against. +### placeBlock(referenceBlock, faceVector, optionsPlace) -The new block will be placed at `referenceBlock.position.plus(faceVector)`. +This function is used to place a block in the Minecraft world. + +- `referenceBlock` (object): The reference block where the new block will be placed adjacent to. +- `faceVector` (object): The vector representing the face of the reference block where the new block will be placed. +- `optionsPlace` (object): An optional object containing additional options for placing the block. + - `swingArm` (string): The arm to swing while placing the block. Defaults to 'right' if not provided. + - `timeOut` (number): The timeout duration in milliseconds for placing the block. Defaults to 5000 milliseconds if not provided. #### bot.placeEntity(referenceBlock, faceVector) From 0bcf51cd1c5c734aafccba7b7f7b2dda079f2846 Mon Sep 17 00:00:00 2001 From: iroaK <55340002+bastianmarin@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:34:19 -0300 Subject: [PATCH 3/6] Fix undefined prob error --- lib/plugins/place_block.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/plugins/place_block.js b/lib/plugins/place_block.js index 76e1cea60..a30e8e0b7 100644 --- a/lib/plugins/place_block.js +++ b/lib/plugins/place_block.js @@ -31,8 +31,8 @@ function inject(bot) { async function placeBlock(referenceBlock, faceVector, optionsPlace) { await placeBlockWithOptions(referenceBlock, faceVector, { - swingArm: typeof optionsPlace.swingArm == 'string' ? optionsPlace.swingArm : 'right', - timeOut: typeof optionsPlace.timeOut == 'number' ? optionsPlace.timeOut : 5000 + swingArm: typeof optionsPlace?.swingArm == 'string' ? optionsPlace?.swingArm : 'right', + timeOut: typeof optionsPlace?.timeOut == 'number' ? optionsPlace?.timeOut : 5000 }) } From 4e40f708add0bff5d2eefff7ac1c71391be6c833 Mon Sep 17 00:00:00 2001 From: iroaK <55340002+bastianmarin@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:35:54 -0300 Subject: [PATCH 4/6] Update place_block.js --- lib/plugins/place_block.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/plugins/place_block.js b/lib/plugins/place_block.js index a30e8e0b7..ce4773522 100644 --- a/lib/plugins/place_block.js +++ b/lib/plugins/place_block.js @@ -1,5 +1,7 @@ const { onceWithCleanup } = require('../promise_utils') +module.exports = inject + function inject(bot) { async function placeBlockWithOptions(referenceBlock, faceVector, optionsPlace) { @@ -39,5 +41,4 @@ function inject(bot) { bot.placeBlock = placeBlock bot._placeBlockWithOptions = placeBlockWithOptions -} -module.exports = inject \ No newline at end of file +} \ No newline at end of file From ad1fdc3cb8cf185bd6a8bbf20861e8a5fd342151 Mon Sep 17 00:00:00 2001 From: iroaK <55340002+bastianmarin@users.noreply.github.com> Date: Mon, 18 Mar 2024 15:42:18 -0300 Subject: [PATCH 5/6] Update place_block.js --- lib/plugins/place_block.js | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/plugins/place_block.js b/lib/plugins/place_block.js index ce4773522..0f55b4ca3 100644 --- a/lib/plugins/place_block.js +++ b/lib/plugins/place_block.js @@ -1,44 +1,41 @@ -const { onceWithCleanup } = require('../promise_utils') +const { onceWithCleanup } = require('../promise_utils'); -module.exports = inject +module.exports = inject; function inject(bot) { - async function placeBlockWithOptions(referenceBlock, faceVector, optionsPlace) { + const dest = referenceBlock.position.plus(faceVector); + let oldBlock = bot.blockAt(dest); + await bot._genericPlace(referenceBlock, faceVector, optionsPlace); - const dest = referenceBlock.position.plus(faceVector) - let oldBlock = bot.blockAt(dest) - await bot._genericPlace(referenceBlock, faceVector, optionsPlace) - - let newBlock = bot.blockAt(dest) + let newBlock = bot.blockAt(dest); if (oldBlock.type === newBlock.type) { [oldBlock, newBlock] = await onceWithCleanup(bot, `blockUpdate:${dest}`, { timeout: optionsPlace.timeOut, // Condition to wait to receive block update actually changing the block type, in case the bot receives block updates with no changes // oldBlock and newBlock will both be null when the world unloads checkCondition: (oldBlock, newBlock) => !oldBlock || !newBlock || oldBlock.type !== newBlock.type - }) + }); } // blockUpdate emits (null, null) when the world unloads if (!oldBlock && !newBlock) { - return + return; } if (oldBlock?.type === newBlock.type) { - throw new Error(`No block has been placed : the block is still ${oldBlock?.name}`) + throw new Error(`No block has been placed: the block is still ${oldBlock?.name}`); } else { - bot.emit('blockPlaced', oldBlock, newBlock) + bot.emit('blockPlaced', oldBlock, newBlock); } } async function placeBlock(referenceBlock, faceVector, optionsPlace) { await placeBlockWithOptions(referenceBlock, faceVector, { - swingArm: typeof optionsPlace?.swingArm == 'string' ? optionsPlace?.swingArm : 'right', - timeOut: typeof optionsPlace?.timeOut == 'number' ? optionsPlace?.timeOut : 5000 - }) + swingArm: typeof optionsPlace?.swingArm === 'string' ? optionsPlace?.swingArm : 'right', + timeOut: typeof optionsPlace?.timeOut === 'number' ? optionsPlace?.timeOut : 5000 + }); } - bot.placeBlock = placeBlock - bot._placeBlockWithOptions = placeBlockWithOptions - + bot.placeBlock = placeBlock; + bot._placeBlockWithOptions = placeBlockWithOptions; } \ No newline at end of file From 0c84b1b12a4c48f3e9ec56dbf439de78d1644414 Mon Sep 17 00:00:00 2001 From: iroaK <55340002+bastianmarin@users.noreply.github.com> Date: Tue, 23 Apr 2024 15:16:27 -0400 Subject: [PATCH 6/6] Fix physics player speed hack in physics.js --- lib/plugins/physics.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/plugins/physics.js b/lib/plugins/physics.js index 79fe868bf..e0d07c4c9 100644 --- a/lib/plugins/physics.js +++ b/lib/plugins/physics.js @@ -17,7 +17,7 @@ const PHYSICS_TIMESTEP = PHYSICS_INTERVAL_MS / 1000 // 0.05 function inject (bot, { physicsEnabled, maxCatchupTicks }) { const PHYSICS_CATCHUP_TICKS = maxCatchupTicks ?? 4 const world = { getBlock: (pos) => { return bot.blockAt(pos, false) } } - const physics = Physics(bot.registry, world) + let physics = Physics(bot.registry, world) const positionUpdateSentEveryTick = bot.supportFeature('positionUpdateSentEveryTick') @@ -204,6 +204,10 @@ function inject (bot, { physicsEnabled, maxCatchupTicks }) { return effectInfo.amplifier + 1 } + bot.speedHack = (newSpeed) => { + physics.playerSpeed = newSpeed ?? 0.1; + } + bot.elytraFly = async () => { if (bot.entity.elytraFlying) { throw new Error('Already elytra flying')