Add safemove

This commit is contained in:
Dominic Zimmer 2020-07-04 15:48:48 +02:00
parent 4ea3db4197
commit f44f4163a8

View File

@ -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)