From 4c84f4820760adb85e1ff97e603432e487d47cf2 Mon Sep 17 00:00:00 2001 From: Guillaume ARM Date: Thu, 9 May 2024 03:03:54 +0200 Subject: [PATCH] fix: robot force forward --- miner.lua | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/miner.lua b/miner.lua index 1f37c1a..0024b02 100644 --- a/miner.lua +++ b/miner.lua @@ -31,6 +31,18 @@ local function isOdd(x) return (x % 2) == 1 end +local function robotForceForward() + local ok = miner.robot.forward() + + if ok then + return ok + end + + turtleUtils.digAll() + + return miner.robot.forward() +end + local function checkConfig() if config.targetY >= config.startY then error('targetY should be lower than startY') @@ -112,12 +124,12 @@ local function returnMineProcedure() if robotState.y > miner.lastPositionState.y then miner.robot.down() elseif robotState.z < miner.lastPositionState.z then - miner.robot.forward() + robotForceForward() else miner.robot.turnRight() for i=1, miner.lastPositionState.x, 1 do - miner.robot.forward() + robotForceForward() end while miner.robot.getState().dir ~= miner.lastPositionState.dir do @@ -144,19 +156,19 @@ local function mineProcedure() miner.robot.down() elseif robotState.dir == 'FORWARD' and robotState.z < targetZ then turtleUtils.digAll() - miner.robot.forward() + robotForceForward() elseif robotState.dir == 'FORWARD' and robotState.z == targetZ then miner.robot.turnRight() turtleUtils.digAll() - miner.robot.forward() + robotForceForward() miner.robot.turnRight() elseif robotState.dir == 'BACKWARD' and robotState.z > 0 then turtleUtils.digAll() - miner.robot.forward() + robotForceForward() elseif robotState.dir == 'BACKWARD' and robotState.z == 0 then miner.robot.turnLeft() turtleUtils.digAll() - miner.robot.forward() + robotForceForward() miner.robot.turnLeft() end @@ -171,7 +183,7 @@ local function mineProcedure() miner.robot.turnRight() for i=1, config.size - 1, 1 do - miner.robot.forward() + robotForceForward() end miner.robot.turnRight() @@ -206,13 +218,13 @@ local function returnHomeProcedure() end for i=1, robotState.x, 1 do - miner.robot.forward() + robotForceForward() end miner.robot.turnLeft() elseif robotState.z > 0 then for i=1, robotState.z, 1 do - miner.robot.forward() + robotForceForward() end miner.robot.turnLeft()