Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local r = require("robot")
- local component = require("component")
- local sides = require("sides")
- local computer = require("computer")
- local inv = component.inventory_controller
- local minDurability=0.1
- local minTourches=1
- local minEnergy=1000
- local torchDistance=11
- local torchSlot=1
- function turnAround()
- r.turnRight()
- r.turnRight()
- end
- function forward()
- while not r.forward() do
- r.swing()
- end
- end
- function up()
- while not r.up() do
- r.swingUp()
- end
- end
- function down()
- while not r.down() do
- r.swingDown()
- end
- end
- function back()
- while not r.back() do
- turnAround()
- dig()
- turnAround()
- end
- end
- function dig()
- r.swing()
- while r.detect() do
- r.swing()
- end
- end
- function digUp()
- r.swingUp()
- while r.detectUp() do
- r.swingUp()
- end
- end
- function digDown()
- r.swingDown()
- while r.detectDown() do
- r.swingDown()
- end
- end
- function checkFull()
- for i=1,16 do
- if r.count(i)==0 then
- return false
- end
- end
- return true
- end
- function digLayer()
- dig()
- forward()
- digUp()
- digDown()
- r.turnRight()
- dig()
- forward()
- digUp()
- digDown()
- turnAround()
- forward()
- dig()
- forward()
- digUp()
- digDown()
- back()
- r.turnRight()
- end
- --Dumps entire inv down
- --Returns False if inv full
- function dumpDown()
- for i=2,16 do
- r.select(i)
- r.dropDown()
- end
- for i=1,54 do
- if inv.getSlotStackSize(sides.down,i)==0 then
- return true
- end
- end
- return false
- end
- --Returns false if the robot needs to return
- function checkStatus()
- if r.durability()==nil or r.durability()<minDurability then
- print("-Durability Ran Out")
- return false
- elseif checkFull() then
- print("-INV Filled Up")
- return false
- elseif r.count(torchSlot)<=minTourches then
- print("-Ran Out Of Torches")
- return false
- elseif computer.energy()<minEnergy then
- print("-Low On Energy")
- return false
- end
- return true
- end
- function placeTorch()
- r.select(torchSlot)
- r.placeDown()
- end
- function pitStop()
- if not dumpDown() then
- os.exit()
- end
- r.turnRight()
- r.select(torchSlot)
- r.suck()
- if r.count(torchSlot)<0 then
- os.exit()
- end
- turnAround()
- if r.durability()<minDurability then
- r.select(2)
- r.suck()
- inv.equip()
- r.dropUp()
- if r.durability==nil or r.durability()<minDurability then
- os.exit()
- end
- end
- r.turnRight()
- if computer.energy()<minEnergy then
- os.exit()
- end
- end
- function mine()
- local depth=0
- up()
- back()
- r.turnLeft()
- r.select(1)
- r.suck()
- inv.equip()
- turnAround()
- r.select(torchSlot)
- r.suck()
- r.turnLeft()
- forward()
- while true do
- while checkStatus() do
- print("Depth: "..depth)
- dig()
- forward()
- if depth%torchDistance==0 then
- placeTorch()
- end
- depth=depth+1
- end
- turnAround()
- for i = 0,depth do
- forward()
- end
- turnAround()
- pitStop()
- for i=0,depth do
- forward()
- end
- end
- end
- mine()
Add Comment
Please, Sign In to add comment