diff --git a/lib/plugins/digging.js b/lib/plugins/digging.js index b91aa193b..817447e52 100644 --- a/lib/plugins/digging.js +++ b/lib/plugins/digging.js @@ -36,15 +36,17 @@ function inject (bot) { } else if (digFace.z) { diggingFace = digFace.z > 0 ? BlockFaces.SOUTH : BlockFaces.NORTH } - await bot.lookAt(block.position.offset(0.5, 0.5, 0.5).offset(digFace.x * 0.5, digFace.y * 0.5, digFace.z * 0.5), forceLook) + await bot.lookAt( + block.position.offset(0.5, 0.5, 0.5).offset(digFace.x * 0.5, digFace.y * 0.5, digFace.z * 0.5), + forceLook + ) } else if (digFace === 'raycast') { // Check faces that could be seen from the current position. If the delta is smaller then 0.5 that means the // bot cam most likely not see the face as the block is 1 block thick // this could be false for blocks that have a smaller bounding box then 1x1x1 - const dx = bot.entity.position.x - block.position.x + 0.5 - const dy = bot.entity.position.y - block.position.y - 0.5 + bot.entity.height // -0.5 because the bot position - // is calculated from the block position that is inside its feet so 0.5 - 1 = -0.5 - const dz = bot.entity.position.z - block.position.z + 0.5 + const dx = bot.entity.position.x - (block.position.x + 0.5) + const dy = bot.entity.position.y + bot.entity.height - (block.position.y + 0.5) + const dz = bot.entity.position.z - (block.position.z + 0.5) // Check y first then x and z const visibleFaces = { y: Math.sign(Math.abs(dy) > 0.5 ? dy : 0), @@ -55,12 +57,20 @@ function inject (bot) { for (const i in visibleFaces) { if (!visibleFaces[i]) continue // skip as this face is not visible // target position on the target block face. -> 0.5 + (current face) * 0.5 - const targetPos = block.position.offset(0.5 + (i === 'x' ? visibleFaces[i] * 0.5 : 0), 0.5 + (i === 'y' ? visibleFaces[i] * 0.5 : 0), 0.5 + (i === 'z' ? visibleFaces[i] * 0.5 : 0)) + const targetPos = block.position.offset( + 0.5 + (i === 'x' ? visibleFaces[i] * 0.5 : 0), + 0.5 + (i === 'y' ? visibleFaces[i] * 0.5 : 0), + 0.5 + (i === 'z' ? visibleFaces[i] * 0.5 : 0) + ) const startPos = bot.entity.position.offset(0, bot.entity.height, 0) const rayBlock = bot.world.raycast(startPos, targetPos.clone().subtract(startPos).normalize(), 5) if (rayBlock) { const rayPos = rayBlock.position - if (rayPos.x === block.position.x && rayPos.y === block.position.y && rayPos.z === block.position.z) { + if ( + rayPos.x === block.position.x && + rayPos.y === block.position.y && + rayPos.z === block.position.z + ) { // console.info(rayBlock) validFaces.push({ face: rayBlock.face, @@ -75,7 +85,9 @@ function inject (bot) { let distSqrt = 999 for (const i in validFaces) { const tPos = validFaces[i].targetPos - const cDist = new Vec3(tPos.x, tPos.y, tPos.z).distanceSquared(bot.entity.position.offset(0, bot.entity.height, 0)) + const cDist = new Vec3(tPos.x, tPos.y, tPos.z).distanceSquared( + bot.entity.position.offset(0, bot.entity.height, 0) + ) if (distSqrt > cDist) { closest = validFaces[i] distSqrt = cDist @@ -172,7 +184,11 @@ function inject (bot) { }) function canDigBlock (block) { - return block && block.diggable && block.position.offset(0.5, 0.5, 0.5).distanceTo(bot.entity.position.offset(0, 1.65, 0)) <= 5.1 + return ( + block && + block.diggable && + block.position.offset(0.5, 0.5, 0.5).distanceTo(bot.entity.position.offset(0, 1.65, 0)) <= 5.1 + ) } function digTime (block) { @@ -195,7 +211,14 @@ function inject (bot) { } const creative = bot.game.gameMode === 'creative' - return block.digTime(type, creative, bot.entity.isInWater, !bot.entity.onGround, enchantments, bot.entity.effects) + return block.digTime( + type, + creative, + bot.entity.isInWater, + !bot.entity.onGround, + enchantments, + bot.entity.effects + ) } bot.dig = dig