From 29af471374bf52bc2a516d328fc298ed5819b94b Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Sun, 23 Dec 2018 02:17:59 -0500 Subject: [PATCH] app tweaks --- farms/superTreefarm.lua | 2 +- miners/scanningMiner.lua | 35 +++++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/farms/superTreefarm.lua b/farms/superTreefarm.lua index 8d82c97..289846a 100644 --- a/farms/superTreefarm.lua +++ b/farms/superTreefarm.lua @@ -548,7 +548,7 @@ local function fellTrees(blocks) end for pt in Point.iterateClosest(turtle.point, blocks) do if pt.sapling then - turtle.suckDownAt(pt) + repeat until not turtle.suckDownAt(pt) else turtle.digAt(pt) end diff --git a/miners/scanningMiner.lua b/miners/scanningMiner.lua index 6630176..11053fd 100644 --- a/miners/scanningMiner.lua +++ b/miners/scanningMiner.lua @@ -456,6 +456,7 @@ local function mineChunk() if pts[i].y > mining.home.y - 8 then pts[i].y = mining.home.y - 8 end + pts[i].y = math.max(pts[i].y, 8) pts[i].y = pts[i].y - mining.home.y -- abs to rel end @@ -546,7 +547,8 @@ end if not fs.exists(STARTUP_FILE) then Util.writeFile(STARTUP_FILE, - [[os.sleep(1) + [[print('sleeping for 10 seconds') +os.sleep(10) shell.openForegroundTab('scanningMiner.lua')]]) print('Autorun program created: ' .. STARTUP_FILE) end @@ -594,10 +596,27 @@ Event.addRoutine(function() z = turtle.point.z - mining.home.z, }) - if math.abs(turtle.point.x) > 500 or math.abs(turtle.point.z) > 500 then - _G.printError('WARNING: distance > 500') - print('waiting for 30 seconds to begin') + local distance = Point.distance( + { x = turtle.point.x, y = 0, z = turtle.point.z }, + { x = mining.x, y = 0, z = mining.z } + ) + local maxDistance = Point.distance( + { x = 0, y = 0, z = 0 }, + { x = mining.x + 16, y = 0, z = mining.z + 16 } + ) + + _G._debug({ distance = distance, maxDistance = maxDistance }) + + if distance > maxDistance then + term.clear() + term.setCursorPos(1, 1) + _G.printError('WARNING\n\nTurtle is outside the mining area\n') + print('Max distance: ' .. math.floor(maxDistance)) + print('Distance to home: ' .. math.floor(distance)) + print('\nIf in a new location, delete usr/config/scanning_miner.progress') + print('\nWaiting for 30 seconds to begin') os.sleep(30) + page:sync() end if not fs.exists(PROGRESS_FILE) then @@ -609,6 +628,10 @@ Event.addRoutine(function() turtle.setMovementStrategy('goto') status('mining') + Event.onTerminate(function() + turtle.abort(true) + end) + if isFinished() then success = false msg = 'Mining complete' @@ -626,10 +649,6 @@ Event.addRoutine(function() Event.exitPullEvents() end) -Event.onTerminate(function() - turtle.abort(true) -end) - UI:setPage(page) UI:pullEvents() UI.term:reset()