Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[TO DO:
- Rednet statistics tracker coming soon
- Version 2.2.3
- Recent changes: added an argument for which side the chest is on.
- 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
- ]]
- --Check Fuel Disabling for those on softcore
- doCheckFuel = true
- --For those that find this annoying
- forceAutoEmpty = true
- --For just plain emptying large amounts of land, will not annoy you with auto-Emptying or max size restraints
- careAboutResources = true
- --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 16
- maxslots = 13
- --If your job is bigger than it can carry (as defined by max slots) it will default to auto-empty
- --Note: For counting to work properly, cobblestone must be the first block it mines, or put a cobble in slot 1
- --Defining things
- _ = {...}
- if _[1] == nil then
- dropSide = "front"
- else
- dropSide = _[1]
- end
- function screen(xPos,yPos)
- term.clear()
- term.setCursorPos(xPos,yPos)
- end
- function mine() -- Basic Move Forward
- while turtle.forward() == false do
- if turtle.dig() == false then
- turtle.attack()
- mined = mined - 1
- end
- mined = mined + 1
- end
- if Cdouble == 1 then
- if turtle.digDown() == true then
- mined = mined + 1
- end
- end
- if Cdouble == 0 then
- moved = moved + 1
- else
- moved = moved + 2
- end
- display()
- end
- function mineRow() -- Move a row then turn
- if cRows ~= 0 then -- cRows is "Rows Completed"
- for length=1, x do --It does this check because on the first row of a layer,
- mine() -- it already occupies the first position
- end
- else
- for length=1, x-1 do
- mine()
- end
- end
- cRows = cRows + 1
- end
- function display() --Runs 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
- totals = {cobble = 0, sand = 0, other = 0} -- Total for display (cannot go inside function)
- function count() --Done after every row of auto-empty and at end
- slot = {} --Detection of blocks code is 1: Cobble 2: Other Raw 3:Other
- for i=1, 16 do --[1] is type, [2] is number
- slot[i] = {}
- slot[i][2] = turtle.getItemCount(i)
- end
- doCheckSand = false
- if area > 100 then
- doCheckSand = true
- end
- slot[1][1] = 1 -- = Assumes Cobble/Main
- for i=2, 16 do --Cobble Check
- turtle.select(i)
- if turtle.compareTo(1) then
- slot[i][1] = 1
- end
- end
- for i=2, 16 do --Sand/Raw Check
- tempItemCount = turtle.getItemCount(i)
- if tempItemCount > 32 and doCheckSand then
- slot[i][1] = 2
- elseif tempItemCount > 0 then
- slot[i][1] = 3
- end
- end
- for i=1, 16 do
- if slot[i][1] == 1 then
- totals.cobble = slot[i][2] + totals.cobble
- elseif slot[i][1] == 2 then
- totals.sand = slot[i][2] + totals.sand
- else
- totals.other = slot[i][2] + totals.other
- end
- end
- end
- function endDrop(final)
- if final ~= false then
- final = true
- end
- if dropSide == "left" then --Turning
- turtle.turnRight()
- elseif dropSide == "right" then
- turtle.turnLeft()
- end
- turtle.select(1)
- if dropSide == "top" then -- Drops to top
- if final == false then
- avar = turtle.getItemCount(1) --Dosen't drop 1 cobblestone for future counting purposes if autofill
- turtle.dropUp(avar-1)
- elseif turtle.detectUp() then
- turtle.dropUp()
- for i=2, 16 do
- turtle.select(i)
- turtle.dropUp()
- end
- end
- elseif dropSide == "bottom" then --Drops to bottom
- if final == false then
- avar = turtle.getItemCount(1)
- turtle.dropDown(avar-1)
- elseif turtle.detectDown() then
- turtle.dropDown()
- for i=2, 16 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- else --Drops to front
- if final == false then
- avar = turtle.getItemCount(1)
- turtle.drop(avar-1)
- elseif turtle.detect() then
- turtle.drop()
- for i=2, 16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- turtle.select(1)
- if dropSide == "right" then --Turning, inverted
- turtle.turnRight()
- elseif dropSide == "left" then
- turtle.turnLeft()
- end
- end
- -----------------------------------------------------------------
- --Input Phase
- screen(1,1)
- print("----- Welcome to Quarry! -----")
- print("")
- --Dimensions of Hole
- print("What dimensions?")
- print("")
- term.write("Length: ")
- x = io.read()
- term.write("Width: ")
- z = io.read()
- term.write("Height: ")
- y = io.read()
- if not tonumber(x) or x == 0 then
- x = 3
- end
- if not tonumber(y) or y == 0 then
- y = 2
- end
- if not tonumber(z) or z == 0 then
- z = 3
- end
- x = math.abs(tonumber(x))
- y = math.abs(tonumber(y))
- z = math.abs(tonumber(z))
- Cdouble = 0
- --Check for if it can do doubles
- if math.ceil(y/2) == y/2 then
- Cdouble = 1
- end
- volume = x*y*z
- area = x*z
- if maxslots > 16 then
- maxslots = 16
- end
- maxsize = maxslots*64
- if Cdouble == 1 then
- maxsize = maxsize/2
- end
- empty = 0
- --Checks if bigger than inventory: 832 blocks theoretical Assuming at least 2 are non-cobble
- if forceAutoEmpty == true then
- if volume > maxsize then
- print("Job very big")
- print("Auto-emptying on")
- empty = 1
- sleep(2)
- end
- end
- if empty ~= 1 and careAboutResources == true then
- 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
- elseif ans == "s" then
- print("Stop? (type \"yes\")")
- if io.read() == "yes" then
- os.shutdown()
- end
- end
- end
- if area > maxsize then
- print("Area too Large, please restart program")
- sleep(5)
- os.reboot()
- end
- if area > 256 then
- Rcheck = 32
- else
- Rcheck = area/4
- end
- if empty == 0 and volume > 256 then
- Rcheck = 32
- else
- Rcheck = area/4
- end
- --Getting Fuel
- if doCheckFuel == true then
- neededFuel = math.ceil(volume*1.1)
- function checkFuel()
- fuelLevel = turtle.getFuelLevel()
- return fuelLevel
- end
- if checkFuel() < neededFuel then
- term.clear()
- term.setCursorPos(1,1)
- print("More Fuel Needed")
- print("Current Fuel: ",checkFuel()," Needed: ",neededFuel)
- print("Place in Bottom Right, press any key")
- os.pullEvent("char")
- print("I'll take a bit more, so we don't have to do this as often")
- turtle.select(16)
- while checkFuel() < neededFuel+500 do
- if turtle.refuel(1) == false then
- term.clearLine()
- print("Still too little fuel")
- term.clearLine()
- print("Press a key to resume fueling")
- os.pullEvent("char")
- end
- x,y = term.getCursorPos()
- print(fuelLevel.." Fuel")
- term.setCursorPos(x,y)
- end
- print(fuelLevel.." Units of Fuel")
- sleep(3)
- turtle.select(1)
- end
- end
- --Check Double changing the Depth y (times it goes down)
- if Cdouble == 1 then
- Dy = y/2
- else
- Dy = y
- end
- --Height Calculation
- if Cdouble == 0 then
- b = 1
- else
- b = 2
- 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, Dy 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 turn == 0 then --This If statement gets it back to the start of this layer
- turtle.turnRight()
- if Cdouble == 1 then
- if turtle.digDown() == true then
- mined = mined + 1
- end
- end
- 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 ~= Dy then --AutoEmptying at the end of every layer
- if Cdouble == 1 then
- AEup = depth*2
- else
- AEup = depth
- end
- for i=1, AEup-b do
- while not turtle.up() do
- end
- end
- turtle.turnLeft()
- while not turtle.forward() do
- end
- count() --Counting
- endDrop(false) -- Drop into specified chest
- turtle.turnLeft()
- turtle.turnLeft()
- while not turtle.forward() do
- end
- for i=1, AEup-b do
- turtle.down()
- end
- turtle.turnLeft()
- end
- if depth ~= Dy then --This checks if it is the last layer of the run
- for a=1, b do
- while not turtle.down() do
- turtle.digDown()
- mined = mined+1
- end
- moved = moved + 1
- end
- turtle.turnRight()
- if Cdouble == 1 then
- if turtle.digDown() == true then
- mined = mined + 1
- end
- end
- turn = 1
- end
- end
- for i=1, y-b 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
- --Counts all blocks at the end also
- count()
- --Output to a chest or sit there
- endDrop()
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(1)
- --Display
- screen(1,1)
- print("Total Blocks Mined: "..mined)
- print("Current Fuel Level: "..turtle.getFuelLevel())
- print("Cobble: "..totals.cobble)
- print("Other Raw: "..totals.sand)
- print("Other: "..totals.other)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement