Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Programmer: Noiro/Thunder7102
- Purpose:
- This miner will server 2 purposes. It is primarily meant to act as a module in WorldEater.
- It can be used as a standalone with multiple modes to be a nice miner.
- ]]
- version = 0.1
- local debug = true
- --Config vars
- --Chunksize mined, if maxRadius = 16, he will mine a 16x16 cube
- local maxRadius = 16
- --The y level the turtle will mine up to. Bigger means there will be a bigger gap between bedrock and the ceiling
- local mineToY = 40
- --Will this turtle use a chest it dumps into or will it dump into a enderchest?
- local hasEnderChest = false
- local mode = "fast"
- --Static Vars
- local chestLoc = {0,0,0,"north"}
- local status = {"starting"}
- --Temporary Variables
- local floorY = 0
- local tempLoc
- --Override determines whether the program will skip the player intro and digging and assume to start digging THERE.
- local override = false
- --Now, if this program gets moduled, things will change
- --This takes parameters and changes up the variables before it gets down to runtime so reactions will be...different.
- if #({...}) > 0 and #({...}) < 3 then
- error("Either enter 0 parameters or 3. Improper amount. You entered: "..tostring(#({...})))
- else
- maxRadius, mineToY, hasEnderChest, floorY = ...
- override = true
- end
- function debug(message)
- if debug then print(message) end
- end
- function emptyInv()
- status = "emptyInv"
- tempLoc = turtle.getCoordsTbl()
- saveData()
- if hasEnderChest then
- turtle.select(1)
- turtle.digUp()
- turtle.placeUp()
- else
- turtle.fMoveTo(chestLoc,"x","z","y")
- end
- for i=2, 16 do
- turtle.select(i)
- if turtle.refuel(1) and turtle.getItemCount(i) > 0 and turtle.getFuelLevel() < 5000 then
- turtle.refuel(turtle.getItemCount(i))
- else
- while not turtle.dropUp(turtle.getItemCount(i)) do sleep(5) end
- end
- end
- --If the turtle has an enderchest, pick it back up again, if not, go to original position
- if hasEnderChest then
- turtle.select(1)
- turtle.digUp()
- else
- turtle.fMoveTo(tempLoc,"y","z","x")
- end
- end
- function findBottom()
- --Go down until you can't (you hit bedrock) and go 3 blocks above that
- while turtle.fDown() do end
- --Go up and set that as the 'floor' you will mine at (so bedrock doesn't get in the way)
- turtle.fUp(3)
- floorY = turtle.getY()
- end
- --[[
- TODO: Redo the logic for mineRadius and forward...it's clunky and overcomplicated.
- Make sure persistence across reboots is available. ^^ It's more fun that way.
- Port to OC when you get a chance...a port without persistence would be fun
- ]]
- --[[
- PRIMARY LOGIC - Handles most of the outline
- ]]
- local blackListedItems = {
- "minecraft:dirt",
- "minecraft:gravel",
- "minecraft:stone"
- }
- function badBlock(direction)
- --This ultimately is in case fastmode is enabled and blacklisted blocks are to be ignored
- --Have to include this part in case there is air
- if direction == "up" and not turtle.detectUp() then
- debug("Nothing above me.")
- return true
- elseif direction == "down" and not turtle.detectDown() then
- debug("Nothing below me.")
- return true
- end
- if mode == "fast" then
- local succ, block
- --Uses dir to know which side to check
- if direction == "up" then succ, block = turtle.inspectUp()
- elseif direction == "down" then succ,block = turtle.inspectDown() end
- --This is where the eval is run on if the name of the block matches the blacklist
- local name = block["name"]
- for i=1, #blackListedItems do
- if name == blackListedItems[i] then
- debug(block["name"].." in blacklist. Looking "..direction..".")
- return true
- end
- end
- return false
- else
- --This means the mode isn't set to fast and they want to mine out everything
- return false
- end
- end
- function column(distance)
- saveData()
- debug("Starting forward...")
- for i=1, distance do
- --Checks firstly if he has room. Also, if set on fastMode, will ignore blacklisted blocks
- debug("On movement "..i.."/"..distance)
- if turtle.getItemCount(16) > 0 then emptyInv() end
- turtle.fForward()
- if turtle.getItemCount(16) > 0 then emptyInv() end
- if not badBlock("up") then turtle.digUp() end
- if turtle.getItemCount(16) > 0 then emptyInv() end
- if not badBlock("down") then turtle.digDown() end
- end
- end
- function mineChunk(radius)
- --Will mine the area with the maxRadius
- status = {"chunk", "start"}
- saveData()
- --Here is the big loop that manages most of the mining
- local turn = "right"
- for i=1,radius-1 do
- debug("Starting column "..i.."/"..tostring(radius-1))
- column(radius-1)
- --This part is for turning around corners and making sure to stay within bounds
- if i<radius-1 then
- if turn == "right" then
- turtle.turnRight()
- column(1)
- turtle.turnRight()
- turn = "left"
- elseif turn == "left" then
- turtle.turnLeft()
- column(1)
- turtle.turnLeft()
- turn = "right"
- end
- end
- --Whoo, he turned around and is about to restart...well, assuming he's supposed to
- end
- debug("Finished mineChunk!")
- end
- function master()
- --Ultimately manages what the turtle should be doing
- if status == "emptyInv" then
- --Persistence stuffs
- emptyInv()
- end
- --The ONLY reason this works is because emptyInv has to run first and return to the original location
- while turtle.getY()+1 < mineToY do
- --The turtle mines the block above him as well so that gets counted as 'done' after mineChunk()
- --mineToY is how far up he is supposed to loop the minechunk
- mineChunk(maxRadius)
- --Go to starting point on that y-level before moving up 3.
- turtle.fMoveTo(0,turtle.getY(),0,"north")
- turtle.fUp(3)
- end
- turtle.fMoveTo(chestLoc, "x", "z", "y")
- fs.delete("startup")
- if fs.exists("realStartup") then
- fs.move("realStartup", "startup")
- end
- print("Done!")
- end
- --[[
- DATA OPERATIONS
- ]]
- function saveData()
- local f = fs.open("minerTempStats", "w")
- local variables = {chestLoc, mineToY, status, floorY}
- f.write(textutils.serialize(variables))
- f.close()
- end
- function loadData()
- local f = fs.open("minerTempStats", "r")
- local variables = textutils.unserialize(f.readAll())
- chestLoc, mineToY, status, floorY = unpack(variables)
- f.close()
- end
- --[[
- STARTUP
- ]]
- function loadMove()
- --Loads moveAPI and puts file in appropriate folder for..subroutines if needed.
- if fs.exists("move") then
- fs.move("move", "api/move")
- elseif fs.exists("api/move") then
- else
- error("MoveAPI cannot be found. Please install it before executing this program.")
- end
- os.loadAPI("api/move")
- end
- function init()
- loadMove()
- if args[1] == "resume" then
- master()
- else
- setup()
- end
- end
- function setup()
- --Gets all data it needs to start
- while turtle.getItemCount(1) == 0 do
- term.clear()
- term.setCursorPos(1,1)
- while turtle.getItemCount(1) == 0 do
- print("No chest found in slot one. Please try again.")
- sleep(2)
- end
- end
- print("Starting operation...")
- turtle.select(1)
- --This part is to create the chest the turtle will dump items into.
- if not hasEnderChest then
- turtle.placeUp()
- end
- if fs.exists("startup") then fs.move("startup", "realStartup") end
- f = fs.open("startup", "w")
- f.writeLine("shell.run(\"miner\", \"resume\")")
- findBottom()
- master()
- end
- print("THIS IS A DEVELOPMENTAL TESTING VERSION....DO NOT USE UNLESS YOU'RE HELPING DEVELOP.")
- --Load this when you're ready
- --init()
Advertisement
Add Comment
Please, Sign In to add comment