SHARE
TWEET

ValuableFinderv2

Proaxel May 25th, 2020 (edited) 2,744 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. depth = 0
  2. useChests = true
  3. descending = true
  4. ascending = true
  5.  
  6. function fuel()
  7.     if turtle.getFuelLevel() <= 10 then
  8.         local fuelTable = {"minecraft:coal", "minecraft:lava_bucket"}
  9.         for i = 1, 16, 1 do
  10.             local itemData = turtle.getItemDetail(i)
  11.             for k, v in ipairs(fuelTable) do
  12.                 if itemData.name == v then
  13.                     turtle.select(i)
  14.                     turtle.refuel()
  15.                     turtle.select(1)
  16.                 end
  17.             end
  18.         end
  19.     end
  20. end
  21.  
  22. function isValuable()
  23.     local junkTable = {"minecraft:stone", "minecraft:dirt", "minecraft:gravel", "minecraft:sand", "minecraft:torch"}
  24.     local valuable = true
  25.    
  26.     local isBlock, blockData = turtle.inspect()
  27.         if isBlock == true then
  28.             --print("There's something here. Block data:")
  29.             --print(blockData.name)
  30.             --print(blockData.metadata)
  31.             for k, v in ipairs(junkTable) do
  32.                 if blockData.name == v then
  33.                     print("This is junk.")
  34.                     valuable = false
  35.                     break
  36.                 end
  37.             end
  38.         else
  39.             --print("There isn't anything here.")
  40.             valuable = false
  41.         end
  42.     if valuable then
  43.         --print("There's something valuable here!")
  44.         return true
  45.        
  46.     else
  47.         --print("Nothing interesting here. Moving on")
  48.         return false
  49.     end
  50. end
  51.  
  52. function checkSides()
  53.     for i = 0, 3, 1 do
  54.         if isValuable() then
  55.             turtle.dig()
  56.         end
  57.         turtle.turnRight()
  58.     end
  59. end
  60.  
  61. function isBottomEmpty()
  62.     local isBlock, blockData = turtle.inspect()
  63.     if isBlock then
  64.         return true
  65.     else
  66.         return false
  67.     end
  68. end
  69.  
  70. function isBottomBedrock()
  71.     local isBlock, blockData = turtle.inspectDown()
  72.     if isBlock then
  73.         if blockData.name == "minecraft:bedrock" then
  74.             print("We've hit bedrock!")
  75.             return true
  76.         else
  77.             return false
  78.         end
  79.     else
  80.         return false
  81.     end
  82. end
  83.  
  84. function knightMove()
  85.     if turtle.detect() then
  86.         turtle.dig()
  87.     end
  88.     turtle.forward()
  89.     if turtle.detect() then
  90.         turtle.dig()
  91.     end
  92.     turtle.forward()
  93.    
  94.     turtle.turnRight()
  95.    
  96.     if turtle.detect() then
  97.         turtle.dig()
  98.     end
  99.     turtle.forward()
  100. end
  101.  
  102. function findChestInInventory()
  103.     local chestSlot = 0
  104.     for i = 1, 16, 1 do
  105.         local data = turtle.getItemDetail(i)
  106.         if data then
  107.             if data.name == "minecraft:chest" then
  108.                 chestSlot = i
  109.                 print("Chest found in slot: " , chestSlot)
  110.                 break
  111.             end
  112.         end
  113.     end
  114.     return chestSlot
  115. end
  116.  
  117. function isChestInInventory()
  118.     local foundChest = false
  119.     for i = 1, 16, 1 do
  120.         local data = turtle.getItemDetail(i)
  121.         if data then
  122.             if data.name == "minecraft:chest" then
  123.                 foundChest = true
  124.                 break
  125.             end
  126.         end
  127.     end
  128.     return foundChest
  129. end
  130.  
  131. function returnToSurface()
  132.     print("Let's go back up...")
  133.  
  134.     while depth ~= 0 do
  135.         fuel()
  136.         if turtle.up() then
  137.             depth = depth - 1
  138.         else
  139.             print("Obstruction detected...")
  140.             turtle.digUp()
  141.         end
  142.     end
  143. end
  144.  
  145. print("Checking for chests")
  146. if not isChestInInventory() then
  147.     print("No chests found! Continue anyway?")
  148.     print("Y for yes, anything else for no")
  149.    
  150.     local decision = io.read()
  151.     if decision ~= "y" then
  152.         os.exit()
  153.     else
  154.         useChests = false
  155.     end
  156. end
  157.  
  158. print("Let's go!")
  159.  
  160.  
  161. while descending do
  162.     fuel()
  163.     checkSides()
  164.    
  165.     if isBottomBedrock() then
  166.         descending = false
  167.         break
  168.     end
  169.    
  170.     turtle.digDown()
  171.     turtle.down()
  172.     depth = depth + 1
  173. end
  174.  
  175. knightMove()
  176.  
  177. print("Let's go back up...")
  178.  
  179. while ascending do
  180.     fuel()
  181.     checkSides()
  182.    
  183.     if depth <= 0 then
  184.         ascending = false
  185.         break
  186.     end
  187.    
  188.     turtle.digUp()
  189.     if turtle.up() then
  190.         depth = depth - 1
  191.     else
  192.         print("Obstruction detected...")
  193.         turtle.digUp()
  194.     end
  195. end
  196.  
  197. print("Chest dumping")
  198. turtle.select(findChestInInventory())
  199. turtle.placeDown()
  200. for a = 1, 16 do
  201.     turtle.select(a)
  202.     local data = turtle.getItemDetail()
  203.     if data.name ~= "minecraft:chest" then
  204.         turtle.dropDown()
  205.     end
  206. end
  207. turtle.select(1)
  208.  
  209. print("Done!")
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