Advertisement
Guest User

Farm

a guest
Nov 25th, 2015
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.09 KB | None | 0 0
  1. local robot = require("robot")
  2. local term = require("term")
  3.  
  4. local cyclesRun = 0
  5.  
  6. function moveForward()
  7.   while not (robot.forward()) do
  8.     os.sleep(1)
  9.   end
  10. end
  11.  
  12. function pickMove()
  13.   robot.useDown()
  14.   moveForward()
  15. end
  16.  
  17. function farmRow()
  18.   for i=1, 8 do
  19.     pickMove()
  20.   end
  21.   robot.useDown()
  22. end
  23.  
  24. function nextRow(row)
  25.   if row % 2 == 1 then
  26.     robot.turnLeft()
  27.     moveForward()
  28.     robot.turnLeft()
  29.   else
  30.     robot.turnRight()
  31.     moveForward()
  32.     robot.turnRight()
  33.   end
  34. end
  35.  
  36. function farmPatch()
  37.   for i = 1, 7 do
  38.     farmRow()
  39.     nextRow(i)
  40.   end
  41. end
  42.  
  43. function moveHome()
  44.   for i = 1, 9 do
  45.     moveForward()
  46.   end
  47.   robot.turnLeft()
  48.   for i = 1, 7 do
  49.     moveForward()
  50.   end
  51. end
  52.  
  53. function dumpItems()
  54.   for i = 1, 16 do
  55.     robot.select(i)
  56.     robot.drop()
  57.   end
  58.   robot.select(1)
  59. end
  60.  
  61. function farm()
  62.   cyclesRun = cyclesRun + 1
  63.   updateScreen()
  64.   moveForward()
  65.   farmPatch()
  66.   moveHome()
  67.   robot.turnRight()
  68.   dumpItems()
  69.   robot.turnAround()
  70. end
  71.  
  72. function updateScreen()
  73.   term.clear()
  74.   term.setCursor(1,1)
  75.   term.write("Running cycle " .. cyclesRun)
  76. end
  77.  
  78. while true do
  79.   farm()
  80.   os.sleep(300)
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement