From eb535fa029fb1016c668539d49fe98d37791b464 Mon Sep 17 00:00:00 2001 From: Dominic Zimmer Date: Mon, 6 Jul 2020 19:18:11 +0200 Subject: [PATCH] Syntax --- mine/client.lua | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/mine/client.lua b/mine/client.lua index 639b881..6323bce 100644 --- a/mine/client.lua +++ b/mine/client.lua @@ -77,6 +77,22 @@ function iTo2Dcoords(j) end end +function digSafe(inspectAction, digAction) + while true do + local status, block = inspectAction() + if status then + if block["name"]:lower():find("turtle") then + -- turtle in front of me. lets wait for it to move + return true + else + digAction() + end + else + return true + end + end +end + -- move safely into the direction, not hurting other turtles, but freeing the path if needed. function moveSafe(moveAction, inspectAction, digAction) while true do @@ -529,6 +545,9 @@ function goToCoordXZ(targetX, targetZ, extraaction) end end +function digSafe(inspectAction, digAction) +end + function goToJob(job) jobX, jobZ = iTo2Dcoords(job) -- this does all the magic updateState({ state = "Going on the job...", morestate = " Jobsite is at ("..tostring(jobX)..", "..tostring(jobZ)..")" }) @@ -559,8 +578,11 @@ function turtleAI2() end end +function extraaction() + repeat sleep(0.6) until (not digSafe(turtle.inspectUp, turtle.digUp())) +end -- turtleAI() faceDir(3) -goToCoordXZ(4, 2, noop) -goToCoordXZ(0, 0, noop) -goToCoordXZ(4, 2, noop) +goToCoordXZ(4, 2, extraaction) +goToCoordXZ(0, 0, extraaction) +goToCoordXZ(4, 2, extraaction)