Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local robot = require("robot")
- local computer = require("computer")
- local component = require("component")
- local sides = require("sides")
- local os = require("os")
- function moveGeneric(move, detect, swing)
- if detect() then swing() end
- if not move() then computer.shutdown() end
- end
- function moveForward()
- moveGeneric(robot.forward, robot.detect, robot.swing)
- end
- function moveUp()
- moveGeneric(robot.up, robot.detectUp, robot.swingUp)
- end
- function moveDown()
- moveGeneric(robot.down, robot.detectDown, robot.swingDown)
- end
- function shouldMine(side)
- local info = component.geolyzer.analyze(side)
- return info and info.name and (info.name:match(".*[oO]re.*") or info.name:match("blockMisc") or info.name:match("resource"))
- end
- function faceDirection(side)
- while side ~= component.navigation.getFacing() do
- robot.turnLeft()
- end
- end
- function scanDig()
- if robot.detectUp() and shouldMine(sides.top) then
- moveUp()
- scanDig()
- moveDown()
- end
- if robot.detectDown() and shouldMine(sides.bottom) then
- moveDown()
- scanDig()
- moveUp()
- end
- for i=2,5,1 do
- if shouldMine(i) then
- if i == sides.right then robot.turnRight()
- elseif i == sides.left then robot.turnLeft()
- elseif i == sides.back then robot.turnAround()
- end
- moveForward()
- scanDig()
- robot.back()
- if i == sides.right then robot.turnLeft()
- elseif i == sides.left then robot.turnRight()
- elseif i == sides.back then robot.turnAround()
- end
- end
- end
- end
- function placeCobble()
- if not robot.detectDown() then
- robot.select(2)
- robot.placeDown()
- end
- end
- function mineTunnel()
- local distance = 120
- for ix=1,distance/2,1 do
- scanDig()
- placeCobble()
- moveUp()
- scanDig()
- moveForward()
- scanDig()
- moveDown()
- scanDig()
- if ix % 4 == 0 then
- robot.select(1)
- if not robot.placeUp(sides.right) then
- robot.placeUp(sides.left)
- end
- end
- placeCobble()
- moveForward()
- end
- robot.turnAround()
- for i=1,distance,1 do
- moveForward()
- end
- end
- local branchDistance = 36
- function mineBranch()
- print("Mining Branch")
- print(branchDistance)
- faceDirection(sides.south)
- for i=1,branchDistance,1 do
- moveForward()
- end
- faceDirection(sides.east)
- mineTunnel()
- faceDirection(sides.north)
- for i=1,branchDistance,1 do
- moveForward()
- end
- if component.geolyzer.analyze(sides.front).name:match("Chest") then
- for i=3,robot.inventorySize(),1 do
- robot.select(i)
- robot.drop()
- end
- else
- print("No chest to drop items.")
- end
- end
- mineBranch()
- while (computer.energy() + 500 < computer.maxEnergy()) do
- os.sleep(500)
- end
- branchDistance = 42
- mineBranch()
- local x = 657
- local y = 11
- local z = -992
- computer.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement