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 robot = require("robot")
- local term = require("term")
- local computer = require("computer")
- local component = require("component")
- local sides = require("sides")
- 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
- 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()
- component.tractor_beam.suck()
- Status()
- 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
- 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
- else
- robot.swingUp()
- 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
- -- Goes Forward until it collides
- local function ForwardUntilWall()
- while true do
- local blockFound = robot.detect()
- if blockFound then
- break
- else
- robot.forward()
- end
- end
- end
- -- Goes Down until it collides
- local function DownUntilWall()
- while true do
- local blockFound = robot.detectDown()
- if blockFound then
- break
- else
- robot.down()
- end
- end
- end
- -- Fells a Tree
- local function Treefeller()
- Sucky()
- robot.turnRight()
- local treeFound = robot.detect()
- if treeFound then
- local saplinggrowing = robot.compare()
- if saplinggrowing then
- robot.turnLeft()
- else
- if row == specialrow then
- robot.select(2)
- robot.swingUp()
- GoUp()
- local speztreeFound = robot.detect()
- if speztreeFound then
- robot.down()
- robot.swing()
- GoForward()
- for i = 1, 6 do
- robot.swingUp()
- GoUp()
- end
- robot.swingUp()
- DownUntilWall()
- robot.turnAround()
- GoForward()
- robot.turnAround()
- robot.place()
- robot.turnLeft()
- Sucky()
- else
- robot.down()
- robot.turnLeft()
- end
- else
- robot.swing()
- GoForward()
- for i = 1, 6 do
- robot.swingUp()
- GoUp()
- end
- robot.swingUp()
- DownUntilWall()
- robot.turnAround()
- GoForward()
- robot.turnAround()
- robot.place()
- robot.turnLeft()
- Sucky()
- end
- end
- else
- robot.place()
- robot.turnLeft()
- end
- end
- -- Move from tree to tree
- local function MoveToTree()
- Treefeller()
- for x = 2, treesX do
- for i = 1, distanceBetweenTrees do
- GoForward()
- end
- Treefeller()
- end
- robot.turnAround()
- for x =2, treesX do
- for i = 1, distanceBetweenTrees do
- GoForward()
- Sucky()
- end
- end
- GoForward()
- robot.turnRight()
- end
- -- Handels the Maintenance
- local function Maintenance()
- row= 0
- Status()
- while robot.detectUp() do
- os.sleep(1)
- Status()
- end
- 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
- -- 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
- -- Robot starts here
- -- 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