Advertisement
Myros27

Suggarcanefarmrobot

Nov 18th, 2019
114
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  --- Automatic Suggar Farmer for Robots by Myros
  2.  
  3.  -- Checks if everything is ready to Start
  4. local robot = require("robot")
  5. local term = require("term")
  6. local computer = require("computer")
  7. local component = require("component")
  8. local sides = require("sides")
  9. local exp = component.experience.level()
  10. print("Robot Sugarcane farm started")
  11. local waiter = 0
  12. local caneX = 29
  13. local caneZ = 7
  14. local distanceToFarm = 15
  15. term.clear()
  16.  
  17.  -- Displays the current Status
  18. local function Status()
  19.     term.clear()
  20.     print(robot.name())
  21.     print("Current EXP:")
  22.     print(component.experience.level())
  23.     print("Current Batt:")
  24.     print(computer.energy())
  25. end
  26.  
  27. -- Sucks everything up
  28. local function Sucky()
  29.     while component.tractor_beam.suck() do
  30.     Status()
  31.     end
  32. end
  33.  
  34. -- Goes forward eventually, no matter if something is blocking the path at the moment.
  35. local function GoForward()
  36.     while true do
  37.         local movedSuccessfuly = robot.forward()
  38.         if movedSuccessfuly then
  39.             break
  40.         else
  41.         robot.swing()
  42.         end
  43.     end
  44.     Sucky()
  45. end
  46.  
  47. -- Goes down eventually, no matter if something is blocking the path at the moment.
  48. local function GoDown()
  49.     while true do
  50.         local movedSuccessfuly = robot.down()
  51.         if movedSuccessfuly then
  52.             break
  53.         end
  54.     end
  55. end
  56.  
  57. -- Goes up eventually, no matter if something is blocking the path at the moment.
  58. local function GoUp()
  59.     while true do
  60.         local movedSuccessfuly = robot.up()
  61.         if movedSuccessfuly then
  62.             break
  63.         end
  64.     end
  65. end
  66.  
  67. -- Check if Charge or Inventory are critical
  68. local function CheckMaintenance()
  69.     if robot.space(robot.inventorySize()) > 60 then
  70.         if computer.energy() > 10000 then
  71.             return true
  72.         end
  73.     else
  74.     end
  75.     return false
  76. end
  77.  
  78. local function Maintenance()
  79.     Status()
  80.     while computer.energy() < 20000 do
  81.         os.sleep(10)
  82.     end
  83.     robot.turnAround()
  84.     GoForward()
  85.     robot.turnAround()
  86.     GoUp()
  87.     for i = 1, robot.inventorySize() do
  88.         robot.select(i)
  89.         robot.drop()
  90.     end
  91.     robot.select(1)
  92.     GoUp()
  93.     GoForward()
  94.     robot.turnRight()
  95.     while robot.detect() do
  96.         robot.turnRight()
  97.         GoForward()
  98.         GoDown()
  99.         GoDown()
  100.         robot.turnAround()
  101.         GoForward()
  102.         local waiter = 20
  103.         for x = 1, 20 do
  104.             Status()
  105.             print("Waiting Secounds:")
  106.             print(waiter)
  107.             local waiter = waiter -1
  108.             os.sleep(1)
  109.         end
  110.         robot.turnAround()
  111.         GoForward()
  112.         robot.turnAround()
  113.         GoUp()
  114.         GoUp()
  115.         GoForward()
  116.         robot.turnRight()
  117.     end
  118.     robot.turnRight()
  119. end
  120.  
  121. local function GoToFarm()
  122.     for i = 1, distanceToFarm do
  123.         GoForward()
  124.     end
  125.     GoForward()
  126. end
  127.  
  128. local function Farm()
  129.     while CheckMaintenance() do
  130.         Status()
  131.         for i = 1,caneZ do
  132.             for i = 1,caneX do
  133.                 GoForward()
  134.             end
  135.             robot.turnLeft()
  136.             GoForward()
  137.             robot.turnLeft()
  138.             for i = 1,caneX do
  139.                 GoForward()
  140.             end
  141.             robot.turnRight()
  142.             GoForward()
  143.             robot.turnRight()
  144.         end
  145.         robot.turnRight()
  146.         for i = 1,caneZ do
  147.             GoForward()
  148.         end
  149.         for i = 1,caneZ do
  150.             GoForward()
  151.         end
  152.         robot.turnLeft()
  153.     end
  154. end
  155.  
  156. local function GoBackFromFarm()
  157.     robot.turnAround()
  158.     for i = 1, distanceToFarm do
  159.         GoForward()
  160.     end
  161.     GoDown()
  162.     GoDown()
  163.     GoForward()
  164. end
  165.  
  166. -- Do the complete cycle.
  167. while true do
  168.     Maintenance()
  169.     GoToFarm()
  170.     Farm()
  171.     GoBackFromFarm()
  172. end
Advertisement
RAW Paste Data Copied
Advertisement