From 61677086e0b020eedb7cb871bc319783746dd13a Mon Sep 17 00:00:00 2001 From: Anton Reinhard Date: Mon, 29 May 2023 02:39:58 +0200 Subject: [PATCH] Fix mining script --- New Attempts/Mining.lua | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/New Attempts/Mining.lua b/New Attempts/Mining.lua index 4ceb4bf..c310b8b 100644 --- a/New Attempts/Mining.lua +++ b/New Attempts/Mining.lua @@ -1,7 +1,8 @@ -compareSlotMax = 4 -- all slots up to this one are used for comparing, order the blocks in decreasing probability +compareSlotMax = 1 -- all slots up to this one are used for comparing, order the blocks in decreasing probability xRelPos = 0 -- "positive = forward" yRelPos = 0 -- "positive = right" +zRelPos = 0 -- "positive = upwards" facing = { x = 1, @@ -29,6 +30,21 @@ function forward() end end +function upwards() + if turtle.up() then + zRelPos = zRelPos + 1 + return true + end + return false +end + +function downwards() + if turtle.down() then + zRelPos = zRelPos - 1 + return true + end + return false + function turnRight() turtle.turnRight() if facing.x == 1 and facing.y == 0 then -- facing forward @@ -110,16 +126,15 @@ function moveTo(x, y) end function blockIsWorth() - return true - --[[for i = 1, compareSlotMax do + for i = 1, compareSlotMax do turtle.select(i) if turtle.compare() then return false end end - return true]] + return true end function checkForItems(z) @@ -163,7 +178,7 @@ function digHole() -- go down turtle.digDown() - while turtle.down() do + while downwards() do z = z + 1 checkForItems(z) turtle.digDown() @@ -172,12 +187,11 @@ function digHole() -- go back up -- look at the remaining direction (-1, 0) and check blocks faceTo(-1, 0) - while z > 0 do + while zRelPos < 0 do if blockIsWorth() then turtle.dig() end - turtle.up() - z = z - 1 + upwards() end end @@ -188,7 +202,7 @@ function returnItems() faceTo(-1, 0) -- already facing right direction, put items - for slot = compareSlotMax + 1, fuelSlot - 1 do + for slot = compareSlotMax + 1, 16 do turtle.select(slot) turtle.drop() end