Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.95 KB | None | 0 0
  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.  
  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.     robot.turnRight()
  109.     local treeFound = robot.detect()
  110.     if treeFound then
  111.         local saplinggrowing = robot.compare()
  112.         if saplinggrowing then
  113.             robot.turnLeft()
  114.         else
  115.             robot.swing()
  116.             GoForward()
  117.             for i = 1, 6 do
  118.                 robot.swing(up)
  119.                 GoUp()
  120.             end
  121.             robot.swing(up)
  122.             DownUntilWall()
  123.             robot.turnAround()
  124.             GoForward()
  125.             robot.turnAround()
  126.             robot.place()
  127.             robot.turnLeft()
  128.         end
  129.     else
  130.     robot.place()
  131.     robot.turnLeft()
  132.     end
  133. end
  134.  
  135. -- Moves to the correct Row
  136. local function RowZ()
  137.     while CheckMaintenance() do
  138.         row = row + 1
  139.         if row > treesZ then
  140.             ForwardUntilWall()
  141.             row = 1
  142.         else
  143.         end
  144.         if row == 1 then
  145.             robot.turnRight()
  146.             robot.select(1)
  147.             GoForward()
  148.             MoveToTree()
  149.         else
  150.             if row == specialrow then
  151.                 robot.select(2)
  152.             else
  153.                 robot.select(1)
  154.             end
  155.             robot.turnAround()
  156.             for i = 1, distanceBetweenTrees do
  157.                 GoForward()
  158.             end
  159.             robot.turnLeft()
  160.             GoForward()
  161.             MoveToTree()           
  162.         end
  163.        
  164.        
  165.     end
  166. end
  167.  
  168. -- Move from tree to tree
  169. local function MoveToTree()
  170.     for x = 2, treesX do
  171.         for i = 1, distanceBetweenTrees do
  172.             GoForward()
  173.         end
  174.         Treefeller()
  175.     end
  176.     robot.turnAround()
  177.     for x =2, treesX do
  178.         GoForward()
  179.     end
  180.     robot.turnRight()
  181. end
  182.  
  183. -- Sucks everything up
  184. local function Sucky()
  185.     component.tractor_beam.suck()
  186. end
  187.  
  188. -- Displays the current Status
  189. local function Status()
  190.     term.clear()
  191.     print(robot.name())
  192.     print("Current EXP: ")
  193.     print(exp)
  194. end
  195.  
  196.  
  197. -- Robot starts here
  198. CheckStart()
  199.  
  200. -- Do the complete cycle.
  201. while true do
  202.     Maintenance()
  203.     RowZ()
  204.     ForwardUntilWall()
  205.     robot.turnLeft()
  206.     GoForward()
  207.     GoForward()
  208. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement