Advertisement
xmarks

FTB Automatic Farm V 2.0

Jan 12th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.50 KB | None | 0 0
  1. -- FTB AutomaticFarm - V 2.0
  2. -- Made by Xmarks
  3. -- https://www.youtube.com/channel/UCA6oAnFqdDcc0sa6H8G5DSA
  4. -- Program Farms and Replants Seeds
  5. -- Program ensures the operation can not be blocked
  6. -- Program Drops Excess Inventory in a chest below when Operation is finished
  7. -- *********************************
  8. -- Fuel Goes to Slot 1
  9. -- Seeds for comparison go to Slot 2
  10. -- *********************************
  11.  
  12. -- Set Coordinates for where the Turtle will farm
  13. x = 4
  14. y = 4
  15.  
  16. -- Global Seed Slot Variable - Do not Change
  17. seed_slot = 0
  18.  
  19. -- Local Function - Check Fuel Level - Refuel if necessary
  20. -- TODO: Calculate Path and do not start if not enough for 1 Full Operation
  21. local function checkFuel()
  22.     if turtle.getFuelLevel() < 20 then
  23.         turtle.select(1)
  24.         turtle.refuel(1)
  25.     end
  26. end
  27.  
  28. -- Local Function - Ensure Turtle Moves Forward 1 Block
  29. local function forward()
  30.     checkFuel()
  31.     counter = 0
  32.    
  33.     while counter < 1 do
  34.         if turtle.forward() then
  35.             counter = counter + 1
  36.         -- If can not move, try digging and attacking
  37.         else
  38.             turtle.dig()
  39.             turtle.attack()
  40.         end
  41.     end
  42. end
  43.  
  44. -- Left U-Turn
  45. local function goLeft()
  46.     turtle.turnLeft()
  47.     forward()
  48.     turtle.turnLeft()
  49. end
  50.  
  51. -- Right U-Turn
  52. local function goRight()
  53.     turtle.turnRight()
  54.     forward()
  55.     turtle.turnRight()
  56. end
  57.  
  58. -- Function Tries to find seeds
  59. local function findSeeds()
  60.     for i = 3,16 do
  61.         turtle.select(i)
  62.         if turtle.compareTo(2) then
  63.             return i
  64.         end
  65.     end
  66.     -- if Seeds are not found - Reset to Slot 2
  67.     return 2
  68. end
  69.  
  70. -- Turtle Plows/Harvests & Plants Seeds
  71. local function harvestReplant()
  72.  
  73.     turtle.digDown()
  74.    
  75.     -- Go to Saved Seed Slot if set during Operation
  76.     if seed_slot ~= 0 then
  77.         turtle.select(seed_slot)
  78.     end
  79.    
  80.     -- If Seed Slot is not set
  81.     -- If Seed Slot is the Comparison Slot
  82.     -- If Saved Seed Slot Count is 0
  83.     -- If Saved Seed Slot does not actually have Seeds
  84.     if ( (seed_slot == 0) or (seed_slot == 2) or (turtle.getItemCount(seed_slot) == 0) or (turtle.compareTo(2) == false) ) then
  85.         seed_slot = findSeeds()
  86.         turtle.select(seed_slot)
  87.     end
  88.  
  89.     turtle.placeDown()
  90. end
  91.  
  92. -- Farming Function
  93. -- Turtle will go around the set Matrix x/y
  94. -- Plowing/Harvesting and Planting
  95. local function farm()
  96.     for i = 1,x do
  97.         if i%2 == 1 then
  98.             goLeft()
  99.            
  100.             for j =1,y do
  101.                 harvestReplant()
  102.                 if j ~= y then
  103.                     forward()
  104.                 end
  105.             end
  106.            
  107.         elseif i%2 == 0 then
  108.             goRight()
  109.            
  110.             for j = 1,y do
  111.                 harvestReplant()
  112.                 if j ~= y then
  113.                     forward()
  114.                 end
  115.             end
  116.         end
  117.     end
  118. end
  119.  
  120. -- Turns the Turtle back to Starting Position
  121. -- Calculations based on the given Farm Matrix-Size x/y
  122. local function returnHome()
  123.     if x%2 == 0 then
  124.         forward()
  125.         turtle.turnRight()
  126.        
  127.         for i = 1,x do
  128.             forward()
  129.         end
  130.        
  131.     elseif x%2 == 1 then
  132.         turtle.turnLeft()
  133.         turtle.turnLeft()
  134.        
  135.         for j = 1,y do
  136.             forward()
  137.         end
  138.        
  139.         turtle.turnRight()
  140.        
  141.         for i = 1,x do
  142.             forward()
  143.         end
  144.     end
  145.    
  146.     turtle.turnRight()
  147.     forward()
  148.     turtle.turnLeft()
  149.     turtle.turnLeft()
  150. end
  151.  
  152. -- Wait for Seeds to Grow Back - 35min
  153. local function timeOut()
  154.     for i = 2100,0,-1 do
  155.         print('Waiting Seed Growth - ' .. i .. 'sec left')
  156.         sleep(1)
  157.     end
  158. end
  159.  
  160. -- Drop Everything except Fuel and Comparison Seeds
  161. local function dumpInventory()
  162.     print('Dropping all blocks in slots 3-to-16 into a bottom chest')
  163.    
  164.     for slot = 3,16 do
  165.         turtle.select(slot)
  166.         turtle.dropDown()
  167.     end
  168. end
  169.  
  170. -- Farm/Return/Wait/Repeat
  171. while true do
  172.   farm()
  173.   returnHome()
  174.   dumpInventory()
  175.   timeOut()
  176. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement