From e31d0986b8e5b61a93035cb6ed356ae32f87356d Mon Sep 17 00:00:00 2001 From: D4VID Date: Mon, 30 Sep 2024 16:42:18 +0200 Subject: [PATCH] Allow mining (gravel) when returning --- miner.lua | 4 ++-- navigator.lua | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/miner.lua b/miner.lua index 3d8f0e8..9e01f8f 100644 --- a/miner.lua +++ b/miner.lua @@ -32,7 +32,7 @@ local function mine_row(length) robot.turnAround() - nav.forward(mined) + nav.forward(mined, true) end -- starts facing right, mines rows to the right @@ -53,7 +53,7 @@ local function mine(mine_rows, mine_row_length) -- go back to start robot.turnAround() - nav.forward(moved_rows) + nav.forward(moved_rows, true) end return { diff --git a/navigator.lua b/navigator.lua index 282785b..a879e53 100644 --- a/navigator.lua +++ b/navigator.lua @@ -2,14 +2,18 @@ local robot = require("robot") -- Moves forward n blocks. -- Waits if there is an obstruction -local function forward(n) +local function forward(n, mine) for _ = 1, n do while true do local result, error = robot.forward() if result then break else - print("Cannot move: " .. error) + if mine and error == "solid" then + robot.swing() + else + print("Cannot move: " .. error) + end end end end