Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- save this as "tunnel"
- -- place turtle at front-left and a chest behind him.
- -- put torches in last slot to light up your tunnel
- -- usage: tunnel 20 10
- -- will dig a tunnel 20 long and 10x10
- -- when inventory is getting full, turtle will return to chest to empty
- -- turtle will use any fuel it mines or you can drop lava/coal etc in for him to use
- -- grab fuel from all slots
- function grabFuel()
- for i=1,15 do
- turtle.select(i)
- turtle.refuel()
- end
- end
- function digAndMove()
- while (turtle.detect()) do
- turtle.dig(); os.sleep(0.5);
- end
- while (not turtle.forward()) do
- turtle.dig(); turtle.attack(); os.sleep(0.5);
- end
- end
- function digAndMoveUp()
- while (turtle.detectUp()) do
- turtle.digUp(); os.sleep(0.5);
- end
- while (not turtle.up()) do
- turtle.digUp();
- end
- end
- function digAndMoveDown()
- while (turtle.detectDown()) do
- turtle.digDown(); os.sleep(0.5);
- end
- while (not turtle.down()) do
- turtle.digDown(); os.sleep(0.5)
- end
- end
- function returnHome()
- local done=false
- if tonumber(distanceFromChest) >=tonumber(tunlen) then
- done=true
- end
- turtle.turnLeft()
- turtle.turnLeft()
- for d=1,distanceFromChest do
- digAndMove()
- end
- --make sure we are back home
- while not turtle.detect() do
- turtle.forward()
- os.sleep(0.2)
- end
- --unload
- for slot=1, 15, 1 do
- turtle.select(slot);
- turtle.drop();
- end
- if done then
- announce("All done")
- error("done")
- else
- turtle.turnLeft()
- turtle.turnLeft()
- for d=1,distanceFromChest do
- digAndMove()
- end
- end
- end
- function announce(thing)
- print(thing)
- end
- ----------------- START
- args={...}
- tunlen=args[1]
- tunsize=args[2]
- if tonumber(tunsize) % 2 ~= 0 then
- tunsize=tonumber(tunsize)+1
- end
- distanceFromChest=0;
- distanceWere=0;
- announce("Starting to dig tunnel "..tunlen.." long...")
- --find start of mine
- while not turtle.detect() do
- turtle.forward()
- os.sleep(0.2)
- end
- while true do
- if distanceFromChest > tonumber(tunlen) then
- returnHome()
- end
- grabFuel();
- announce("Fuel "..turtle.getFuelLevel().." at "..distanceFromChest.." of "..tunlen);
- --place torch?
- if distanceFromChest % 5 == 1 then
- turtle.turnLeft()
- turtle.dig();
- turtle.select(16);
- turtle.place();
- turtle.turnRight()
- end
- grabFuel();
- --facing bottom left block
- digAndMove()
- distanceFromChest=distanceFromChest + 1;
- turtle.turnRight()
- for bottotop=1,tonumber(tunsize) do
- for leftright=2,tonumber(tunsize) do
- digAndMove()
- end --leftright
- if (bottotop < tonumber(tunsize)) then
- digAndMoveUp()
- turtle.turnLeft()
- turtle.turnLeft()
- else
- turtle.turnRight()
- for down=2,tunsize do
- digAndMoveDown()
- end
- end
- end --botttotop
- local goHome=true
- for inv=1,16 do
- if turtle.getItemCount(inv)==0 then
- goHome=false
- end
- end
- if goHome then
- announce("about to drop off load")
- returnHome()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement