Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- Automatic Rubber & Birch Tree Farmer for Robots by Myros
- -- credits to SubThread, ...
- -- Checks if everything is ready to Start
- local function CheckStart()
- local robot = require("robot")
- local component = require("component")
- local exp = component.experience.level()
- local row = 0
- local rowminus =0
- print("Robot tree farm started")
- -- Change these to change the tree farm grid size or the distance between each tree in the grid. Specialrow is for your 2. Sapling. if no other sapling needed, set to 0.
- local treesX = 9
- local treesZ = 3
- local distanceBetweenTrees = 5
- local specialrow = 2
- 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
- end
- end
- robot.suck()
- 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
- -- Handels the Maintenance
- local function Maintenance()
- Status()
- for i = 3, robot.inventorySize() do
- robot.select(i)
- robot.drop()
- end
- robot.turnAround()
- while computer.energy() < 20000 do
- os.sleep(20)
- end
- GoForward()
- GoForward()
- robot.turnLeft()
- end
- -- Goes Forward until it collides
- local function ForwardUntilWall()
- while true do
- local blockFound = robot.detect()
- if blockFound then
- break
- else
- robot.down()
- end
- end
- end
- -- Goes Down until it collides
- local function DownUntilWall()
- while true do
- local blockFound = robot.detect(down)
- if blockFound then
- break
- else
- robot.down()
- end
- end
- end
- -- Fells a Tree
- local function Treefeller()
- robot.turnRight()
- local treeFound = robot.detect()
- if treeFound then
- local saplinggrowing = robot.compare()
- if saplinggrowing then
- robot.turnLeft()
- else
- robot.swing()
- GoForward()
- for i = 1, 6 do
- robot.swing(up)
- GoUp()
- end
- robot.swing(up)
- DownUntilWall()
- robot.turnAround()
- GoForward()
- robot.turnAround()
- robot.place()
- robot.turnLeft()
- end
- else
- robot.place()
- robot.turnLeft()
- end
- end
- -- Moves to the correct Row
- local function RowZ()
- while CheckMaintenance() do
- row = row + 1
- if row > treesZ then
- ForwardUntilWall()
- row = 1
- else
- end
- if row == 1 then
- robot.turnRight()
- robot.select(1)
- GoForward()
- MoveToTree()
- else
- if row == specialrow then
- robot.select(2)
- else
- robot.select(1)
- end
- robot.turnAround()
- for i = 1, distanceBetweenTrees do
- GoForward()
- end
- robot.turnLeft()
- GoForward()
- MoveToTree()
- end
- end
- end
- -- Move from tree to tree
- local function MoveToTree()
- for x = 2, treesX do
- for i = 1, distanceBetweenTrees do
- GoForward()
- end
- Treefeller()
- end
- robot.turnAround()
- for x =2, treesX do
- GoForward()
- end
- robot.turnRight()
- end
- -- Sucks everything up
- local function Sucky()
- component.tractor_beam.suck()
- end
- -- Displays the current Status
- local function Status()
- term.clear()
- print(robot.name())
- print("Current EXP: ")
- print(exp)
- end
- -- Robot starts here
- CheckStart()
- -- Do the complete cycle.
- while true do
- Maintenance()
- RowZ()
- ForwardUntilWall()
- robot.turnLeft()
- GoForward()
- GoForward()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement