Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 3 x 3 Tunnel with torches
- local tArgs = {...}
- print("Checking inventory...")
- if (#tArgs ~= 1) then
- print("Program call: <mprogramName> <tunnelLength>")
- return
- end
- local tunnelLength = tonumber(tArgs[1])
- local distanceTravelled = 0
- local torchSlot = 1
- local hasTorches = false;
- -- define functions
- local function EmptyInventory()
- print("Emptying inventory...")
- for i = 1, 16, 1 do
- turtle.select(i)
- turtle.drop()
- end
- print("Fuel left: "..turtle.getFuelLevel())
- end
- local function ReturnHome()
- print("Returning...")
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 0, distanceTravelled, 1 do
- turtle.forward()
- end
- EmptyInventory()
- end
- local function CheckForFuel()
- local foundFuel = false
- for i = 1, 16, 1 do
- turtle.select(i);
- if (turtle.refuel(0)) then
- print("Found Fuel.")
- foundFuel = true
- print("Trying to refuel...");
- if (turtle.getFuelLevel() <= turtle.getFuelLimit()) then
- turtle.refuel()
- print("Refueled succesfully.")
- else
- print("Refueling failed. Fuel already full.")
- end
- end
- end
- turtle.select(1)
- if (foundFuel == false) then
- print("No fuel found!")
- end
- return foundFuel
- end
- local function CheckForTorches()
- hasTorches = false;
- for i = 1, 16, 1 do
- turtle.select(i)
- if (turtle.getItemDetail()) then
- if (turtle.getItemDetail().name == "minecraft:torch") then
- print("Found torches.")
- torchSlot = i
- hasTorches = true
- end
- end
- end
- if (hasTorches == false) then
- print("No torches found!.")
- end
- turtle.select(1)
- return hasTorches
- end
- local function CheckTorchSlot(index)
- turtle.select(index)
- if (turtle.getItemDetail()) then
- if (turtle.getItemDetail().name == "minecraft:torch") then
- return
- else
- print("torchSlot out of torches. Searching for torches...")
- CheckForTorches()
- end
- else
- print("torchSlot out of torches. Searching for torches...")
- CheckForTorches()
- end
- end
- local function CheckDistance()
- local isReturning = false
- if (turtle.getFuelLevel() <= distanceTravelled + 5) then
- print("Fuel is low.")
- if (CheckForFuel() == false) then
- isReturning = true
- print("Returning...")
- ReturnHome()
- end
- end
- return isReturning
- end
- local function ClearRow(setTorch)
- turtle.turnLeft()
- turtle.dig()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.dig()
- if (setTorch == true) then
- turtle.select(torchSlot)
- if (turtle.getItemDetail()) then
- if (turtle.getItemDetail().name == "minecraft:torch") then
- turtle.place()
- end
- end
- turtle.select(1)
- end
- turtle.turnLeft()
- end
- local function ClearBlock()
- ClearRow(false)
- turtle.digUp()
- turtle.up()
- if distanceTravelled % 6 == 0 then
- ClearRow(true)
- else
- ClearRow(false)
- end
- turtle.digUp()
- turtle.up()
- ClearRow(false)
- end
- local function ResetPosition()
- turtle.down()
- turtle.down()
- CheckDistance()
- end
- local function GoBackABlock()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- -- tunnel
- if(CheckForFuel() == false and turtle.getFuelLevel() < 5) then
- print("Fuel is needed!")
- return
- end
- if (CheckForTorches() == false) then
- print("Torches are needed!")
- return
- end
- for i = 1, tunnelLength, 1 do
- ClearBlock()
- ResetPosition()
- turtle.dig()
- turtle.forward()
- distanceTravelled = distanceTravelled + 1
- end
- GoBackABlock()
- ReturnHome()
Add Comment
Please, Sign In to add comment