Advertisement
1vannn

sandbox_driving

Nov 27th, 2022 (edited)
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.17 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. mining = "True"
  83. while mining == "True" do
  84.     fuel_level = turtle.getFuelLevel()
  85.     local depth_hole = 0
  86.     if (mining_depth == 0) then
  87.         if (fuel_level <= 300) then
  88.             print("Not enough fuel!")
  89.         end
  90.     end
  91.  
  92.     if (bedrock_check() == "True") then -- We've hit bedrock, go back up...
  93.         while true do
  94.             if (turtle_UpInspect() == "False") then
  95.                 mining = "False"
  96.                 break
  97.             else
  98.                 turtle_asend()
  99.             end
  100.         end
  101.     else
  102.         for i=1,4 do -- checks all 4 sides of the Turtle
  103.             check_block()
  104.             turtle.turnRight()
  105.         end
  106.         turtle.digDown()
  107.         turtle.down()
  108.         depth_hole = depth_hole + 1
  109.     end
  110.    
  111. end
  112.  
  113. if (mining_depth == 0) then
  114.     mining_depth = depth_hole
  115.     print("Mining Depth: "..mining_depth)
  116. end
  117.  
  118. building_block_slot = 0
  119. -- selecting a building block
  120. print("Selecting a building block")
  121. for i = 1, 16 do
  122.     turtle.select(i)
  123.     local block = turtle.getItemDetail()
  124.     if (block) then
  125.         local block_name = block["name"]
  126.         if string_contains(block_name,building_blocks) then
  127.             if building_block_slot == 0 then
  128.                 building_block_slot = i
  129.                 break
  130.             end
  131.         end
  132.     end
  133. end
  134. -- Inventory Check
  135. print("Dumping unneeded inventory")
  136. for i = 1, 16 do
  137.     if (i ~= building_block_slot) then
  138.         turtle.select(i)
  139.         local block = turtle.getItemDetail()
  140.         if (block) then
  141.             local block_name = block["name"]
  142.             if not string_contains(block_name,good_items) then
  143.                 print("Dumping "..block_name)
  144.                 turtle.dropDown()
  145.             end
  146.         end
  147.     end
  148. end
  149.  
  150. -- Leave no trace
  151. turtle.select(building_block_slot)
  152. item_count = turtle.getItemCount()
  153. item_drop_count = item_count - 1
  154. turtle.dropDown(item_drop_count)
  155. turtle.placeDown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement