Advertisement
BassBoostedDuck

tree mining script updated 1.18.2

Apr 9th, 2022 (edited)
652
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.27 KB | None | 0 0
  1. -- TREE MINING SYSTEM.
  2.   tree = 0
  3.   branch = 0
  4.   leaf = 0
  5.   count = 0
  6.   amount = 0
  7.   -- add any blocks name that you want to be kept (this is automaticaly all the ore's that are of any value to the player.)
  8.   keeparray = {"minecraft:coal_block","minecraft:amethyst_block","minecraft:raw_copper_block","minecraft:raw_goldblock","minecraft:raw_iron_block","minecraft:coal","minecraft:raw_iron","minecraft:raw_copper","minecraft:raw_gold","minecraft:redstone","minecraft:emerald","minecraft:lapis_lazuli","minecraft:diamond"}
  9.   --count is how many blocks it has mined.
  10.   print("how long will the main tunnel be?")
  11.   local tree = read()
  12.   tree = (tonumber(tree))
  13.   print("how long will the side tunnel's be?")
  14.   local branch = read()
  15.   branch =(tonumber(branch))
  16.   print("ready to start? y/n?")
  17.   local reply = read()
  18.   runs = 0
  19.   -- this section of code allows for item checking if the item is not in the list then it gets thrown out but the turtle
  20.   keeparray = {"minecraft:coal_block","minecraft:amethyst_block","minecraft:raw_copper_block","minecraft:raw_goldblock","minecraft:raw_iron_block","minecraft:coal","minecraft:raw_iron","minecraft:raw_copper","minecraft:raw_gold","minecraft:redstone","minecraft:emerald","minecraft:lapis_lazuli","minecraft:diamond"}
  21. i = 0
  22. z = 1
  23. local function contains(keeparray, val)
  24.     for i=1,#keeparray do
  25.         if keeparray[i] == val then
  26.         print("true")
  27.             return true
  28.         end
  29.     end
  30.     print("false")
  31.     print(val)
  32.     return false
  33. end
  34. checktimes = 0
  35. function empty()
  36.     z =1
  37.     listleng = #keeparray
  38.     while z ~= 17 do
  39.         c = 0
  40.         checkthrow = 1
  41.         local data = turtle.getItemDetail(z)
  42.     if data then
  43.         item_name = data.name
  44.     end
  45.         if contains(keeparray,item_name) then
  46.             checkthrow = 0
  47.         item_name = nil
  48.         end
  49.         if checkthrow == 1
  50.         then
  51.             throw = turtle.getItemCount(z)
  52.             turtle.select(z)
  53.             turtle.drop(throw)
  54.             turtle.select(1)
  55.         end
  56.         z = z + 1
  57.     end
  58. end
  59. function check()
  60.     print(checktimes)
  61.     if checktimes == 100 then
  62.         checktimes = checktimes - 100
  63.         empty()
  64.     end
  65.     checktimes = checktimes + 1
  66. end
  67.  
  68.  
  69.   function fw()
  70.     if turtle.forward() then
  71.         check()
  72.     else
  73.       turtle.dig()  
  74.       runs = runs + 1
  75.       print("hit wall ")
  76.       print(runs)
  77.       print("amount of times")
  78.       rerun()
  79.     end
  80.   end
  81.   --
  82.   function rerun()
  83.     fw()
  84.   end
  85.   --
  86.   --moves turtle back.
  87.   function back1()
  88.     while amount > 0 do
  89.       turtle.back()
  90.       amount = amount - 1
  91.     end
  92.   end
  93.   --
  94.  
  95.           -- add the check for the backwards movement of the robot or it will get stuck on in the water lava situation.
  96.        
  97.        
  98.        
  99.  
  100.   -- makes the main tunnel as long as is needed.
  101.   function t()
  102.     while amount < tree do
  103.       turtle.dig()
  104.       fw()
  105.       turtle.digDown()
  106.       turtle.turnLeft()
  107.       turtle.dig()
  108.       fw()
  109.       turtle.digDown()
  110.       turtle.turnRight()
  111.       turtle.turnRight()
  112.       fw()
  113.       turtle.turnLeft()
  114.       amount = amount + 1
  115.     end
  116.     back1()
  117.   end
  118.   --
  119.   function back4()
  120.     while len > 0 do
  121.       turtle.back()
  122.       len = len - 1
  123.     end
  124.   end
  125.   --
  126.   function back3()
  127.     while len > 0 do
  128.       turtle.back()
  129.       len = len - 1
  130.     end
  131.     branch2()
  132.   end
  133.   --
  134.  function branch2()
  135.    turtle.turnLeft()
  136.    turtle.turnLeft()
  137.    turtle.forward()
  138.   while branch > len do
  139.     len = len + 3
  140.     turtle.dig()
  141.     fw()
  142.     turtle.digDown()
  143.     turtle.dig()
  144.     fw()
  145.     turtle.digDown()
  146.     turtle.dig()
  147.     fw()
  148.     turtle.digDown()
  149.     turtle.turnRight()
  150.     leaf()
  151.     turtle.turnLeft()
  152.     turtle.turnLeft()
  153.     leaf()
  154.     turtle.turnRight()
  155.   end
  156.   back4()
  157.   turtle.back()
  158.   turtle.turnRight()
  159. end
  160. --
  161. len = 0
  162. function branch1()
  163.   while branch > len do
  164.     len = len + 3
  165.     turtle.dig()
  166.     fw()
  167.     turtle.digDown()
  168.     turtle.dig()
  169.     fw()
  170.     turtle.digDown()
  171.     turtle.dig()
  172.     fw()
  173.     turtle.digDown()
  174.     turtle.turnRight()
  175.     leaf()
  176.     turtle.turnLeft()
  177.     turtle.turnLeft()
  178.     leaf()
  179.     turtle.turnRight()
  180.   end
  181.   back3()
  182. end
  183. --
  184. le = 0
  185. ru = 0
  186.   -- makes the branches and called for the leaves to be made when needed.
  187.   function b()
  188.       leng = tree / 12
  189.       print(leng)
  190.       turtle.forward()
  191.       turtle.turnRight()
  192.       branch1()
  193.       while le < leng do
  194.         le = le + 1
  195.         ru = 0
  196.         while ru <= 12 do
  197.           turtle.forward()
  198.           ru = ru + 1
  199.         end
  200.         turtle.turnRight()
  201.         branch1()
  202.       end
  203.       while le > 0 do
  204.         ru = 12
  205.         while ru > 0 do
  206.           ru = ru -1
  207.           turtle.back()
  208.         le = le - 1
  209.         end
  210.       end
  211.   end
  212.   --
  213.   function back2()
  214.     while length > 0 do
  215.       turtle.back()
  216.       length = length - 1
  217.     end
  218.   end
  219.   --
  220.   length = 0
  221.   -- makes the smaller branches off the second main branch.
  222.   function leaf()
  223.     while length ~= 6 do
  224.       turtle.dig()
  225.       fw()
  226.       length = length + 1
  227.     end
  228.     back2()
  229.   end
  230.   --
  231.   function s()
  232.     print("working")
  233.     t()
  234.     b()
  235.   end
  236.   --
  237. function exit()
  238. print("goodbye")
  239. end
  240. --
  241.   --Must be at the bottom.
  242.   if reply == "y" then
  243.     s()
  244.   else
  245.     exit()
  246.   end
  247.   --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement