Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local computer = require("computer")
- local inventory = component.inventory_controller
- local robot = require("robot")
- local generator = component.generator
- if generator == nil then
- print("No generator component found, please install!")
- end
- local status = "running"
- local StripsMined = 0
- function refuel()
- -- try to refuel from inventory
- for i = 1, 16 do
- robot.select(i)
- generator.insert()
- end
- -- Check if we did refuel
- if generator.count() > 1 then
- return true
- else
- return false
- end
- end
- -- Check fuel in generator
- function checkFuel()
- if generator.count() > 5 then
- return true
- else
- -- No fuel in generator, try to insert fuel from inventory
- refuel()
- if generator.count() > 5 then
- return true
- else
- return false
- end
- end
- end
- -- Check Energy in robot
- function checkEnergy()
- Energy = computer.energy() / computer.maxEnergy() * 100
- if Energy < 10 and checkFuel() == false then
- return false
- else
- return true
- end
- end
- -- Check held item durability
- function checkDurability()
- -- robot.durability() returns durability percentage from 0-1
- if robot.durability() == nil then
- print("Robot has no tool in tool slot")
- return false
- end
- if robot.durability() > 0.05 then
- return true
- else
- return false
- end
- end
- -- Check if we have space in the inventory
- function checkInventorySpace()
- for i = 1, 16 do
- robot.select(i)
- if robot.space() == 64 then
- return true
- else
- end
- end
- return false
- end
- -- Notify chest placement position
- print("Please place a chest directly to the right of the robot")
- os.sleep(1)
- -- Check if we have fuel in the generator
- if generator.count() < 5 then
- print("WARNING: Low amounts of fuel in generator!")
- os.sleep(0.5)
- print("Do you wish to refuel now? (Y / N)")
- refuelAction = io.read()
- else
- refuelAction = nil
- end
- if refuelAction ~= nil and refuelAction == "Y" then
- refuel()
- else
- end
- print("Input the depth of the stripmine..")
- depth = io.read()
- print("Input amount of strips..")
- amount = io.read()
- -- Move forward Function
- function moveForward()
- if robot.detect(forward) == true then
- robot.swing()
- robot.forward()
- else
- robot.forward()
- end
- while robot.detectUp() == true do
- robot.swingUp()
- os.sleep(1) -- wait in case sand or gravel
- end
- end
- -- Return to chest location
- -- Call only after exiting a strip facing outward
- function returnToChest()
- -- turn to face chest
- robot.turnLeft()
- if StripsMined > 0 then
- for i = 1, StripsMined do
- moveForward()
- moveForward()
- moveForward()
- end
- end
- if robot.detect(front) == true then
- local front = 3
- for i = 1, 16 do
- robot.select(i)
- if robot.space() ~= 64 then
- for chestSlot = 1, 27 do
- if inventory.getStackInSlot(front,chestSlot) == nil then
- inventory.dropIntoSlot(front, chestSlot, 64)
- end
- end
- end
- end
- --wait for emptying
- for k = 1, 16 do
- robot.select(k)
- if robot.space() ~= 64 then
- status = "no_inv_chest_full"
- print("Chest is full..")
- end
- end
- -- Reset status if inventory was a problem
- if status == "no_inv" then
- status = "running"
- end
- robot.select(1)
- else
- print("ERROR: No Chest Found in front of expected position")
- end
- -- return to to strip mine position
- robot.turnRight()
- robot.turnRight()
- if StripsMined > 0 then
- for i = 1, StripsMined do
- moveForward()
- moveForward()
- moveForward()
- end
- end
- end
- -- Start Strip mining
- for i = 1, amount do
- local BlocksMovedInStrip = 0
- for i = 1, depth do
- BlocksMovedInStrip = i
- if checkEnergy() == true then
- if checkDurability() == true then
- if checkInventorySpace() == true then
- moveForward()
- else
- status = "no_inv"
- print("No Inventory Space")
- break
- end
- else
- status = "no_durability"
- print("No Durability")
- break
- end
- else
- status = "no_energy"
- print("No Energy")
- break
- end
- end
- -- After first loop completed or canceled
- if status == "running" then
- robot.turnRight()
- robot.turnRight()
- for i = 1, depth do
- moveForward()
- end
- else
- if BlocksMovedInStrip > 1 then
- robot.turnRight()
- robot.turnRight()
- for i = 1, BlocksMovedInStrip do
- moveForward()
- end
- end
- end
- returnToChest()
- -- Check if we are still green
- if status == "running" then
- --robot.turnRight()
- moveForward()
- moveForward()
- moveForward()
- robot.turnRight()
- StripsMined = StripsMined + 1
- else
- robot.turnRight()
- robot.turnRight()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement