Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not turtle then
- error("Turtle required!")
- end
- write("Miner initializing")
- textutils.slowPrint("...", 5)
- local DEBUG = true
- local resume = not DEBUG and fs.exists(fs.combine("database", shell.getRunningProgram(), "state"))
- local running = false
- local Aware2 = require("Aware2")
- local aware = Aware2.new()
- local Miner2 = require("Miner2")
- local miner = Miner2.new(aware)
- function setup()
- local branchCount, branchLength, branchGap, verticalGap, startX, startY, startZ, facing, minY, maxY
- if DEBUG then
- branchCount = 16
- branchLength = 16
- branchGap = 0
- verticalGap = 1
- startX = -1667
- startY = 63
- startZ = 592
- facing = 3
- minY = 16
- maxY = 24
- else
- while branchCount == nil do
- print("");
- print("How many branches should be mined?")
- local input = read();
- branchCount = tonumber(input)
- if branchCount == nil then
- print("'" .. input .. "' should be a number")
- end
- end
- while branchLength == nil do
- print("");
- print("How long should each branch be?")
- local input = read();
- branchLength = tonumber(input)
- if branchLength == nil then
- print("'" .. input .. "' should be a number")
- end
- end
- if branchCount > 1 then
- while branchGap == nil do
- print("");
- print("How many block gap should there be between branches?")
- local input = read();
- branchGap = tonumber(input)
- if branchGap == nil then
- print("'" .. input .. "' should be a number")
- end
- end
- end
- while verticalGap == nil do
- print("");
- print("How much space between floors?")
- local input = read();
- verticalGap = tonumber(input)
- if verticalGap == nil then
- print("'" .. input .. "' should be a number")
- end
- end
- while startX == nil do
- print("");
- print("What is the startX of the turtle?")
- local input = read();
- startX = tonumber(input)
- if startX == nil then
- print("'" .. input .. "' should be a number")
- end
- end
- while startY == nil do
- print("");
- print("What is the startY of the turtle?")
- local input = read();
- startY = tonumber(input)
- if startY == nil then
- print("'" .. input .. "' should be a number")
- end
- end
- while startZ == nil do
- print("");
- print("What is the startZ of the turtle?")
- local input = read();
- startZ = tonumber(input)
- if startZ == nil then
- print("'" .. input .. "' should be a number")
- end
- end
- while facing == nil do
- print("");
- print("What is the facing? 1=north, 2=east, 3=south, 4=west")
- local input = read();
- facing = tonumber(input)
- if facing == nil then
- print("'" .. input .. "' should be a number")
- end
- end
- while minY == nil do
- print("");
- print("What is the minY?")
- local input = read();
- minY = tonumber(input)
- if minY == nil then
- print("'" .. input .. "' should be a number")
- end
- end
- while maxY == nil do
- print("");
- print("What is the maxY?")
- local input = read();
- maxY = tonumber(input)
- if maxY == nil then
- print("'" .. input .. "' should be a number")
- end
- end
- end
- miner.aware.state.pos.x = startX
- miner.aware.state.pos.y = startY
- miner.aware.state.pos.z = startZ
- miner.aware.state.pos.f = facing
- miner.aware:setHome(miner.aware.state.pos)
- miner.aware.state.branchCount = branchCount
- miner.aware.state.branchLength = branchLength
- miner.aware.state.branchGap = branchGap
- miner.aware.state.verticalGap = verticalGap
- miner.aware.state.minY = minY
- miner.aware.state.maxY = maxY
- -- set initial target y level
- miner.aware.state.yLevel = minY
- -- setup the GUI frame
- miner:guiFrame()
- running = true
- miner.aware:saveState(miner.aware.state)
- end
- function main()
- if not resume then
- setup()
- end
- running = true
- miner:useFuel(1000)
- if not miner.aware:equip("minecraft:diamond_pickaxe", "right") then
- error()
- end
- miner:setCurrentAction("descend")
- -- descend to target y level
- miner:moveTo(
- {
- x = miner.aware.state.pos.x,
- y = miner.aware.state.yLevel,
- z = miner.aware.state.pos.z,
- f = miner.aware.state.pos.f
- },
- true,
- "yxz",
- true
- )
- local keepGoing = true
- -- as long as we're at or below the max y level, we branch mine
- while keepGoing do
- miner:setCurrentBranch(1)
- -- execute each branch mine for the current y level
- for i = miner.aware.state.currentBranch, miner.aware.state.branchCount do
- local isEvenBranch = i % 2 == 0
- miner:setCurrentBranch(i)
- miner:branchMine({
- f = isEvenBranch and 4 or 2, -- face right for odd branches, face left for even ones, because we're coming back the other direction
- l = miner.aware.state.branchLength - 1,
- b = 1,
- left = false,
- right = false,
- up = false
- })
- -- if we just finished an even branch,we can safely unroll the last 2 branches.
- -- we did this in case we need a pitstop midway through an even branch.
- -- this way we can find our path back to the shaft without breaking any new blocks, e.g. we will follow the zag and zig
- -- in the even of odd branches, its a straight unobstructed path back to the shaft
- if isEvenBranch then
- -- remove 2 branches worth of movements
- local toBeRemoved = (miner.aware.state.branchLength - 1) * 2;
- -- remove the odd branches additional lateral movement into the current branch
- toBeRemoved = toBeRemoved + miner.aware.state.branchGap + 1
- miner.aware:removeCheckpoints(toBeRemoved)
- end
- -- get in position for the next branch
- if i < miner.aware.state.branchCount then
- miner:turnTo(1)
- for _ = 1, miner.aware.state.branchGap + 1 do
- miner:dig()
- miner:move()
- end
- end
- end
- -- go back to the vertical shaft
- miner:moveTo(
- {
- x = miner.aware.state.home.x,
- y = miner.aware.state.pos.y,
- z = miner.aware.state.home.z,
- f = 1
- },
- true,
- (miner.aware.state.home.f == 1 or miner.aware.state.home.f == 3) and "xzy" or "zxy",
- true
- )
- local nextY = miner.aware.state.pos.y + miner.aware.state.verticalGap + 1
- if nextY >= miner.aware.state.home.y or nextY > miner.aware.state.maxY then
- -- we've reached our max ceiling
- keepGoing = false
- else
- -- move up the shaft to the next level to branch mine
- miner.aware.state.yLevel = nextY
- miner.aware:saveState(miner.aware.state)
- miner:moveTo(
- {
- x = miner.aware.state.pos.x,
- y = miner.aware.state.yLevel,
- z = miner.aware.state.pos.z,
- f = miner.aware.state.pos.f
- },
- false,
- true
- )
- end
- end
- miner:setCurrentAction("home")
- miner.aware:goHome((miner.aware.state.home.f == 1 or miner.aware.state.home.f == 3) and "xzy" or "zxy", true)
- miner:unload("up")
- miner:setCurrentAction("done")
- miner.aware:deleteState()
- end
- function listen()
- while true do
- local event = os.pullEvent()
- if event == "stateSaved" and running then
- miner:guiStats()
- end
- if event == "moved" then
- miner.aware:addCheckpoint()
- end
- end
- end
- parallel.waitForAny(main, listen)
Advertisement
Add Comment
Please, Sign In to add comment