SHARE
TWEET

Untitled

a guest Nov 17th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. --- Automatic Rubber & Birch Tree Farmer for Robots by Myros
  3. -- credits to SubThread, ...
  4.  
  5.  -- Checks if everything is ready to Start
  6. local function CheckStart()
  7.  
  8. local robot = require("robot")
  9. local component = require("component")
  10. local exp = component.experience.level()
  11. local row = 0
  12. local rowminus =0
  13.  
  14. print("Robot tree farm started")
  15.  
  16. -- 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.
  17. local treesX = 9
  18. local treesZ = 3
  19. local distanceBetweenTrees = 5
  20. local specialrow = 2
  21. Status()
  22. end
  23.  
  24. -- Goes forward eventually, no matter if something is blocking the path at the moment.
  25. local function GoForward()
  26.     while true do
  27.         local movedSuccessfuly = robot.forward()
  28.         if movedSuccessfuly then
  29.             break
  30.         end
  31.     end
  32.     robot.suck()
  33. end
  34.  
  35. -- Goes down eventually, no matter if something is blocking the path at the moment.
  36. local function GoDown()
  37.     while true do
  38.         local movedSuccessfuly = robot.down()
  39.         if movedSuccessfuly then
  40.             break
  41.         end
  42.     end
  43. end
  44.  
  45. -- Goes up eventually, no matter if something is blocking the path at the moment.
  46. local function GoUp()
  47.     while true do
  48.         local movedSuccessfuly = robot.up()
  49.         if movedSuccessfuly then
  50.             break
  51.         end
  52.     end
  53. end
  54.  
  55. -- Check if Charge or Inventory are critical
  56. local function CheckMaintenance()
  57.     if robot.space(robot.inventorySize()) > 60 then
  58.         if computer.energy() > 10000 then
  59.             return true
  60.         end
  61.     else
  62.     end
  63.     return false
  64. end
  65.  
  66. -- Handels the Maintenance
  67. local function Maintenance()
  68.     Status()
  69.     for i = 3, robot.inventorySize() do
  70.         robot.select(i)
  71.         robot.drop()
  72.     end
  73.     robot.turnAround()
  74.     while computer.energy() < 20000 do
  75.         os.sleep(20)
  76.     end
  77.     GoForward()
  78.     GoForward()
  79.     robot.turnLeft()
  80. end
  81.  
  82. -- Goes Forward until it collides
  83. local function ForwardUntilWall()
  84.     while true do
  85.         local blockFound = robot.detect()
  86.         if blockFound then
  87.             break
  88.         else
  89.             robot.down()   
  90.         end
  91.     end
  92. end
  93.  
  94. -- Goes Down until it collides
  95. local function DownUntilWall()
  96.     while true do
  97.         local blockFound = robot.detect(down)
  98.         if blockFound then
  99.             break
  100.         else
  101.             robot.down()   
  102.         end
  103.     end
  104. end
  105.  
  106. -- Fells a Tree
  107. local function Treefeller()
  108.     Sucky()
  109.     robot.turnRight()
  110.     local treeFound = robot.detect()
  111.     if treeFound then
  112.         local saplinggrowing = robot.compare()
  113.         if saplinggrowing then
  114.             robot.turnLeft()
  115.         else
  116.             robot.swing()
  117.             GoForward()
  118.             for i = 1, 6 do
  119.                 robot.swing(up)
  120.                 GoUp()
  121.             end
  122.             robot.swing(up)
  123.             DownUntilWall()
  124.             robot.turnAround()
  125.             GoForward()
  126.             robot.turnAround()
  127.             robot.place()
  128.             robot.turnLeft()
  129.             Sucky()
  130.         end
  131.     else
  132.     robot.place()
  133.     robot.turnLeft()
  134.     end
  135. end
  136.  
  137. -- Moves to the correct Row
  138. local function RowZ()
  139.     while CheckMaintenance() do
  140.         row = row + 1
  141.         if row > treesZ then
  142.             ForwardUntilWall()
  143.             row = 1
  144.         else
  145.         end
  146.         if row == 1 then
  147.             robot.turnRight()
  148.             robot.select(1)
  149.             GoForward()
  150.             MoveToTree()
  151.         else
  152.             if row == specialrow then
  153.                 robot.select(2)
  154.             else
  155.                 robot.select(1)
  156.             end
  157.             robot.turnAround()
  158.             for i = 1, distanceBetweenTrees do
  159.                 GoForward()
  160.             end
  161.             robot.turnLeft()
  162.             GoForward()
  163.             MoveToTree()           
  164.         end
  165.        
  166.        
  167.     end
  168. end
  169.  
  170. -- Move from tree to tree
  171. local function MoveToTree()
  172.     for x = 2, treesX do
  173.         for i = 1, distanceBetweenTrees do
  174.             GoForward()
  175.         end
  176.         Treefeller()
  177.     end
  178.     robot.turnAround()
  179.     for x =2, treesX do
  180.         GoForward()
  181.     end
  182.     robot.turnRight()
  183. end
  184.  
  185. -- Sucks everything up
  186. local function Sucky()
  187.     component.tractor_beam.suck()
  188. end
  189.  
  190. -- Displays the current Status
  191. local function Status()
  192.     term.clear()
  193.     print(robot.name())
  194.     print("Current EXP:")
  195.     print(exp)
  196. end
  197.  
  198.  
  199. -- Robot starts here
  200. CheckStart()
  201.  
  202. -- Do the complete cycle.
  203. while true do
  204.     Maintenance()
  205.     RowZ()
  206.     ForwardUntilWall()
  207.     robot.turnLeft()
  208.     GoForward()
  209.     GoForward()
  210. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top