Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Automatic Suggar Farmer for Robots by Myros
- -- Checks if everything is ready to Start
- local robot = require("robot")
- local term = require("term")
- local computer = require("computer")
- local component = require("component")
- local sides = require("sides")
- local exp = component.experience.level()
- print("Robot Sugarcane farm started")
- local waiter = 0
- local caneX = 29
- local caneZ = 7
- local distanceToFarm = 15
- term.clear()
- -- Displays the current Status
- local function Status()
- term.clear()
- print(robot.name())
- print("Current EXP:")
- print(component.experience.level())
- print("Current Batt:")
- print(computer.energy())
- end
- -- Sucks everything up
- local function Sucky()
- while component.tractor_beam.suck() do
- Status()
- end
- end
- -- Goes forward eventually, no matter if something is blocking the path at the moment.
- local function GoForward()
- while true do
- local movedSuccessfuly = robot.forward()
- if movedSuccessfuly then
- break
- else
- robot.swing()
- end
- end
- Sucky()
- end
- -- Goes down eventually, no matter if something is blocking the path at the moment.
- local function GoDown()
- while true do
- local movedSuccessfuly = robot.down()
- if movedSuccessfuly then
- break
- end
- end
- end
- -- Goes up eventually, no matter if something is blocking the path at the moment.
- local function GoUp()
- while true do
- local movedSuccessfuly = robot.up()
- if movedSuccessfuly then
- break
- end
- end
- end
- -- Check if Charge or Inventory are critical
- local function CheckMaintenance()
- if robot.space(robot.inventorySize()) > 60 then
- if computer.energy() > 10000 then
- return true
- end
- else
- end
- return false
- end
- local function Maintenance()
- Status()
- while computer.energy() < 20000 do
- os.sleep(10)
- end
- robot.turnAround()
- GoForward()
- robot.turnAround()
- GoUp()
- for i = 1, robot.inventorySize() do
- robot.select(i)
- robot.drop()
- end
- robot.select(1)
- GoUp()
- GoForward()
- robot.turnRight()
- while robot.detect() do
- robot.turnRight()
- GoForward()
- GoDown()
- GoDown()
- robot.turnAround()
- GoForward()
- local waiter = 20
- for x = 1, 20 do
- Status()
- print("Waiting Secounds:")
- print(waiter)
- local waiter = waiter -1
- os.sleep(1)
- end
- robot.turnAround()
- GoForward()
- robot.turnAround()
- GoUp()
- GoUp()
- GoForward()
- robot.turnRight()
- end
- robot.turnRight()
- end
- local function GoToFarm()
- for i = 1, distanceToFarm do
- GoForward()
- end
- GoForward()
- end
- local function Farm()
- while CheckMaintenance() do
- Status()
- for i = 1,caneZ do
- for i = 1,caneX do
- GoForward()
- end
- robot.turnLeft()
- GoForward()
- robot.turnLeft()
- for i = 1,caneX do
- GoForward()
- end
- robot.turnRight()
- GoForward()
- robot.turnRight()
- end
- robot.turnRight()
- for i = 1,caneZ do
- GoForward()
- end
- for i = 1,caneZ do
- GoForward()
- end
- robot.turnLeft()
- end
- end
- local function GoBackFromFarm()
- robot.turnAround()
- for i = 1, distanceToFarm do
- GoForward()
- end
- GoDown()
- GoDown()
- GoForward()
- end
- -- Do the complete cycle.
- while true do
- Maintenance()
- GoToFarm()
- Farm()
- GoBackFromFarm()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement