dealingwith

Square Farmer

Feb 17th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.14 KB | None | 0 0
  1. function fuel()
  2.   if turtle.getFuelLevel() < 10 then
  3.     turtle.select(1)
  4.     if turtle.refuel(1) then
  5.       return true
  6.     end
  7.     print("Refuelling failed.")
  8.     return false
  9.   end
  10. end
  11.  
  12. function right()
  13.   turtle.turnRight()
  14. end
  15.  
  16. function left()
  17.   turtle.turnLeft()
  18. end
  19.  
  20. function forward()
  21.   turtle.forward()
  22. end
  23.  
  24. function digDown()
  25.   turtle.digDown()
  26. end
  27.  
  28. function suckDown()
  29.   turtle.suckDown()
  30. end
  31.  
  32. function fif(val, a, b)
  33.   if val then a() else b() end
  34. end
  35.  
  36. function fif_flip(val, a, b)
  37.   if val then a() else b() end
  38.   return not val
  39. end
  40.  
  41. function farm_row(len)
  42.   for i=1,len,1 do
  43.     fuel()
  44.     forward()
  45.     digDown()
  46.     turtle.select(3)
  47.     suckDown()
  48.     turtle.select(2)
  49.     turtle.placeDown()
  50.   end
  51. end
  52.  
  53. function farm(len)
  54.   local turn_right = true
  55.   for i=1,len,1 do
  56.     farm_row(len)
  57.     forward()
  58.     fif(turn_right, right, left)
  59.     forward()
  60.     turn_right = fif_flip(turn_right, right, left)
  61.   end
  62.   left()
  63.   for i=1,len,1 do
  64.     forward()
  65.   end
  66.   for i=3,16,1 do
  67.     turtle.select(i)
  68.     turtle.drop()
  69.   end
  70.   right()
  71. end
  72.  
  73. while true do
  74.   farm(8)
  75.   os.sleep(2400)
  76. end
Advertisement
Add Comment
Please, Sign In to add comment