Advertisement
Guest User

Turtle planter (dye sapling) v4

a guest
Oct 31st, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.63 KB | None | 0 0
  1. --
  2. -- Turtle planter for dye saplings
  3. --
  4. -- Dye sapling have two major problems wich make them hard to farm:
  5. --  * Dye sapling don't work with MFR planter and Multifarm.
  6. --  * Dye saplings produce blood wood wich don't work properly with
  7. --    MFR harvester.
  8. --
  9. -- This program plant the given sapling every two blocks in a square shape,
  10. -- and harvest blood wood when the turtle are in front of it.
  11. --
  12. -- HOWTO USE
  13. -- ---------
  14. -- The *entire inventory* must be filled with sapling, exepted the last
  15. -- slot, wich must contain at least one blood wood log.
  16. --
  17. -- NOTES
  18. -- -----
  19. -- The turtle expect blood wood to grow in a 3x3 square, wich seems
  20. -- to be the case with dye sapling.  It also expect that the blood
  21. -- wood tree begin to diverge in a 3x3 shape two blocks above from
  22. -- the floor.  Again, it seems to be the case.
  23. --
  24.  
  25.  
  26. local WIDTH = 5
  27. local HEIGHT = 5
  28. local slot = 2
  29.  
  30. turtle.forceForward = function()
  31.     repeat until turtle.forward()
  32. end
  33.  
  34. turtle.forceForwardAndDig = function()
  35.     while not turtle.forward() do turtle.dig() end
  36. end
  37. turtle.forceUpAndDig = function()
  38.     while not turtle.up() do turtle.digUp() end
  39. end
  40. turtle.forceDownAndDig = function()
  41.     while not turtle.down() do turtle.digDown() end
  42. end
  43.  
  44. local isBloodTree = function(compareFunc)
  45.     local ret = false
  46.  
  47.     turtle.select(1)
  48.     ret = compareFunc()
  49.     turtle.select(slot)
  50.  
  51.     return ret
  52. end
  53.  
  54. local break_blood_tree = function()
  55.     if isBloodTree(turtle.compareUp) then
  56.         turtle.forceUpAndDig()
  57.  
  58.         -- Break the whole 3x3x1 space
  59.         turtle.forceForwardAndDig()
  60.         turtle.turnLeft()
  61.         turtle.forceForwardAndDig()
  62.  
  63.         for i = 1, 3 do
  64.             turtle.turnLeft()
  65.             turtle.forceForwardAndDig()
  66.             turtle.forceForwardAndDig()
  67.         end
  68.  
  69.         turtle.turnLeft()
  70.         turtle.forceForwardAndDig()
  71.         turtle.turnLeft()
  72.         turtle.forceForwardAndDig()
  73.  
  74.         -- Make the turtle facing at the same direction as the begining
  75.         turtle.turnLeft()
  76.         turtle.turnLeft()
  77.  
  78.         break_blood_tree()
  79.  
  80.         turtle.forceDownAndDig()
  81.     end
  82. end
  83.  
  84. turtle.plant = function()
  85.     if turtle.getItemCount() == 0 then
  86.         if slot > 16 then
  87.             return
  88.         end
  89.  
  90.         slot = slot + 1
  91.         turtle.select(slot)
  92.     end
  93.  
  94.     -- In some rare case a block may prevent the turtle
  95.     -- planting, remove it.  Don't insist on failure.
  96.     if not turtle.compare() then
  97.         turtle.dig()
  98.     end
  99.  
  100.     turtle.placeDown()
  101. end
  102.  
  103. turtle.plantAndForward = function()
  104.     turtle.plant()
  105.     turtle.forceForward()
  106.  
  107.     if isBloodTree(turtle.compare) then
  108.         turtle.forceForwardAndDig()
  109.         break_blood_tree()
  110.     else
  111.         turtle.forceForward()
  112.     end
  113. end
  114.  
  115. turtle.select(slot)
  116. while slot <= 16 do
  117.     for i = 1, WIDTH do
  118.         for j = 1, HEIGHT - 1 do
  119.             turtle.plantAndForward()
  120.         end
  121.  
  122.         -- Last col have a special case for the finish since the
  123.         -- turtle must move back to the starting position at the
  124.         -- end of the col
  125.         if i == WIDTH then
  126.             turtle.plant()
  127.         else
  128.             if i % 2 == 0 then
  129.                 turtle.turnLeft()
  130.                 turtle.plantAndForward()
  131.                 turtle.turnLeft()
  132.             else
  133.                 turtle.turnRight()
  134.                 turtle.plantAndForward()
  135.                 turtle.turnRight()
  136.             end
  137.         end
  138.     end
  139.  
  140.     -- Move back to the starting position
  141.     turtle.forceForward()
  142.  
  143.     if WIDTH % 2 == 0 then
  144.         turtle.turnRight()
  145.         for i = 1, WIDTH - 1 do
  146.             turtle.forceForward()
  147.             turtle.forceForward()
  148.         end
  149.         turtle.turnRight()
  150.         turtle.forceForward()
  151.     else
  152.         turtle.turnLeft()
  153.         for i = 1, WIDTH - 1 do
  154.             turtle.forceForward()
  155.             turtle.forceForward()
  156.         end
  157.  
  158.         turtle.forceForward()
  159.         turtle.turnLeft()
  160.         turtle.forceForward()
  161.  
  162.         for i = 1, HEIGHT - 1 do
  163.             turtle.forceForward()
  164.             turtle.forceForward()
  165.         end
  166.  
  167.         turtle.turnLeft()
  168.         turtle.forceForward()
  169.         turtle.turnLeft()
  170.     end
  171. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement