SHARE
TWEET

ValuableFinderv2

Proaxel May 28th, 2020 1,740 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. depth = 0
  2. descending = true
  3. ascending = true
  4. chestSlot = 1
  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()
  86.         turtle.dig()
  87.     end
  88.     turtle.forward()
  89.     if turtle.detect()
  90.         turtle.dig()
  91.     end
  92.     turtle.forward()
  93.    
  94.     turtle.turnRight()
  95.    
  96.     if turtle.detect()
  97.         turtle.dig()
  98.     end
  99.     turtle.forward()
  100. end
  101.  
  102. function chestInInventory()
  103.     local foundChest = false
  104.     for i = 1, 16, 1 do
  105.         local data = getItemDetail(i)
  106.         if data.name == "minecraft:chest" then
  107.             foundChest = true
  108.         end
  109.     end
  110.    
  111.     if foundChest then
  112.         return true
  113.     else
  114.         return false
  115.     end
  116. end
  117.  
  118. function returnToSurface()
  119.     print("Let's go back up...")
  120.  
  121.     while depth ~= 0 do
  122.         fuel()
  123.         if turtle.up() then
  124.             depth = depth - 1
  125.         else
  126.             print("Obstruction detected...")
  127.             turtle.digUp()
  128.         end
  129.     end
  130. end
  131.  
  132. print("Checking for chests")
  133. if not chestInInventory then
  134.     print("No chests found! Continue anyway?")
  135.     print("Y for yes, anything else for no")
  136.    
  137.     local decision = io.read()
  138.     if decision ~= "y" then
  139.         os.exit()
  140.     end
  141. end
  142.  
  143. print("Let's go!")
  144.  
  145.  
  146. while descending do
  147.     fuel()
  148.     checkSides()
  149.    
  150.     if isBottomBedrock() then
  151.         descending = false
  152.         break
  153.     end
  154.    
  155.     turtle.digDown()
  156.     turtle.down()
  157.     depth = depth + 1
  158. end
  159.  
  160. knightMove()
  161.  
  162. print("Let's go back up...")
  163.  
  164. while ascending do
  165.     fuel()
  166.     checkSides()
  167.    
  168.     if (depth = 0)
  169.         ascending = false
  170.         break
  171.     end
  172.    
  173.     turtle.digUp()
  174.     if turtle.up() then
  175.         depth = depth - 1
  176.     else
  177.         print("Obstruction detected...")
  178.         turtle.digUp()
  179.     end
  180.     depth = depth - 1
  181. end
  182.  
  183. print("Chest dumping")
  184. turtle.select(16)
  185. turtle.placeDown()
  186. for a = 1, 14 do
  187.     turtle.select(a)
  188.     turtle.dropDown()
  189. end
  190. if turtle.getItemCount(16) < 0 then
  191.     print("Out of chests!! Stopping")
  192.     break
  193. end
  194. turtle.select(1)
  195.  
  196. 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