Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --TO DO:
- --Maybe rednet statistics tracker that fires after every row.
- --Maybe put coal in slot 16 check after every row
- --Version 2.0.4
- --Directions: If you want, place a chest right behind where you place the turtle. It will place things here when its done
- --Also, if auto-empty is on, it will always eject the things it has into the place where a chest is supposed to be, it just dosen't check for a chest
- --This is how many (theoretical) slots it will fill with cobble. e.g. 13 allows 13 slots for cobble (or other stack) and 2 slots for other things.
- --Maximum here is 15 because 16 is for fuel
- maxslots = 13
- --If your job is bigger than it can carry (as defined by max slots) it will default to auto-empty
- --Defining things
- function screen(xPos,yPos)
- term.clear()
- term.setCursorPos(xPos,yPos)
- end
- function mine()
- while turtle.forward() == false do
- turtle.dig()
- mined = mined + 1
- term.setCursorPos(1,2)
- term.clearLine()
- end
- moved = moved + 1
- display()
- end
- function mineRow()
- if cRows ~= 0 then
- for length=1, x do
- mine()
- end
- else
- for length=1, x-1 do
- mine()
- end
- end
- cRows = cRows + 1
- end
- function display() --Run in Mine(), display information to the screen in a certain place
- percent = math.ceil((moved/volume)*100)
- term.setCursorPos(1,2)
- term.clearLine()
- print(mined)
- term.setCursorPos(1,4)
- term.clearLine()
- print(percent.."%")
- end
- fuel = turtle.getFuelLevel()
- slot = {}
- for i=1, 16 do
- slot[i] = {}
- end
- sandCh = 0
- stacks = {}
- cobble = 0
- sand = 0
- other = 0
- --Input Phase
- screen(1,1)
- print("----- Welcome to Quarry! -----")
- print("")
- --Dimensions of Hole
- print("What dimensions?")
- print("")
- term.write("Length: ")
- x = math.abs(tonumber(io.read()))
- term.write("Width: ")
- z = math.abs(tonumber(io.read()))
- term.write("Height: ")
- y = math.abs(tonumber(io.read()))
- if not y or y == 0 then
- y = 3
- end
- if not x or x == 0 then
- x = 3
- end
- if not z or z == 0 then
- z = 3
- end
- volume = x*y*z
- area = x*z
- if maxslots > 15 then
- maxslots = 15
- end
- maxsize = maxslots*64
- empty = 0
- --Checks if bigger than inventory: 832 blocks theoretical Assuming at least 2 are non-cobble
- if volume > maxsize then
- print("Job very big")
- print("Auto-emptying on")
- empty = 1
- sleep(2)
- else
- print("Turn on auto-emptying? (Y/N)")
- ans = string.sub(string.lower(io.read()),1,1)
- if ans == "y" or ans == "1" then
- empty = 1
- end
- end
- if area > maxsize then
- print("Area too Large, please restart program")
- sleep(5)
- os.reboot()
- end
- --Getting Fuel
- while fuel < volume do
- print("Fuel Needed")
- print("Put Fuel in Bottom Right")
- print("Press any key when placed")
- os.pullEvent("char")
- screen(1,1)
- turtle.select(16)
- Nfuel = turtle.getItemSpace(16)
- for i = 1, Nfuel do
- fuel = turtle.getFuelLevel()
- if fuel < volume+50 then
- turtle.refuel(1)
- else
- i = 65 --Breaks the for
- end
- end
- end
- --Mining Phase
- turn = 1 --Turn right is 0, turn left is 1 opposite to start
- mined = 0 -- Total Blocks Mined
- moved = 0 -- Total Spaces Moved
- turtle.select(1)
- screen(1,1)
- print("Blocks Mined")
- print("")
- print("Percent Complete")
- mine()
- for depth=1, y do
- for width = 1, z do
- cRows = 0 -- Rows completed (z)
- mineRow()
- if turn == 1 then
- turn = 0
- else
- turn = 1
- end
- if width ~= z then --Check if last row of set, will not turn if last
- if turn == 0 then
- turtle.turnRight()
- mine()
- turtle.turnRight()
- else
- turtle.turnLeft()
- mine()
- turtle.turnLeft()
- end
- end
- end
- if --This If statement gets it back to the start of this layer
- turn == 0 then
- turtle.turnRight()
- turtle.turnRight()
- for i=1, x-1 do
- while not turtle.forward() do
- end
- end
- turtle.turnRight()
- for i=1, z-1 do
- while not turtle.forward() do
- end
- end
- else
- turtle.turnRight()
- for i=1, z-1 do
- while not turtle.forward() do
- end
- end
- end
- if empty == 1 and depth ~= y then --AutoEmptying at the end of every layer
- for i=1, depth-1 do
- while not turtle.up() do
- end
- end
- turtle.turnLeft()
- while not turtle.forward() do
- end
- for i=1, 15 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- turtle.turnLeft()
- turtle.turnLeft()
- while not turtle.forward() do
- end
- for i=1, depth-1 do
- turtle.down()
- end
- turtle.turnLeft()
- end
- if depth ~= y then --This checks if it is the last layer of the run
- if turtle.down() == false then
- turtle.digDown()
- mined = mined+1
- turtle.down()
- end
- moved = moved + 1
- turtle.turnRight()
- turn = 1
- end
- end
- for i=1, y-1 do --This gets the turtle back to the top layer
- while not turtle.up() do
- end
- end
- turtle.turnLeft()
- while not turtle.forward() do
- end
- --Detection of blocks code is 1: Cobble 2: Other Raw 3:Other
- if empty == 0 then
- slot[1][1] = 1
- for i=2, 15 do --Checks each slot for cobble
- turtle.select(i)
- Ccobble = turtle.compareTo(1)
- if Ccobble == true then
- slot[i][1] = 1
- end
- end
- for i=2, 15 do --Checks each slot for stacks, assumes sand or dirt
- Cnum = turtle.getItemCount(i)
- if Cnum == 64 and slot [i][1] ~= 1 then
- slot[i][1] = 2
- table.insert(stacks, i)
- sandCh = 1
- end
- end
- for i=2, 15 do --Checks if other slots have sand or dirt
- turtle.select(i)
- if sandCh == 1 then--Checks if there is any sand/dirt
- for a=1, #stacks do --Compares it to all known sand/dirt slots
- Csand = turtle.compareTo(stacks[a])
- if Csand == true then --If it is the same as any dirt/sand
- slot[i][1] = 2
- a = 20 --Breaks the for
- end
- end
- end
- end
- for i=2, 15 do
- if slot[i][1] ~= 1 and slot[i][1] ~= 2 then
- slot[i][1] = 3
- end
- end
- for i=1, 15 do
- slot[i][2] = turtle.getItemCount(i)
- end
- for i=1, 15 do
- if slot[i][1] == 1 then
- cobble = cobble + slot[i][2]
- end
- if slot[i][1] == 2 then
- sand = sand + slot[i][2]
- end
- if slot[i][1] == 3 then
- other = other + slot[i][2]
- end
- end
- end
- --Output to a chest or sit there
- chest = turtle.detect()
- if chest == true then
- for i=1,15 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- --Display
- screen(1,1)
- print("Total Blocks Mined: "..mined)
- print("Current Fuel Level: "..turtle.getFuelLevel())
- if empty == 0 then
- print("Cobble: "..cobble)
- print("Other Raw: "..sand)
- print("Other: "..other)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement