Advertisement
jironpaste

Pam harvestcraft turtle farmer minecraft computercraft

Apr 6th, 2020
719
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.08 KB | None | 0 0
  1. --[[Turtle for harvesting Pam's Harvestcraft tree "fruits" (almonds,oranges,figs..).
  2. --Place Turtle infront of fruit, place a TORCH in the last slot.
  3. --The Turtle will drop any fruit collected bellow (chest etc).]]
  4. -- X are Fruits, T = turtle, C = chest, R = refuel Chest
  5. -- Think hight
  6. --    x x x x  (H = 2)
  7. --    x x x x  (Place T infront of left most X and chest under) Height = 1
  8. --   R C       (H = ground)
  9. -- https://i.imgur.com/OkK10p1.png (Basic setup shown)
  10. print("Welcome to Jiron's Pam harvest Turtle")
  11. print("Remember to place a torch in the last slot")
  12. print("Width of the farm in ODD numbers only!")
  13. re = io.read()
  14. width = tonumber(re)
  15. print("Height of farm?")
  16. rel = io.read()
  17. height = tonumber(rel)
  18. print("Farm size set to " .. width .. "x" .. height)
  19. print("Cycle time? in minutes")
  20. print("https://i.imgur.com/OkK10p1.png")
  21. print("Shows basic setup")
  22. redir = io.read()
  23.  
  24. --Farm
  25. waitTime = tonumber(redir * 60)
  26. age_metadata = 2 --metadata = 2 means the fruits are mature
  27. tUP = true
  28. start = true
  29. count = 0
  30. start = true
  31.  
  32.  
  33.  
  34. function noFaithInUser(number)
  35.     if height < 1 then
  36.         height = 1
  37.     end
  38.     if (number % 2 == 0) then
  39.         print("Error: Width is not odd in size!")
  40.         return true
  41.     end
  42.     start = false
  43.     return flase
  44. end
  45.  
  46. function detectGrowth()
  47.    
  48.     if turtle.detectUp() == true then
  49.         turtle.digUp()
  50.     end
  51.    
  52.     if turtle.detect() then
  53.         local suc, t = turtle.inspect()
  54.         if suc and t.metadata == age_metadata then
  55.            
  56.             turtle.select(16)
  57.             turtle.place()
  58.             turtle.suck()
  59.             count = count + 1
  60.             print("Item count: ", count)
  61.         --sendItemToStorage()
  62.         end
  63.     end
  64. end
  65.  
  66. function sendItemToStorage()
  67.     for i = 1, 15 do -- loop through the slots
  68.         turtle.select(i)-- change to the slot
  69.         turtle.dropDown()
  70.     end
  71. end
  72.  
  73.  
  74. function refuelTurtle()
  75.     turtle.turnLeft()
  76.     turtle.forward()
  77.     turtle.turnLeft()
  78.     turtle.turnLeft()
  79.     turtle.suckDown()
  80.     for i = 1, 15 do -- loop through the slots
  81.         turtle.select(i)-- change to the slot
  82.         if turtle.refuel(0) then -- if it's valid fuel
  83.             turtle.refuel()-- consume half the stack as fuel
  84.         end
  85.     end
  86.     sendItemToStorage()
  87.     turtle.forward()
  88.     turtle.turnLeft()
  89. end
  90.  
  91. function UpOrDown()
  92.     if tUP == true then
  93.         moveUp(height - 1)
  94.         tUP = false
  95.     else
  96.         moveDown(height - 1)
  97.         tUP = true
  98.     end
  99. end
  100.  
  101. function run()
  102.     for newWidth = width, 1, -1 do
  103.         turtle.select(16)
  104.        
  105.         if height > 0 then
  106.             if newWidth == width then
  107.                 UpOrDown()
  108.                 turtle.turnRight()
  109.                 turtle.forward()
  110.                 turtle.turnLeft()
  111.                 detectGrowth()
  112.            
  113.             else
  114.                
  115.                 UpOrDown()
  116.                 if newWidth > 1 then
  117.                     turtle.turnRight()
  118.                     turtle.forward()
  119.                     turtle.turnLeft()
  120.                     detectGrowth()
  121.                 end
  122.             end
  123.        
  124.         else
  125.             turtle.turnRight()
  126.             turtle.forward()
  127.             turtle.turnLeft()
  128.             detectGrowth()
  129.         end
  130.        
  131.         if newWidth == 1 then
  132.             returnToStart()
  133.         end
  134.    
  135.     end
  136. end
  137.  
  138. function moveUp(h)
  139.     if h >= 1 then
  140.         detectGrowth()
  141.         turtle.up()
  142.         detectGrowth()
  143.         h = h - 1
  144.         moveUp(h)
  145.     end
  146. end
  147.  
  148. function moveDown(h)
  149.     if h >= 1 then
  150.         detectGrowth()
  151.         turtle.down()
  152.         detectGrowth()
  153.         h = h - 1
  154.         moveDown(h)
  155.     end
  156. end
  157.  
  158. function move(length)
  159.     if length >= 0 then
  160.         turtle.forward()
  161.        
  162.         length = length - 1
  163.         move(length)
  164.     end
  165. end
  166.  
  167. function returnToStart()
  168.     turtle.turnLeft()
  169.    
  170.     move(width - 2)
  171.     turtle.turnRight()
  172.     UpOrDown()
  173. end
  174.  
  175.  
  176.  
  177. while true do
  178.     if start == true then
  179.         if noFaithInUser(width) == true then
  180.             break
  181.         end
  182.     end
  183.     if height == 0 then
  184.         detectGrowth()
  185.         sendItemToStorage()
  186.         sleep(waitTime)
  187.     else
  188.         detectGrowth()
  189.         run()
  190.         sendItemToStorage()
  191.         refuelTurtle()
  192.         sleep(waitTime)--checks every 60s
  193.     end
  194. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement