Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- tunnel <l> <w> <h> <left/right>
- local tArgs = { ... }
- local length = 0
- local height = 0
- local width = 0
- local slotWithEnderChest = 16
- -- 0: left 1: right
- local direction = 0
- if #tArgs ~= 4 then
- print("Usage: <l> <w> <h> <left/right>")
- return
- end
- if tArgs[3] == "right" then
- direction = 1
- end
- length = tArgs[1]
- width = tArgs[2]
- height = tArgs[3] -1
- function checkEmpty()
- emptySlots = 0
- for i=1,16 do
- if i == slotWithEnderChest then
- break
- end
- if turtle.getItemCount(i) == 0 then
- emptySlots = emptySlots + 1
- end
- end
- if emptySlots < 1 then
- return false
- else
- return true
- end
- end
- function empty()
- -- Empty the turtle's inventory
- currentSlot = turtle.getSelectedSlot()
- -- Check if the ender chest can be placed
- if turtle.detectUp() then
- turtle.digUp()
- end
- -- Place the ender chest
- turtle.select(slotWithEnderChest)
- turtle.placeUp()
- chest = peripheral.wrap("up")
- for i=1,16 do
- if i == slotWithEnderChest then
- break
- end
- turtle.select(i)
- turtle.dropUp()
- end
- turtle.select(slotWithEnderChest)
- turtle.digUp()
- turtle.select(currentSlot)
- end
- function doEmpty()
- if not checkEmpty() then
- empty()
- end
- end
- function checkRefuel()
- currentSlot = turtle.getSelectedSlot()
- if turtle.getFuelLevel() < 1000 then
- print("Refuelling")
- if turtle.detectUp() then
- turtle.digUp()
- end
- -- Place the ender chest
- turtle.select(slotWithEnderChest)
- turtle.placeUp()
- turtle.select(currentSlot)
- chest = peripheral.wrap("top")
- inventorySize = chest.getInventorySize()
- for i=1,inventorySize do
- currentItem = chest.getStackInSlot(i)
- if currentItem == nil then
- break
- end
- if currentItem["name"] == "coal" then
- -- Find the first inventory slot in the turtle
- freeSlot = -1
- for j=1,16 do
- print("Checking slot "..j..":"..turtle.getItemCount(j))
- if turtle.getItemCount(j) == 0 then
- freeSlot = j
- print("Found free slot "..j)
- break
- end
- end
- chest.pushItemIntoSlot("down", i, 64, freeSlot)
- turtle.select(i)
- turtle.refuel()
- end
- end
- turtle.select(slotWithEnderChest)
- turtle.digUp()
- turtle.select(currentSlot)
- else
- print(turtle.getFuelLevel())
- end
- end
- function digTunnel()
- for w=1, width do
- for l=1, length do
- checkRefuel()
- checkEmpty()
- turtle.dig()
- turtle.forward()
- for h=1, height do
- while turtle.detectUp() do
- turtle.digUp()
- end
- turtle.up()
- end
- for h=1, height do
- turtle.down()
- end
- end
- for l=1, length do
- turtle.back()
- end
- -- Turn
- if direction == 0 then
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- else
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.turnRight()
- end
- end
- empty()
- end
- digTunnel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement