SHARE
TWEET

ultitree

xmann110 Feb 14th, 2020 (edited) 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function refuel()
  2.     if turtle.getFuelLevel() < 20 then
  3.         turtle.select(1)
  4.         turtle.refuel(1)
  5.     end
  6. end
  7.  
  8. function restock()
  9.     go_to_restock()
  10.     take_items()
  11.     drop_off_items()
  12.     go_back_from_restock()
  13. end
  14.  
  15. function needs_restocking()
  16.     turtle.select(1)
  17.     if turtle.getItemCount() < 4 then
  18.         return true
  19.     end
  20.     turtle.select(2)
  21.     if turtle.getItemCount() < 4 then
  22.         return true
  23.     end
  24.     turtle.select(5)
  25.     if turtle.getItemCount() > 0 then
  26.         return true
  27.     end
  28.     return false
  29. end
  30.  
  31. function take_items()
  32.     turtle.turnLeft()
  33.  
  34.     turtle.select(1)
  35.     while turtle.getItemCount() < 4 do
  36.         turtle.suck(32 - turtle.getItemCount())
  37.     end
  38.  
  39.     turtle.select(2)
  40.     while turtle.getItemCount() < 8 do
  41.         turtle.suckDown(32 - turtle.getItemCount())
  42.     end
  43.  
  44.     turtle.turnRight()
  45. end
  46.  
  47. function drop_off_items()
  48.     for i=3, 16 do
  49.         turtle.select(i)
  50.         items = turtle.getItemDetail()
  51.         if items then
  52.             if items.name == "minecraft:log" then
  53.                 turtle.dropUp()
  54.             else
  55.                 if items.name == "minecraft:sapling" then
  56.                     turtle.dropDown()
  57.                 else
  58.                     turtle.dropUp()
  59.                     print("Unknown item picked up: " .. items.name)
  60.                 end
  61.             end
  62.         end
  63.     end
  64. end
  65.  
  66.  
  67. function go_to_restock()
  68.     refuel()
  69.     turtle.turnRight()
  70.     turtle.turnRight()
  71.     turtle.dig()
  72.     turtle.forward()
  73.     turtle.dig()
  74.     turtle.forward()
  75.     turtle.dig()
  76.     turtle.forward()
  77.     turtle.dig()
  78.     turtle.forward()
  79.     turtle.turnRight()
  80.     turtle.turnRight()
  81. end
  82.  
  83. function go_back_from_restock()
  84.     refuel()
  85.     turtle.dig()
  86.     turtle.forward()
  87.     turtle.dig()
  88.     turtle.forward()
  89.     turtle.dig()
  90.     turtle.forward()
  91.     turtle.dig()
  92.     turtle.forward()
  93.     turtle.dig()
  94. end
  95.  
  96. function harvest()
  97.     refuel()
  98.  
  99.     turtle.select(1)
  100.     turtle.dig()
  101.     turtle.forward()
  102.  
  103.     while true do
  104.         refuel()
  105.         turtle.dig()
  106.         turtle.digUp()
  107.         turtle.up()
  108.         a, b = turtle.inspectUp()
  109.         if not (a) or b.name == "minecraft:leaves" then
  110.             break
  111.         end
  112.     end
  113.  
  114.     for i=1, 2 do
  115.         refuel()
  116.         turtle.dig()
  117.         turtle.digUp()
  118.         turtle.up()
  119.     end
  120.     refuel()
  121.     turtle.turnRight()
  122.     turtle.dig()
  123.     turtle.forward()
  124.     turtle.turnLeft()
  125.  
  126.     while true do
  127.         refuel()
  128.         turtle.dig()
  129.         turtle.digDown()
  130.         turtle.down()
  131.         a, b = turtle.inspectDown()
  132.         if a and (b.name == "minecraft:dirt") or (b.name == "minecraft:grass") then
  133.             break
  134.         end
  135.     end
  136.  
  137.     turtle.dig()
  138.     turtle.turnLeft()
  139.     turtle.forward()
  140.     turtle.turnRight()
  141.     turtle.back()
  142. end
  143.  
  144. function plant()
  145.     planted = true
  146.     refuel()
  147.     turtle.select(1)
  148.     turtle.dig()
  149.     turtle.suck()
  150.     turtle.forward()
  151.     turtle.suck()
  152.     turtle.dig()
  153.     turtle.forward()
  154.     turtle.suck()
  155.     turtle.dig()
  156.     turtle.turnRight()
  157.     turtle.suck()
  158.     turtle.select(2)
  159.     turtle.place()
  160.     turtle.turnLeft()
  161.     turtle.back()
  162.     turtle.place()
  163.     turtle.turnRight()
  164.     turtle.suck()
  165.     turtle.place()
  166.     turtle.turnLeft()
  167.     turtle.back()
  168.     turtle.place()
  169. end
  170.  
  171. blockExists, block = turtle.inspect()
  172. if not (blockExists and (block.name == "minecraft:log" or block.name == "minecraft:sapling")) then
  173.     take_items()
  174.     go_back_from_restock()
  175. end
  176.  
  177. while true do
  178.     refuel()
  179.  
  180.     blockExists, block = turtle.inspect()
  181.     if blockExists then
  182.         if block.name == "minecraft:sapling" then
  183.             sleep(1)
  184.             turtle.select(1)
  185.             turtle.suckUp()
  186.         else
  187.             harvest()
  188.         end
  189.     else
  190.         plant()
  191.     end
  192.  
  193.     if needs_restocking() then
  194.         restock()
  195.     end
  196. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top