Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local length = tArgs[1]
- local numTunnels = tArgs[2]
- local inv = true
- local checkTorch = 0
- local height = 0
- local fullInvNum = 0
- function checkOreId(name)
- return name == 'minecraft:coal_ore'
- or name == 'minecraft:iron_ore'
- or name == 'minecraft:gold_ore'
- or name == 'minecraft:diamond_ore'
- or name == 'minecraft:lapis_ore'
- or name == 'minecraft:redstone_ore'
- or name == 'minecraft:lit_redstone_ore'
- end
- function checkOre(func)
- local success, data = func()
- if not success then return false end
- return checkOreId(data.name)
- end
- function isOre()
- return checkOre(turtle.inspect)
- end
- function isOreUp()
- return checkOre(turtle.inspectUp)
- end
- function isOreDown()
- return checkOre(turtle.inspectDown)
- end
- function repeatSuccess(func)
- while func() do end
- end
- function dig()
- repeatSuccess(turtle.dig)
- end
- function digUp()
- repeatSuccess(turtle.digUp)
- end
- function digDown()
- repeatSuccess(turtle.digDown)
- end
- isUp = false
- function searchAround()
- print('searching for ores')
- turtle.select(1)
- if isOre() then
- dig()
- turtle.forward()
- searchAround()
- turtle.back()
- turtle.place()
- elseif isOreDown() then
- digDown()
- turtle.down()
- searchAround()
- turtle.up()
- turtle.placeDown()
- elseif isOreUp() then
- digUp()
- turtle.up()
- searchAround()
- turtle.down()
- turtle.placeUp()
- end
- turtle.turnLeft()
- if isOre() then
- dig()
- turtle.forward()
- searchAround()
- turtle.back()
- turtle.place()
- end
- turtle.turnRight()
- turtle.turnRight()
- if isOre() then
- dig()
- turtle.forward()
- searchAround()
- turtle.back()
- turtle.place()
- end
- turtle.turnLeft()
- end
- -- The basic function to move forward and dig
- function tunnel()
- -- These used throughout to erase screen
- term.clear()
- term.setCursorPos(1,1)
- print("Mining...")
- for i=1,length do
- fuel()
- dig()
- turtle.forward()
- digUp()
- isUp = false
- searchAround()
- turtle.up()
- isUp = true
- searchAround()
- turtle.down()
- torch()
- end
- end
- -- The function to turn around and go the other direction down the tunnel, also clears side tunnels
- function turnAround()
- term.clear()
- term.setCursorPos(1,1)
- print("Turning around...")
- for k = 1,6 do
- fuel()
- dig()
- turtle.forward()
- digUp()
- isUp = false
- searchAround()
- turtle.up()
- isUp = true
- searchAround()
- turtle.down()
- torch()
- end
- checkInv()
- while turtle.back() == false do
- turtle.turnRight()
- turtle.turnRight()
- dig()
- for i = 1,3 do
- turtle.forward()
- dig()
- end
- turtle.turnRight()
- turtle.turnRight()
- for i = 1,3 do
- turtle.back()
- end
- end
- turtle.back()
- turtle.back()
- end
- -- Clears the specified item from the inventory, most likely cobble, also stops on full inv
- function checkInv()
- term.clear()
- term.setCursorPos(1,1)
- print("Trashing...")
- for y = 2,16 do
- turtle.select(y)
- if turtle.compareTo(1) then
- turtle.drop()
- end
- end
- end
- function fullInv()
- checkInv()
- -- To not spill items everywhere, some credit to link0153 :)
- for i = 1,16 do
- if turtle.getItemCount(i) > 0 then
- fullInvNum = fullInvNum + 1
- end
- end
- while fullInvNum == 16 do
- term.clear()
- term.setCursorPos(1,1)
- print("Inventory full, please clear.")
- sleep(5)
- for i = 1,16 do
- if turtle.getItemCount(i) == 0 then
- fullInvNum = 0
- end
- end
- end
- fullInvNum = 0
- term.clear()
- term.setCursorPos(1,1)
- print("Mining...")
- end
- -- Checks how long since the last torch, then decides to place one above or not
- function torch()
- -- Checks if low on torches
- if turtle.getItemCount(16) < 5 then
- term.clear()
- term.setCursorPos(1,1)
- print("Waiting for torches...place in bottom right.")
- while turtle.getItemCount(16) < 5 do
- sleep(2)
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Mining...")
- if checkTorch == 8 then
- fuel()
- turtle.select(16)
- turtle.up()
- digUp()
- -- This if and loop will bring the turtle back down from the placed torch
- if turtle.placeUp() or turtle.getItemCount(16) == 0 then
- for i = 0,height do
- fuel()
- turtle.down()
- end
- turtle.select(1)
- checkTorch = 0
- height = 0
- else
- height = height + 1
- torch()
- end
- -- If it's too soon, dont place a torch
- else
- checkTorch = checkTorch + 1
- end
- end
- -- Checks the fuel level, asks for more if necessary
- function fuel()
- if turtle.getFuelLevel() < 50 then
- print ("Wating for fuel...place in bottom left.")
- while turtle.getFuelLevel() < 50 do
- turtle.select(13)
- turtle.refuel()
- sleep(2)
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- print("Mining...")
- turtle.select(1)
- end
- -- This function is a one time startup function, makes sure the turtle has the necessary materials
- function begin()
- turtle.select(1)
- -- Checks for trash item
- if turtle.getItemCount(1) == 0 then
- print("Please place an item to trash in the top left.")
- while turtle.getItemCount(1) == 0 do
- sleep(1)
- end
- term.clear()
- term.setCursorPos(1,1)
- begin()
- -- Confirms trashed item
- else
- print("The item in the top left will be trashed...confirm?")
- os.pullEvent("key")
- end
- term.clear()
- term.setCursorPos(1,1)
- end
- -- From here is the main code
- -- Checks for correct args
- if not (tArgs[1] == nil or tArgs[2] == nil) then
- begin()
- -- Loops for the specified # of tunnels, one tunnel being up and back
- for j = 1,numTunnels do
- tunnel()
- fullInv()
- turtle.turnLeft()
- turnAround()
- fullInv()
- turtle.turnLeft()
- tunnel()
- fullInv()
- turtle.turnRight()
- turnAround()
- fullInv()
- turtle.turnRight()
- end
- -- Resets the screen and displays a confirmation of finishing
- term.clear()
- term.setCursorPos(1,1)
- print("Done!")
- else
- term.clear()
- term.setCursorPos(1,1)
- print("Not enough arguments, should be used 'branch [length] [number of tunnels]'")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement