Gellis12

Farmer

Oct 2nd, 2014
1,281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. local arguments={...}
  2. if #arguments~=1 then
  3.   print("Usage: Farmer <Side Length>")
  4.   return
  5. end
  6. local length=tonumber(arguments[1])
  7. if length<2 then
  8.   print("Side length must be greater than 1")
  9.   return
  10. end
  11.  
  12. function blockHarvest()
  13.   turtle.digDown()
  14.   turtle.placeDown()
  15. end
  16.  
  17. function row(dist)
  18.   for l=1, dist, 1 do
  19.     blockHarvest()
  20.     if l~=dist then
  21.       while not turtle.forward() do
  22.         turtle.dig()
  23.         turtle.attack()
  24.       end
  25.     end
  26.   end
  27. end
  28.  
  29. if math.fmod(length, 2)==0 then
  30.   for i=1, math.ceil(length/2), 1 do
  31.     row(length)
  32.     turtle.turnRight()
  33.    
  34.     while not turtle.forward() do
  35.       turtle.dig()
  36.       turtle.attack()
  37.     end
  38.    
  39.     turtle.turnRight()
  40.    
  41.     row(length)
  42.     if i~=math.ceil(length/2) then
  43.       turtle.turnLeft()
  44.      
  45.       while not turtle.forward() do
  46.         turtle.dig()
  47.         turtle.attack()
  48.       end
  49.      
  50.       turtle.turnLeft()
  51.     else
  52.       turtle.turnRight()
  53.     end
  54.   end
  55.    
  56.   for q=2, length, 1 do
  57.     turtle.forward()
  58.   end
  59.  
  60.   turtle.turnRight()
  61. else
  62.   for i=1, math.ceil((length-1)/2) do
  63.     row(length)
  64.    
  65.     turtle.turnRight()
  66.     while not turtle.forward() do
  67.       turtle.dig()
  68.       turtle.attack()
  69.     end
  70.     turtle.turnRight()
  71.    
  72.     row(length)
  73.    
  74.     turtle.turnLeft()
  75.     while not turtle.forward() do
  76.       turtle.dig()
  77.       turtle.attack()
  78.     end
  79.     turtle.turnLeft()
  80.   end
  81.   row(length)
  82.  
  83.   turtle.turnLeft()
  84.   for q=2, length, 1 do
  85.     turtle.forward()
  86.   end
  87.   turtle.turnLeft()
  88.   for q=2, length, 1 do
  89.     turtle.forward()
  90.   end
  91.   turtle.turnRight()
  92.   turtle.turnRight()    
  93. end
Advertisement
Add Comment
Please, Sign In to add comment