Advertisement
Guest User

fertilize

a guest
Mar 24th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.35 KB | None | 0 0
  1. --Initialize variables
  2. local xParkLocation = -1
  3. local xCoord = xParkLocation
  4. local yParkLocation = 0
  5. local yCoord = yParkLocation
  6. local xMinCoord = 0
  7. local xMaxCoord = 6
  8. local yMinCoord = 0
  9. local yMaxCoord = 6
  10. local xStart = xMinCoord --Set the starting X location equal to the min X coordinate
  11. local xLimit = xMaxCoord --Sets the ending X location equal to the max X coordinate
  12. local xDirection = 1 --1 goes forward and -1 goes backward
  13. local stuckTimer = 3 --Number of seconds to delay before retrying move
  14.  
  15. --Create Fertilization function
  16. local function fertilize()
  17.  
  18.   --Loop through all Y coordinates
  19.   for y = yMinCoord, yMaxCoord, 1 do
  20.  
  21.     --Loop through all X coordinates at the current Y coordinate
  22.     for x = xStart, xLimit, xDirection do
  23.  
  24.       --Use BoneMeal
  25.       turtle.select(9)
  26.       turtle.placeDown()
  27.      
  28.       --Determine where the turtle should go based on its direction
  29.       if xDirection == 1 then
  30.      
  31.         --Make sure the turtle doesn't go past the max X coordinate
  32.         if x < xMaxCoord then
  33.          
  34.           --Move the turtle forward 1 block
  35.  
  36.           while turtle.forward() == false do
  37.  
  38.             print("Get out of my way!")
  39.             sleep(stuckTimer)
  40.  
  41.           end
  42.          
  43.           --Update the X coordinate variable
  44.           xCoord = xCoord + xDirection
  45.        
  46.         else
  47.        
  48.           --Make sure the turtle doesn't go past the max Y coordinate
  49.           if yCoord < yMaxCoord then
  50.              
  51.             --Move to the next row
  52.             turtle.turnLeft()
  53.             while turtle.forward() == false do
  54.  
  55.               print("Get out of my way!")
  56.               sleep(stuckTimer)
  57.  
  58.             end
  59.             turtle.turnLeft()
  60.            
  61.             -- Set "for" loop variables
  62.               --for next row
  63.               xStart = xMaxCoord
  64.               xLimit = xMinCoord
  65.               xDirection = -1
  66.            
  67.             end
  68.        
  69.         end
  70.      
  71.       else
  72.      
  73.         --Make sure the turtle doesn't go past the min X coordinate
  74.         if x > xMinCoord then
  75.        
  76.           --Move the turtle forward 1 block
  77.           while turtle.forward() == false do
  78.  
  79.             print("Get out of my way!")
  80.             sleep(stuckTimer)
  81.  
  82.           end
  83.  
  84.           xCoord = xCoord + xDirection
  85.        
  86.         else
  87.        
  88.           --Make sure the turtle doesn't go past the max Y coordinate
  89.             if yCoord < yMaxCoord then
  90.            
  91.             --Move to next row
  92.             turtle.turnRight()
  93.             while turtle.forward() == false do
  94.  
  95.               print("Get out of my way!")
  96.               sleep(stuckTimer)
  97.  
  98.             end
  99.  
  100.             turtle.turnRight()
  101.            
  102.             -- Set "for" loop variables
  103.                 --for next row
  104.               xStart = xMinCoord
  105.               xLimit = xMaxCoord
  106.               xDirection = 1
  107.            
  108.             end
  109.        
  110.         end
  111.      
  112.       end
  113.    
  114.     end
  115.    
  116.     --Update the X coordinate variable
  117.     if y < yMaxCoord then
  118.    
  119.         yCoord = yCoord + 1
  120.    
  121.     end
  122.  
  123.   end
  124.  
  125. end
  126.  
  127.  
  128.  
  129. --Create return to storage function
  130. local function returnToStorage()
  131.  
  132.   --Turn the turtle to face toward Y 0
  133.   turtle.turnRight()
  134.  
  135.   --Move the turtle to Y 0
  136.   for y = yCoord, yParkLocation, -1 do
  137.  
  138.     --Make sure the turtle doesn't go past the min Y coordinate
  139.     if y > yMinCoord then
  140.    
  141.       --Move the turtle forward 1 block
  142.       while turtle.forward() == false do
  143.  
  144.         print("Get out of my way!")
  145.         sleep(stuckTimer)
  146.  
  147.       end
  148.      
  149.     end
  150.  
  151.   end
  152.  
  153.   --Turn the turtle to face toward X 0
  154.   turtle.turnRight()
  155.  
  156.   --Move the turtle to X -1
  157.   for x = xCoord, xParkLocation, -1 do
  158.  
  159.      --Make sure the turtle doesn't go past the X park coordinate
  160.     if x >= xParkLocation then
  161.  
  162.       --Move the turtle back 1 block
  163.       while turtle.forward() == false do
  164.  
  165.         print("Get out of my way!")
  166.         sleep(stuckTimer)
  167.  
  168.       end
  169.  
  170.  
  171.     end
  172.    
  173.   end
  174.  
  175.   turtle.turnLeft()
  176.   turtle.turnLeft()
  177.  
  178. end
  179.  
  180. --Exit storage
  181. while turtle.forward() == false do
  182.  
  183.   print("Get out of my way!")
  184.   sleep(stuckTimer)
  185.  
  186. end
  187.  
  188. --Select BoneMeal slot
  189. turtle.select(9)
  190.  
  191. --Fertilize
  192. fertilize()
  193.  
  194. --Return to storage
  195. returnToStorage()
  196.  
  197. --Write to the console window
  198. print( "Fertilization Complete, Please add more Bonemeal" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement