diff --git a/dominic/canemine.lua b/dominic/canemine.lua index 4f506cc..e6f97d1 100644 --- a/dominic/canemine.lua +++ b/dominic/canemine.lua @@ -124,7 +124,6 @@ function digShaft() digDeep(turtle.down, noop, noop, depth) turtle.turnLeft() digDeep(turtle.up, noop, noop, depth) - turtle.turnLeft() selectCobble() turtle.placeDown() turtle.up() @@ -132,9 +131,80 @@ function digShaft() turtle.up() end +function digTo(x, z) + print("Digging to rel. coord ("..tostring(x)..", "..tostring(z)..")") + while z > 0 do + turtle.dig() + turtle.forward() + turtle.digUp() + z = z - 1 + end + turtle.turnRight() + while x > 0 do + turtle.dig() + turtle.forward() + turtle.digUp() + x = x - 1 + 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 + 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 + sleep(0.6) + else + digAction() + end + else + -- nothing in the way, try to move + if moveAction() then + break + end + end + end +end + +function goToSpawn(x, z) + turtle.digUp() + turtle.up() + while z > 0 do + moveSafe(turtle.forward, turtle.inspect, turtle.dig) + z = z - 1 + end + turtle.turnRight() + while x > 0 do + moveSafe(turtle.forward, turtle.inspect, turtle.dig) + x = x - 1 + end +end + +function goToBarrel() + moveSafe(turtle.forward, turtle.inspect, noop) + turtle.turnRight() + moveSafe(turtle.forward, turtle.inspect, noop) + turtle.turnLeft() + moveSafe(turtle.forward, turtle.inspect, noop) + moveSafe(turtle.forward, turtle.inspect, noop) + moveSafe(turtle.forward, turtle.inspect, noop) + moveSafe(turtle.down, turtle.inspectDown, noop) + turtle.turnLeft() +end + +function emptyToBarrel() +end + spotNum = tonumber(args[1]) if spotNum then x, z = ithSpot(spotNum) digTo(x,z) digShaft() + --goToSpawn(x, z) + --goToBarrel() + --emptyToBarrel() end +--moveSafe(turtle.forward, turtle.inspect, turtle.dig) +--moveSafe(turtle.forward, turtle.inspect, turtle.dig)