SHARE
TWEET

miner

a guest Mar 22nd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tunnel_length = 0
  2. local cluster_width = 0
  3. local cluster_height = 0
  4.  
  5. local done_width = 0
  6. local done_height = 0
  7.  
  8. local pos_x = 0
  9. local pos_y = 0
  10. local pos_z = 0
  11.  
  12. local facing_pos = {"front", "right", "back", "left"}
  13. local facing_nb = 1
  14. local facing = facing_pos[facing_nb]
  15.  
  16. local useless_ressources = {"minecraft:stone", "minecraft:cobblestone","minecraft:dirt", "chisel:limestone2", "chisel:marble2"}
  17.  
  18. function read_cluster_params()
  19.     write("Enter tunnel length : ")
  20.     tunnel_length = tonumber(read())
  21.     write("Enter cluster width : ")
  22.     cluster_width = tonumber(read())
  23.     write("Enter cluster height : ")
  24.     cluster_height = tonumber(read())
  25. end
  26.  
  27. function turnleft()
  28.     turtle.turnLeft()
  29.     facing_nb = ((facing_nb + 3) % 4)
  30.     if (facing_nb == 0) then
  31.         facing_nb = 4
  32.     end
  33.     facing = facing_pos[facing_nb]
  34. end
  35.  
  36. function turnright()
  37.     turtle.turnRight()
  38.     facing_nb = ((facing_nb + 1) % 4)
  39.     if (facing_nb == 0) then
  40.         facing_nb = 4
  41.     end
  42.     facing = facing_pos[facing_nb]
  43. end
  44.  
  45. function turn_180_r()
  46.     turtle.turnRight()
  47.     turtle.turnRight()
  48.     facing_nb = ((facing_nb + 2) % 4)
  49.     if (facing_nb == 0) then
  50.         facing_nb = 4
  51.     end
  52.     facing = facing_pos[facing_nb]
  53. end
  54.  
  55. function turn_180_l()
  56.     turtle.turnLeft()
  57.     turtle.turnLeft()
  58.     facing_nb = ((facing_nb + 2) % 4)
  59.     if (facing_nb == 0) then
  60.         facing_nb = 4
  61.     end
  62.     facing = facing_pos[facing_nb]
  63. end
  64.  
  65. function is_useless(n)
  66.     for i=1, 5 do
  67.         if (n == useless_ressources[i]) then
  68.          return true
  69.         end
  70.     end
  71.     return false
  72. end
  73.  
  74. function detect_up_down()
  75.     local success, data = turtle.inspectUp()
  76.     if success then
  77.         if (is_useless(data.name)) then
  78.  
  79.         else
  80.             turtle.digUp()
  81.         end
  82.     end
  83.     local s, d = turtle.inspectDown()
  84.     if s then
  85.         if (is_useless(d.name)) then
  86.  
  87.         else
  88.             turtle.digDown()
  89.         end
  90.     end
  91. end
  92.  
  93. function face_correct_side(toface)
  94.     if (facing_nb == toface) then
  95.         return true
  96.     end
  97.     turnleft()
  98.     if (facing_nb == toface) then
  99.         return true
  100.     end
  101.     turnleft()
  102.     if (facing_nb == toface) then
  103.         return true
  104.     end
  105.     turnleft()
  106.     if (facing_nb == toface) then
  107.         return true
  108.     end
  109. end
  110.  
  111.  
  112. function drop_to_chest()
  113.     local selected_slot = 1
  114.     while (selected_slot <= 16) do
  115.         turtle.select(selected_slot)
  116.         turtle.drop()
  117.         selected_slot = selected_slot + 1
  118.     end
  119.     turtle.select(1)
  120. end
  121.  
  122. function clear_inventory()
  123.     local selected_slot = 1
  124.     while (selected_slot <= 16) do
  125.         turtle.select(selected_slot)
  126.         local tmp = turtle.getItemDetail()
  127.         if (tmp ~= nil) then
  128.             if (is_useless(tmp.name)) then
  129.                 turtle.drop()
  130.             end
  131.         end
  132.         selected_slot = selected_slot + 1
  133.     end
  134.     turtle.select(1)
  135. end
  136.  
  137. function is_inv_full()
  138.     turtle.select(16)
  139.     local tmp = turtle.getItemDetail()
  140.     turtle.select(1)
  141.     if (tmp == nil) then
  142.         return false
  143.     else
  144.         return true
  145.     end
  146. end
  147.  
  148. function mine_tunnel()
  149.     while (pos_z + 1 < tunnel_length) do
  150.         detect_up_down()
  151.         turtle.dig()
  152.         while (turtle.forward() == false) do
  153.             turtle.dig()
  154.         end
  155.         detect_up_down()
  156.         pos_z = pos_z + 1
  157.     end
  158. end
  159.  
  160. function mine_tunnel_invert()
  161.     while (pos_z > 0) do
  162.         detect_up_down()
  163.         turtle.dig()
  164.         while (turtle.forward() == false) do
  165.             turtle.dig()
  166.         end
  167.         detect_up_down()
  168.         pos_z = pos_z - 1
  169.     end
  170. end
  171.  
  172. function go_to_next_tunnel()
  173.     if (facing_nb == 1) then
  174.         turnright()
  175.         while (turtle.forward() == false) do
  176.             turtle.dig()
  177.         end
  178.         pos_x = pos_x + 1
  179.         turnright()
  180.     elseif (facing_nb == 3) then
  181.         turnleft()
  182.         while (turtle.forward() == false) do
  183.             turtle.dig()
  184.         end
  185.         pos_x = pos_x + 1
  186.         turnleft()
  187.     end
  188. end
  189.  
  190. function go_to_next_tunnel_invert()
  191.     if (facing_nb == 3) then
  192.         turnright()
  193.         while (turtle.forward() == false) do
  194.             turtle.dig()
  195.         end
  196.         pos_x = pos_x - 1
  197.         turnright()
  198.     elseif (facing_nb == 1) then
  199.         turnleft()
  200.         while (turtle.forward() == false) do
  201.             turtle.dig()
  202.         end
  203.         pos_x = pos_x - 1
  204.         turnleft()
  205.     end
  206. end
  207.  
  208. function handle_x_mining()
  209.     while (done_width == 0) do
  210.        
  211.         mine_tunnel()
  212.         go_to_next_tunnel()
  213.         mine_tunnel_invert()
  214.         clear_inventory()
  215.         if (pos_x + 1 < cluster_width) then
  216.             go_to_next_tunnel()
  217.         else
  218.             done_width = 1
  219.         end
  220.     end
  221. end
  222. function handle_x_mining_invert()
  223.     while (done_width == 0) do
  224.  
  225.         mine_tunnel()
  226.         go_to_next_tunnel_invert()
  227.         mine_tunnel_invert()
  228.  
  229.         if (pos_x > 0) then
  230.             go_to_next_tunnel_invert()
  231.         else
  232.             done_width = 1
  233.         end
  234.     end
  235. end
  236.  
  237. function move_down()
  238.     if (pos_z == 0) then
  239.         face_correct_side(1)
  240.     else
  241.         face_correct_side(3)
  242.     end
  243.     while (turtle.down() == false) do
  244.         turtle.digDown()
  245.     end
  246.     pos_y = pos_y + 1
  247.     while (turtle.down() == false) do
  248.         turtle.digDown()
  249.     end
  250.     pos_y = pos_y + 1
  251.     while (turtle.down() == false) do
  252.         turtle.digDown()
  253.     end
  254.     pos_y = pos_y + 1
  255. end
  256.  
  257. function deposit_inventory()
  258.     local lx = pos_x
  259.     local ly = pos_y
  260.  
  261.     print("Inventory is full")
  262.     print("Positon before x:"..lx.." y:"..ly)
  263.  
  264.     if (lx > 0) then
  265.         face_correct_side(4)
  266.         while (lx > 0) do
  267.             while (turtle.forward() == false) do
  268.                 turtle.dig()
  269.             end
  270.             lx = lx - 1
  271.         end
  272.     end
  273.     if (ly > 0) then
  274.         while (ly > 0) do
  275.             while (turtle.up() == false) do
  276.                 turtle.digUp()
  277.             end
  278.             ly = ly - 1
  279.         end
  280.     end
  281.     face_correct_side(3)
  282.     print("Should be in front of chest")
  283.     print("Positon x:"..lx.." y:"..ly)
  284.     drop_to_chest()
  285.  
  286.     while (ly ~= pos_y) do
  287.         while (turtle.down() == false) do
  288.             turtle.digDown()
  289.         end
  290.         ly = ly + 1
  291.     end
  292.  
  293.     if (lx ~= pos_x) then
  294.         face_correct_side(2)
  295.         while (lx ~= pos_x) do
  296.             while (turtle.forward() == false) do
  297.                 turtle.dig()
  298.             end
  299.             lx = lx + 1
  300.         end
  301.     end
  302.     print("Positon after x:"..lx.." y:"..ly)
  303. end
  304.  
  305. read_cluster_params()
  306. while (pos_y <= cluster_height) do
  307.     while (turtle.forward() == false) do
  308.         turtle.dig()
  309.     end
  310.     handle_x_mining()
  311.     done_width = 0
  312.     while (turtle.forward() == false) do
  313.         turtle.dig()
  314.     end
  315.     --right side
  316.     if (is_inv_full()) then
  317.         deposit_inventory()
  318.     end
  319.     move_down()
  320.  
  321.     while (turtle.forward() == false) do
  322.         turtle.dig()
  323.     end
  324.     handle_x_mining_invert()
  325.     done_width = 0
  326.     while (turtle.forward() == false) do
  327.         turtle.dig()
  328.     end
  329.     if (pos_y <= cluster_height) then
  330.         --left side
  331.         if (is_inv_full()) then
  332.             deposit_inventory()
  333.         end
  334.         move_down()
  335.     end
  336. end
  337.  
  338. --go back to chest
  339. if (pos_x > 0) then
  340.     face_correct_side(4)
  341.     while (pos_x > 0) do
  342.         while (turtle.forward() == false) do
  343.             turtle.dig()
  344.         end
  345.         pos_x = pos_x - 1
  346.     end
  347. end
  348. if (pos_y > 0) then
  349.     while (pos_y > 0) do
  350.         while (turtle.up() == false) do
  351.             turtle.digUp()
  352.         end
  353.         pos_y = pos_y - 1
  354.     end
  355. end
  356. face_correct_side(3)
  357. print("Should be in front of chest")
  358. print("Positon z:"..pos_z.." x:"..pos_x.." y:"..pos_y)
  359. drop_to_chest()
  360. print("Have fun with your new ores!")
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