SHARE
TWEET

Untitled

xmann110 Aug 11th, 2019 (edited) 17 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function refuel()
  2.     if turtle.getFuelLevel() < 15 then
  3.         print("Fuel level is ", turtle.getFuelLevel(), "refueling...")
  4.         turtle.select(1)
  5.         turtle.refuel(1)
  6.     end
  7. end
  8.  
  9. function forceForward()
  10.     while not turtle.forward() do
  11.         refuel()
  12.         a, b = turtle.inspect()
  13.         if a then
  14.             if a.name == "minecraft:leaves" then
  15.                 turtle.dig()
  16.             end
  17.         end
  18.     end
  19. end
  20.  
  21. function interactTree(right)
  22.     print("Interacting with tree planting spot...")
  23.     a, b = turtle.inspect()
  24.     if a then
  25.         if b.name == "minecraft:sapling" then
  26.             print("Tree is planted but not mature, ignoring")
  27.         elseif b.name == "minecraft:log" then
  28.             mineTree(right)
  29.             plantSaplings(right)
  30.         else
  31.             print("WARNING: Unknown block found: ", b.name)
  32.             turtle.dig()
  33.             plantSaplings(right)
  34.         end
  35.     else
  36.         plantSaplings(right)
  37.     end
  38. end
  39.  
  40. function plantSaplings(right)
  41.     print("Planting saplings...")
  42.     refuel()
  43.     findItem("minecraft:sapling")
  44.     if right then
  45.         forceForward()
  46.         forceForward()
  47.         turtle.turnLeft()
  48.         turtle.place()
  49.         turtle.turnRight()
  50.         turtle.back()
  51.         turtle.place()
  52.         turtle.turnLeft()
  53.         turtle.place()
  54.         turtle.turnRight()
  55.         turtle.back()
  56.         turtle.place()
  57.     else
  58.         forceForward()
  59.         forceForward()
  60.         turtle.turnRight()
  61.         turtle.place()
  62.         turtle.turnLeft()
  63.         turtle.back()
  64.         turtle.place()
  65.         turtle.turnRight()
  66.         turtle.place()
  67.         turtle.turnLeft()
  68.         turtle.back()
  69.         turtle.place()
  70.     end
  71. end
  72.  
  73. function findItem(item)
  74.     for i=1, 16 do
  75.         turtle.select(i)
  76.         if turtle.getItemCount() > 1 then
  77.             local data = turtle.getItemDetail()
  78.             if data.name == item then
  79.                 break
  80.             end
  81.         end
  82.     end
  83. end
  84.  
  85. function mineTree(right)
  86.     print("Chopping down tree")
  87.     refuel()
  88.     turtle.dig()
  89.     forceForward()
  90.     local blocksLeft = 0
  91.     while true do
  92.         refuel()
  93.         turtle.dig()
  94.         turtle.digUp()
  95.         if turtle.up() then
  96.             blocksLeft = blocksLeft + 1
  97.         end
  98.         a, b = turtle.inspectUp()
  99.         if a then
  100.             if not b.name == "minecraft:log" then
  101.                 break
  102.             end
  103.         else
  104.             break
  105.         end
  106.     end
  107.     turtle.digUp()
  108.     turtle.up()
  109.     turtle.dig()
  110.     print("Got to top of tree, tree height: ", blocksLeft)
  111.     if right then
  112.         turtle.turnLeft()
  113.         turtle.dig()
  114.         forceForward()
  115.         turtle.turnRight()
  116.     else
  117.         turtle.turnRight()
  118.         turtle.dig()
  119.         forceForward()
  120.         turtle.turnLeft()
  121.     end
  122.  
  123.     while blocksLeft + 1 > 0 do
  124.         refuel()
  125.         while not turtle.down() do
  126.             turtle.digDown()
  127.         end
  128.         turtle.dig()
  129.         blocksLeft = blocksLeft - 1
  130.     end
  131.  
  132.     if right then
  133.         turtle.turnRight()
  134.         forceForward()
  135.         turtle.turnLeft()
  136.         turtle.back()
  137.     else
  138.         turtle.turnLeft()
  139.         forceForward()
  140.         turtle.turnRight()
  141.         turtle.back()
  142.     end
  143. end
  144.  
  145. function startup()
  146.     print("Getting out of starting position...")
  147.     refuel()
  148.     forceForward()
  149.     forceForward()
  150.     forceForward()
  151. end
  152.  
  153. function harvest()
  154.     -- Go forward one lane
  155.     for i=1, 7 do
  156.         refuel()
  157.         turtle.turnLeft()
  158.         interactTree(false)
  159.         turtle.turnRight()
  160.         turtle.turnRight()
  161.         interactTree(true)
  162.         turtle.turnLeft()
  163.         forceForward()
  164.         forceForward()
  165.         forceForward()
  166.     end
  167.  
  168.     -- Switch to right next lane
  169.  
  170.     turtle.turnRight()
  171.     for i=1, 6 do
  172.         refuel()
  173.         forceForward()
  174.     end
  175.     turtle.turnRight()
  176.  
  177.     forceForward()
  178.     forceForward()
  179.  
  180.     -- Go forward one lane
  181.  
  182.     for i=1, 7 do
  183.         refuel()
  184.         turtle.turnLeft()
  185.         interactTree()
  186.         turtle.turnRight()
  187.         turtle.turnRight()
  188.         interactTree()
  189.         turtle.turnLeft()
  190.         forceForward()
  191.         forceForward()
  192.         forceForward()
  193.     end
  194.  
  195.     -- Switch to left next lane
  196.  
  197.     turtle.turnLeft()
  198.     for i=1, 6 do
  199.         refuel()
  200.         forceForward()
  201.     end
  202.     turtle.turnLeft()
  203.  
  204.     forceForward()
  205.     forceForward()
  206.  
  207.     -- Go forward one lane
  208.  
  209.     for i=1, 7 do
  210.         refuel()
  211.         turtle.turnLeft()
  212.         interactTree()
  213.         turtle.turnRight()
  214.         turtle.turnRight()
  215.         interactTree()
  216.         turtle.turnLeft()
  217.         forceForward()
  218.         forceForward()
  219.         forceForward()
  220.     end
  221.  
  222.     -- Switch to right next lane
  223.  
  224.     turtle.turnRight()
  225.     forceForward()
  226.     forceForward()
  227.     forceForward()
  228.     turtle.turnRight()
  229.     forceForward()
  230.     forceForward()
  231.  
  232.     -- Go forward one lane
  233.  
  234.     for i=1, 7 do
  235.         refuel()
  236.         turtle.turnLeft()
  237.         interactTree()
  238.         turtle.turnRight()
  239.         forceForward()
  240.         forceForward()
  241.         forceForward()
  242.     end
  243.     turtle.turnRight()
  244.     for i=1, 15 do
  245.         refuel()
  246.         forceForward()
  247.     end
  248.     turtle.turnLeft()
  249.     forceForward()
  250.  
  251.     for i=2, 16 do
  252.         turtle.select(i)
  253.         turtle.drop()
  254.     end
  255. end
  256.  
  257. startup()
  258. harvest()
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