Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Tunnel Mining Turtle (with return)
- -- Mines, places torches, builds floor
- -- Variables
- turtle.select(1)
- local tArgs = { ... }
- local togo = tonumber(tArgs[1])
- togo = togo or 1
- local torch = 0
- local cobble = 0
- term.clear()
- term.setCursorPos(1,1)
- print(os.getComputerLabel() .. " at your service!")
- print()
- print("Please place blocks as follows:")
- print("Slot 1 - Fuel (coal or lava)")
- print("Slot 2 - Torches (optional)")
- print("Slot 3 - Cobble (optional)")
- print()
- print("Press [ENTER] when ready.")
- read(input)
- -- Starting Out
- if turtle.getItemCount(1) < 1 then
- print("No fuel! Abort!")
- quit()
- end
- torch = 0
- if turtle.getItemCount(2) > 0 then
- torch = 1
- end
- if turtle.getItemCount(3) > 0 then
- cobble = 1
- end
- local i = 0
- -- Functions
- function tfuel(amount)
- if turtle.getFuelLevel() < 16 then
- turtle.select(1)
- turtle.refuel(amount)
- end
- end
- function turnaround()
- turtle.turnRight()
- turtle.turnRight()
- end
- function uandd()
- if turtle.detectUp() then
- repeat
- turtle.digUp()
- sleep(0.5)
- until turtle.detectUp() == false
- end
- if turtle.detectDown() then
- repeat
- turtle.digDown()
- until turtle.detectDown() == false
- end
- if cobble > 0 then
- turtle.down()
- if turtle.detectDown() == false then
- turtle.select(3)
- turtle.placeDown()
- turtle.select(1)
- end
- turtle.up()
- end
- end
- function mydig()
- tfuel(1)
- if turtle.detect() then
- repeat
- turtle.dig()
- sleep(0.5)
- until turtle.detect() == false
- turtle.forward()
- uandd()
- else
- turtle.forward()
- uandd()
- end
- end
- function discard() -- run back to start and drop off items
- turnaround()
- for f = 1,i do
- tfuel(1)
- while turtle.forward() == false do
- turtle.dig()
- end
- end
- for x = 2+torch+cobble,16 do
- turtle.select(x)
- turtle.dropDown()
- end
- turnaround()
- for f = 1,i do
- tfuel(1)
- while turtle.forward() == false do
- turtle.dig()
- end
- end
- turtle.select(1)
- end
- -- Main Loop
- repeat
- i = i + 1
- term.clear()
- term.setCursorPos(1,1)
- local pct = (i/togo)*100
- print("Mining "..i.." of "..togo.." ("..pct.."%)")
- print("Fuel: "..turtle.getFuelLevel())
- mydig()
- turtle.turnRight()
- mydig()
- turnaround()
- turtle.forward()
- mydig()
- turnaround()
- turtle.forward()
- turtle.turnLeft()
- if togo >= 8 and torch > 0 then
- if (i % 8 == 0) then
- turtle.select(2)
- turtle.placeDown()
- turtle.select(1)
- end
- end
- -- check to see if turtle is full
- if turtle.getItemCount(16) > 0 then
- discard()
- end
- turtle.select(1)
- until i >= togo
- --Lets assume that worked and he made it
- turnaround()
- for r = 1, togo do
- tfuel(1)
- while turtle.forward() == false do
- turtle.dig()
- end
- end
- for x = 1,16 do
- turtle.select(x)
- turtle.dropDown()
- end
- turtle.select(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement