Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- loadfile("move")()
- loadfile("config")()
- local mineConfig = config.load("miner.dat")
- local radiusFirst = true
- local enderChest = false
- local enderFuel = false
- local dataFile = "radialminer.dat"
- local fuelSlot = nil
- local noiseSlot = {}
- local useNoise = false
- function checkInventory()
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- if turtle.refuel(0) then
- if fuelSlot == nil then
- fuelSlot = i
- else
- return
- end
- else
- noiseSlot[i] = true
- useNoise = true
- end
- else
- return
- end
- end
- end
- function loadWork()
- local work = config.load(dataFile)
- if work == nil then
- work = createWork()
- config.save(dataFile, work)
- end
- return work
- end
- function createWork()
- local work = {}
- work.startRadius = work.startRadius or config.getNumber("startRadius", 1)
- work.endRadius = work.endRadius or config.getNumber("endRadius", 2000)
- work.startHeight = work.startHeight or config.getNumber("startHeight", 4)
- work.endHeight = work.endHeight or config.getNumber("endHeight", 57)
- work.currentHeight = work.currentHeight or config.getNumber("currentHeight")
- turtle.y = work.currentHeight
- for r = work.startRadius, work.endRadius do
- work[r] = {}
- for h = work.startHeight + 1, work.endHeight, 3 do
- work[r][h] = false
- end
- end
- return work
- end
- function getNextRadius(work, height, turtleId)
- for r = work.startRadius, work.endRadius do
- for h = height or work.startHeight + 1, height or work.endHeight, 3 do
- if work[r][h] == false
- or (turtleId ~= nil and work[r][h] == turtleId) then
- return r
- end
- end
- end
- end
- function getNextHeight(work, radius, turtleId)
- for h = work.startHeight, work.endHeight do
- for r = radius or work.startRadius, radius or work.endRadius do
- if work[r][h] == false
- or (turtleId ~= nil and work[r][h] == turtleId) then
- return h
- end
- end
- end
- end
- function getWork(work, turtleId)
- local radius
- local height
- if radiusFirst then
- radius = getNextRadius(work, height, turtleId)
- height = getNextHeight(work, radius, turtleId)
- else
- height = getNextHeight(work, radius, turtleId)
- radius = getNextRadius(work, height, turtleId)
- end
- if radius ~= nil then
- work[radius][height] = turtleId
- config.save(dataFile, work)
- end
- return radius, height
- end
- function finishWork(work, radius, height)
- work[radius][height] = true
- config.save(dataFile, work)
- end
- function unload()
- turtle.moveToWaypoint("home", "xzy")
- for i = 1, 16 do
- local amount = turtle.getItemCount(i)
- if amount > 0 then
- -- keep full stack of fuel and at least 1 noise block
- if i ~= fuelSlot then
- turtle.select(i)
- if noiseSlot[i] then
- if not turtle.dropUp(turtle.getItemCount(i) - 1) then
- print("chest is full")
- while not turtle.dropUp(turtle.getItemCount(i) - 1) do
- sleep(10)
- end
- end
- else
- if not turtle.dropUp() then
- print("chest is full")
- while not turtle.dropUp() do
- sleep(10)
- end
- end
- end
- end
- end
- end
- turtle.select(1)
- end
- function unloadReturn()
- print("inventory full, returning items early")
- turtle.setWaypoint("mine")
- unload()
- turtle.moveToWaypoint("mine", "yxz")
- end
- function isFull()
- local full = true
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- full = false
- break
- end
- end
- return full
- end
- function isNoiseUp()
- for slot in pairs(noiseSlot) do
- turtle.select(slot)
- if turtle.compareUp() then
- turtle.select(1)
- return true
- end
- end
- turtle.select(1)
- return false
- end
- function isNoiseDown()
- for slot in pairs(noiseSlot) do
- turtle.select(slot)
- if turtle.compareDown() then
- turtle.select(1)
- return true
- end
- end
- turtle.select(1)
- return false
- end
- function mineForward3()
- turtle.dig()
- if isFull() then
- unloadReturn()
- end
- turtle.moveForward()
- if isFull() then
- unloadReturn()
- end
- if not useNoise or not isNoiseUp() then
- turtle.digUp()
- if isFull() then
- unloadReturn()
- end
- end
- if not useNoise or not isNoiseDown() then
- turtle.digDown()
- if isFull() then
- unloadReturn()
- end
- end
- end
- function ensureFueled(requiredFuel)
- if fuelSlot ~= nil then
- turtle.select(fuelSlot)
- while turtle.getFuelLevel() < requiredFuel do
- if turtle.getItemCount(fuelSlot) > 1 then
- turtle.refuel(1)
- else
- -- not enough fuel
- return false
- end
- end
- turtle.select(1)
- return true
- else
- return (turtle.getFuelLevel() >= requiredFuel)
- end
- end
- function mine(radius, height)
- turtle.setWaypoint("home")
- turtle.setWaypoint("mine", turtle.x, height, turtle.z + radius, 1)
- checkInventory()
- -- calculate fuel
- local requiredFuel = radius * 8 + turtle.distanceTo("mine") * 2
- while not ensureFueled(requiredFuel) do
- print("waiting for fuel...")
- io.read()
- checkInventory()
- end
- print("mining radius ", radius, " at level ", height, " with ", requiredFuel, " fuel")
- turtle.moveToWaypoint("mine", "yxz")
- -- mine ring
- for i = 1, 4 do
- for j = 1, radius do
- mineForward3()
- end
- turtle.turnRight()
- for j = 1, radius do
- mineForward3()
- end
- end
- unload()
- end
- local work = loadWork()
- while true do
- local radius, height = getWork(work, 1)
- if radius ~= nil then
- mine(radius, height)
- finishWork(work, radius, height)
- else
- print("finished")
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment