Advertisement
1vannn

smartMiner2

Nov 26th, 2022 (edited)
943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.73 KB | None | 0 0
  1. good_items = {"diamond","gold","lapis","iron","emerald","silver","lead","bauxite","raw","uranium","obsidian","coal","redstone","nickel","torch","copper","tin","ore"}
  2. building_blocks = {"stone","granite","tuff","wood","log","andesite","cobble"}
  3.  
  4. print("Checking for updated script..")
  5. paste_id = "http://pastebin.com/raw.php?i=ranQP0a1"
  6. pasteContent = http.get(paste_id)
  7. Paste = pasteContent.readAll()
  8. pasteContent.close()
  9.  
  10. file = fs.open("smartMiner","r")
  11. contents = file.readAll()
  12. file.close()
  13.  
  14. mining_depth = 0
  15.  
  16. if (Paste ~= contents) then
  17.         print("Updating program...")
  18.         shell.run("delete","smartMiner")
  19.         wFile = fs.open("smartMiner","w")
  20.         wFile.write(Paste)
  21.         wFile.close()
  22.         sleep(2)
  23.         os.reboot()
  24. end
  25.  
  26. function ntfy_message(ore)
  27.     local response = http.post("https://ntfy.sh/ishires_smartMiner",os.getComputerID() .. " - Just mined a "..ore)
  28. end
  29.  
  30. function string_contains(string,good_items)
  31.     for key,value in pairs(good_items) do
  32.         if string.match(string, value) then
  33.             return "True"
  34.         end
  35.     end
  36. end
  37.  
  38. function check_block()
  39.     local block, block_data = turtle.inspect()
  40.     if block then -- Block is detected by the Turtle
  41.         local block_name = block_data["name"]
  42.         if string_contains(block_name,good_items) then
  43.             print(block_name.." in list of items to mine!")
  44.             turtle.dig()
  45.             ntfy_message(block_name)
  46.         end
  47.     end
  48. end
  49.  
  50. function turtle_UpInspect()
  51.     local block, block_data = turtle.inspectUp()
  52.     if block then -- Block is detected by the Turtle
  53.         local block_name = block_data["name"]
  54.         if (string.find(block_name,"obsidian")) then
  55.             return true
  56.         else
  57.             return false
  58.         end
  59.     else
  60.         return true
  61.     end
  62. end
  63.  
  64. function turtle_asend()
  65.     turtle.digUp()
  66.     turtle.up()
  67. end
  68.  
  69. function bedrock_check()
  70.     local block, block_data = turtle.inspectDown()
  71.     if block then -- Block is detected by the Turtle
  72.         local block_name = block_data["name"]
  73.         if (string.find(block_name,"bedrock")) then
  74.             return true
  75.         else
  76.             return false
  77.         end
  78.     else
  79.         return false
  80.     end
  81. end
  82.  
  83. args = {...}
  84. distance = args[1]
  85.  
  86. if (distance % 4 == 0) then
  87.    
  88.     depth_hole = 0
  89.  
  90.     holes = distance / 4
  91.     for i=1,holes do
  92.         mining = true
  93.        
  94.         -- check above your head for blocks
  95.         block_up = turtle.inspectUp()
  96.         if (block_up == "nil") then
  97.             turtle.digDown()
  98.             print("Selecting a building block")
  99.             for i = 1, 16 do
  100.                 turtle.select(i)
  101.                 local block = turtle.getItemDetail()
  102.                 if (block) then
  103.                     local block_name = block["name"]
  104.                     if string_contains(block_name,building_blocks) then
  105.                         turtle.placeUp()
  106.                         break
  107.                     end
  108.                 end
  109.             end
  110.            
  111.         end
  112.  
  113.         while mining do
  114.             fuel_level = turtle.getFuelLevel()    
  115.             if (mining_depth == 0) then
  116.                 if (fuel_level <= 300) then
  117.                     print("Not enough fuel!")
  118.                 end
  119.             end
  120.  
  121.             if bedrock_check() then -- We've hit bedrock, go back up...
  122.                 while true do
  123.                     if not turtle_UpInspect() then
  124.                         mining = false
  125.                         break
  126.                     else
  127.                         turtle_asend()
  128.                     end
  129.                 end
  130.             else
  131.                 for i=1,4 do -- checks all 4 sides of the Turtle
  132.                     check_block()
  133.                     turtle.turnRight()
  134.                 end
  135.                 turtle.digDown()
  136.                 turtle.down()
  137.                 depth_hole = depth_hole + 1
  138.             end
  139.         end
  140.    
  141.        
  142.         -- selecting a building block
  143.  
  144.         building_block_slot = 0
  145.         print("Selecting a building block")
  146.         for i = 1, 16 do
  147.             turtle.select(i)
  148.             local block = turtle.getItemDetail()
  149.             if (block) then
  150.                 local block_name = block["name"]
  151.                 if string_contains(block_name,building_blocks) then
  152.                     if building_block_slot == 0 then
  153.                         building_block_slot = i
  154.                         break
  155.                     end
  156.                 end
  157.             end
  158.         end
  159.         -- Inventory Check
  160.         print("Dumping unneeded inventory")
  161.         for i = 1, 16 do
  162.             if (i ~= building_block_slot) then
  163.                 turtle.select(i)
  164.                 local block = turtle.getItemDetail()
  165.                 if (block) then
  166.                     local block_name = block["name"]
  167.                     if not string_contains(block_name,good_items) then
  168.                         print("Dumping "..block_name)
  169.                         turtle.dropDown()
  170.                     end
  171.                 end
  172.             end
  173.         end
  174.  
  175.         -- Leave no trace
  176.         turtle.select(building_block_slot)
  177.         item_count = turtle.getItemCount()
  178.         item_drop_count = item_count - 1
  179.         turtle.dropDown(item_drop_count)
  180.         turtle.placeDown()
  181.  
  182.         -- Logic below moves to the next hole
  183.         turtle.dig()
  184.         turtle.forward()
  185.         turtle.dig()
  186.         turtle.forward()
  187.         turtle.dig()
  188.         turtle.forward()
  189.     end
  190.  
  191.     -- Coming Home Function
  192.     distance_home = holes + (holes * 2)
  193.     turtle.turnRight()
  194.     turtle.turnRight()
  195.     for i=1,distance_home do
  196.         turtle.dig()
  197.         turtle.forward()
  198.     end
  199.  
  200. else
  201.     print("Value not divisible by 4!")
  202. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement