Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function move(f)
- if turtle.getFuelLevel() == 0 then
- for slot=1,16 do
- turtle.select(slot)
- if turtle.refuel(0) then
- turtle.refuel(1)
- break
- end
- end
- if turtle.getFuelLevel() == 0 then
- print("No fuel, stopping...")
- return false
- end
- end
- -- mooooooveeee soooooo4aaaaraaa
- while not f() do
- turtle.dig()
- turtle.attack()
- sleep(1)
- end
- end
- -- return true if item count in slot 2 == 64
- local function refill2()
- local cobbleCount = turtle.getItemCount(2)
- local refillCount = 64 - cobbleCount
- if (cobbleCount == 0) then
- print("Out of tunnel buildblock: place buildblock in slot 2 to continue")
- repeat
- sleep(1)
- until (turtle.getItemCount(2) > 0)
- else
- for n = 3,16 do
- turtle.select(2)
- if (turtle.compareTo(n) == true) then
- turtle.select(n)
- if (refillCount > turtle.getItemCount(n)) then
- turtle.transferTo(2, turtle.getItemCount(n))
- refillCount = 64 - turtle.getItemCount(2)
- else
- turtle.transferTo(2, refillCount)
- break
- end
- end
- end
- end
- return turtle.getItemCount(2) == 64
- end
- local function place()
- if not turtle.detect() then
- refill2()
- turtle.select(2)
- turtle.place()
- return true
- end
- return false
- end
- local function placeUp()
- if not turtle.detectUp() then
- refill2()
- turtle.select(2)
- turtle.placeUp()
- return true
- end
- return false
- end
- local function placeDown()
- if not turtle.detectDown() then
- refill2()
- turtle.select(2)
- turtle.placeDown()
- return true
- end
- return false
- end
- function emptyStash()
- for slot=3,16 do
- inSlot = turtle.getItemDetail(slot)
- if inSlot.name == "minecraft:cobblestone" then
- turtle.select(slot)
- turtle.drop()
- end
- end
- end
- local function dig()
- while turtle.detect() do
- turtle.dig()
- end
- end
- local function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- end
- end
- -- 1 floor step
- local function step1()
- dig()
- move(turtle.forward)
- placeDown()
- end
- -- 2 floor step
- local function step2()
- dig()
- move(turtle.forward)
- placeUp()
- end
- local function placeTorch()
- turtle.select(1)
- if turtle.getItemCount() < 1 then
- print("No torches in slot 1, place torches in slot 1")
- return false
- end
- turtle.turnRight()
- turtle.place()
- turtle.turnLeft()
- return true
- end
- -- MAIN
- local args = { ... }
- local length = 0
- local width = 3
- local depth = 0
- if #args < 1 then
- print( "Usage: tunnel <length> [width, default 3]" )
- return
- else
- length = tonumber( args[1] )
- if length < 1 then
- print( "Tunnel length must be > 0" )
- return
- end
- end
- if #args > 1 then
- width = tonumber( args[2] )
- if width < 1 then
- print( "Tunnel width must be > 0" )
- return
- end
- end
- print( "Tunnelling: length="..length.." width="..width.." height=2" )
- for i=1,length do
- step1(false)
- turtle.turnRight()
- for j=2,width do
- step1()
- if (i % 7 == 0) and (j % 7 == 0) then
- placeTorch()
- end
- end
- place()
- digUp()
- move(turtle.up)
- place()
- placeUp()
- turtle.turnRight()
- turtle.turnRight()
- for j=2,width do
- step2()
- end
- place()
- move(turtle.down)
- place()
- turtle.turnRight()
- if (i == 2) or (i % 7 == 0) then
- placeTorch()
- end
- depth = depth + 1
- if refill2() then
- emptyStash()
- end
- end
- print( "Returning to start..." )
- -- Return to where we started
- turtle.turnLeft()
- turtle.turnLeft()
- while depth > 0 do
- move(turtle.forward)
- depth = depth - 1
- end
- turtle.turnRight()
- turtle.turnRight()
- print( "Tunnel complete." )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement