NiallDoherty

Farm

Jul 20th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. local tArgs = {...}
  2. forward = tArgs[1] - 1
  3. across = tArgs[2]
  4. direction = tArgs[3]
  5.  
  6. function move()
  7.     while not turtle.forward() do
  8.         turtle.attack()
  9.         turtle.dig()
  10.     end
  11. end
  12.  
  13. function dig()
  14.   if turtle.detectDown() then
  15.     turtle.digDown()
  16.     turtle.placeDown()
  17.   end
  18. end
  19.  
  20. function changeDirection()
  21.     if(direction == "right") then
  22.     direction = "left"
  23.   else
  24.     direction = "right"
  25.   end
  26. end
  27.  
  28. function mineForward(length)
  29.     for x = 0, length do
  30.         dig()
  31.         if(x < tonumber(length)) then      
  32.             move()
  33.         end
  34.     end
  35. end
  36.  
  37. function turn()
  38.   if(direction == "right") then
  39.     turtle.turnRight()
  40.   else
  41.     turtle.turnLeft()
  42.   end
  43. end
  44.  
  45. function nextRow()
  46.     turn()
  47.     mineForward(1)
  48.     turn()
  49.     changeDirection()
  50. end
  51.  
  52. function unload()
  53.   for i = 2, 16 do
  54.     turtle.select(i)
  55.     turtle.dropUp()
  56.   end
  57.   turtle.select(1)
  58. end
  59.  
  60. function goHome()
  61.   for i = 1, forward do
  62.     move()
  63.   end
  64.   turtle.turnRight()
  65.   for i = 1, forward do
  66.     move()
  67.   end
  68.   turtle.turnRight()
  69. end
  70. function main()
  71.         for y = 1, across do
  72.             mineForward(forward)
  73.             if(y < tonumber(across)) then
  74.                 nextRow()  
  75.    else
  76.      turn()
  77.      turn()
  78.             end
  79.         end
  80. end
  81.  
  82. while true do
  83.   main()
  84.   goHome()
  85.   unload()
  86.   print("1.5 hours remaining")
  87.   sleep(1800)
  88.   print("1 hour remaining")
  89.   sleep(1800)
  90.   print("Half an hour remaining")
  91.   sleep(1700)
  92.   for x = 1, 10 do
  93.     print(x.. " seconds until harvest")
  94.     sleep(1)
  95.   end
  96. end
Add Comment
Please, Sign In to add comment