Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local robot = require("robot")
- local component = require("component")
- local geo = component.geolyzer
- local modem = false
- if(component.isAvailable("modem")) then
- modem = component.modem
- end
- local crafting = false
- if(component.isAvailable("crafting")) then
- crafting = component.crafting
- end
- local invCon = component.inventory_controller
- local event = require("event")
- local term = require("term")
- local computer = require("computer")
- local ser = require("serialization")
- local currX = 0
- local currZ = 0
- local currY = 0
- local status = "Nominal"
- local currD = "0"
- local mined = 0
- local x = 10
- local z = 10
- local y = 10
- local skip = 0
- local port = 90
- local strength = 400
- function turn(direction)
- if direction == "right" then
- currD = currD + 1
- robot.turnRight()
- elseif direction == "left" then
- currD = currD - 1
- robot.turnLeft()
- end
- if currD < 0 then
- currD = 3
- elseif currD > 3 then
- currD = 0
- end
- end
- function statusCheck()
- status = "Checking"
- if(checkPower() < 25 or checkInv() == "full" or not checkTool()) then
- resetPos(currX, currZ, currY, false)
- end
- status = "Nominal"
- end
- function sendStatus()
- if(modem) then
- modem.broadcast(port, ser.serialize({
- status = status,
- currX = currX,
- currZ = currZ,
- currY = currY,
- mined = mined,
- power = checkPower(),
- x = x,
- z = z,
- y = y,
- skip = skip
- }))
- end
- end
- function resetPos(oldX, oldZ, oldY, wait)
- status = "Returning"
- sendStatus()
- print("Returning to Origin...")
- local oldOri = currD
- local ori = 2 - currD
- for i = 1, ori do
- turn("right")
- end
- digForward(currX)
- ori = 3 - currD
- for i = 1, ori do
- turn("right")
- end
- digForward(currZ)
- digUp(currY)
- turn("left")
- local maxInv = robot.inventorySize()
- emptyInv()
- digUp(1)
- getTool()
- digDown(1)
- emptyInv()
- turn("right")
- turn("right")
- print("Recharging...")
- local percent = checkPower()
- while(percent < 99) do
- percent = checkPower()
- status = "Recharging"
- sendStatus()
- print("Recharging: " .. math.floor(percent) .. "%")
- os.sleep(1)
- end
- print("Recharged")
- print("Returning to Position")
- status = "Nominal"
- sendStatus()
- continue(oldX, oldZ, oldY, oldOri)
- end
- function continue(oldX, oldZ, oldY, oldOri)
- digDown(oldY)
- turn("right")
- digForward(oldZ)
- turn("left")
- digForward(oldX)
- local ori = oldOri - currD
- for i = 1, ori do
- turn("right")
- end
- end
- function emptyInv()
- status = "Emptying"
- sendStatus()
- local maxInv = robot.inventorySize()
- print("Emptying inventory...")
- for i = 1, maxInv do
- robot.select(i)
- robot.drop()
- end
- robot.select(1)
- end
- function getTool()
- if(not checkTool()) then
- while true do
- status = "Equipping"
- sendStatus()
- local targetInvMax = invCon.getInventorySize(3)
- if(targetInvMax == nil) then
- print("No tool inventory")
- return
- end
- print("Checking inventory...")
- for i = 1, targetInvMax do
- if(invCon.getStackInSlot(3, i) ~= nil) then
- local item = invCon.getStackInSlot(3, i)
- invCon.suckFromSlot(3, i, 1)
- if(item["name"] == "tconstruct:sharpening_kit") then
- if(not crafting) then
- print("No crafting upgrade")
- break
- end
- status = "Repairing"
- sendStatus()
- robot.select(2)
- invCon.equip()
- crafting.craft(1)
- robot.select(2)
- invCon.equip()
- else
- robot.select(1)
- invCon.equip()
- end
- print("Tool equipped!")
- return
- end
- end
- print("No tool available!")
- print("Press enter to check again...")
- status = "No tool"
- sendStatus()
- term.read()
- end
- end
- end
- function checkInv()
- local invMax = robot.inventorySize()
- local count = robot.count(invMax)
- if(count > 0) then
- return "full"
- else
- return "available"
- end
- end
- function checkTool()
- local dur = robot.durability()
- if(dur == nil or dur <= 0.05) then
- return false
- else
- return true
- end
- end
- function checkPower()
- local power = computer.energy()
- local maxPower = computer.maxEnergy()
- local percent = power/(maxPower/100)
- return percent
- end
- function digDown(distY)
- local move
- for i = 1, distY do
- sendStatus()
- move = nil
- while(move == nil) do
- if status == "Nominal" then
- statusCheck()
- end
- local dig, block = robot.swingDown()
- if block == "block" then
- mined = mined + 1
- end
- move = robot.down()
- end
- currY = currY + 1
- end
- end
- function digUp(distY)
- local move
- for i = 1, distY do
- sendStatus()
- move = nil
- while(move == nil) do
- if status == "Nominal" then
- statusCheck()
- end
- local dig, block = robot.swingUp()
- if block == "block" then
- mined = mined + 1
- end
- move = robot.up()
- end
- currY = currY - 1
- end
- end
- function digForward(distX, axis)
- local move
- for i = 1, distX do
- sendStatus()
- move = nil
- while(move == nil) do
- if status == "Nominal" then
- statusCheck()
- end
- local dig, block = robot.swing(0)
- if block == "block" then
- mined = mined + 1
- end
- move = robot.forward()
- end
- if axis == "+x" then
- currX = currX + 1
- elseif axis == "-x" then
- currX = currX - 1
- elseif axis == "+z" then
- currZ = currZ + 1
- elseif axis == "-z" then
- currZ = currZ - 1
- end
- end
- end
- function row(distX)
- print("Current Segment: " .. math.floor(currZ/3)+1)
- turn("left")
- digForward(distX, "+x")
- turn("right")
- turn("right")
- digForward(distX, "-x")
- turn("left")
- end
- function plane(distX, distZ)
- print("Current Level: " .. math.floor(currY-skip))
- row(distX)
- for i = 1, distZ do
- digForward(1, "+z")
- if(i % 3 == 0) then
- row(distX)
- end
- end
- turn("right")
- turn("right")
- digForward(distZ, "-z")
- turn("right")
- turn("right")
- end
- function start(distX, distZ, distY)
- distY = distY - 1
- distX = distX - 1
- distZ = distZ - 1
- digDown(2 + skip)
- turn("right")
- plane(distX, distZ)
- for i = 1, distY do
- digDown(1)
- if(i % 3 == 0) then
- plane(distX, distZ)
- end
- end
- status = "Returning"
- sendStatus()
- digUp(currY)
- turn("right")
- emptyInv()
- turn("left")
- turn("left")
- status = "Complete"
- sendStatus()
- print("Quarry complete!")
- end
- print("Quarry Config:")
- print("- Omit to use default values")
- print("- () = Default Values")
- term.write("X (" .. x .. "): ")
- local confX = term.read()
- if string.len(confX) > 1 then
- x = tonumber(confX)
- end
- term.write("Z (" .. z .. "): ")
- local confZ = term.read()
- if string.len(confZ) > 1 then
- z = tonumber(confZ)
- end
- term.write("Y (" .. y .. "): ")
- local confY = term.read()
- if string.len(confY) > 1 then
- y = tonumber(confY)
- end
- term.write("Skip Levels (" .. skip .. "): ")
- local confSkip = term.read()
- if string.len(confSkip) > 1 then
- skip = tonumber(confSkip)
- end
- term.write("Broadcast Port (" .. port .. "): ")
- confPort = term.read()
- if string.len(confPort) > 1 then
- port = tonumber(confPort)
- end
- term.write("Signal Strength (" .. strength .. "): ")
- confStrength = term.read()
- if string.len(confStrength) > 1 then
- strength = tonumber(confStrength)
- end
- print("\nConfirm Config:")
- print("X: " .. x)
- print("Z: " .. z)
- print("Y: " .. y)
- print("Skipping " .. skip)
- print("Broadcast Port: " .. port)
- print("Signal Strength: " .. strength)
- print("\nPress Enter to start")
- term.read()
- print("\nStarting Quarry...\n")
- if(modem) then
- modem.setStrength(strength)
- end
- start(x,z,y,skip)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement