Advertisement
mathiaas

mine

Dec 14th, 2019 (edited)
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.71 KB | None | 0 0
  1. junk = {"granite","andesite","dirt", "stone","gravel","diorite", "grass_block", "flint", "cobblestone","bedrock", "lapis", "gold"}
  2.  
  3. depth = 0
  4. function valuable()
  5.   if (turtle.inspect()) then
  6.     local succ, data = turtle.inspect()
  7.     data.name = data.name:gsub("minecraft:", "")
  8.     if (string.match(data.name, "_ore")) then
  9.       data.name = data.name:gsub("_ore", "")
  10.       shell.run("data "..data.name.." 1")
  11.       turtle.dig()
  12.     end
  13.   end
  14. end
  15.  
  16. function checkWalls()
  17.   for i = 1, 4 do
  18.     valuable()
  19.     turtle.turnRight()
  20.   end
  21. end
  22.  
  23. function mine()
  24.   while (turtle.getFuelLevel() <= 130) do
  25.     turtle.turnRight()
  26.   end
  27.  
  28.   while turtle.down() do end
  29.   depth = 0
  30.   while (turtle.inspectDown() or turtle.down()) do
  31.     depth = depth + 1
  32.     local success, data = turtle.inspectDown()
  33.     if (data.name == "minecraft:bedrock") then
  34.       break
  35.     elseif (data.name == "minecraft:water" or data.name == "minecraft:flowing_water" or data.name == "minecraft:lava") then
  36.       turtle.down()
  37.     else
  38.       turtle.digDown()
  39.     end
  40.     checkWalls()
  41.   end
  42.  
  43.   organize()
  44.  
  45.   for i = 1, depth do
  46.     turtle.up()
  47.   end
  48.   turtle.select(1)
  49.   turtle.placeDown()
  50. end
  51.  
  52. function organize()
  53.   turtle.up()
  54.   depth = depth - 1
  55.   inventory = {}
  56.  
  57.   for i = 2,16 do
  58.     if (turtle.getItemDetail(i)) then
  59.       data = turtle.getItemDetail(i)
  60.       data["slot"] = i
  61.       table.insert(inventory,data)
  62.     end
  63.   end
  64.  
  65.   for key, valu in pairs(inventory) do
  66.     if (isJunk(inventory[key].name)) then
  67.       turtle.select(inventory[key].slot)
  68.       turtle.dropDown()
  69.     end
  70.   end
  71. end
  72.  
  73. function isJunk(input)
  74.     local _match
  75.     for key, valu in pairs(junk) do
  76.       if (input == "minecraft:"..junk[key]) then
  77.         _match = true
  78.       end
  79.     end
  80.     if (_match) then
  81.       return true
  82.     else
  83.       return false
  84.     end
  85. end
  86.  
  87. function main()
  88.   while true do
  89.     mine()
  90.     depo()
  91.     pathing()
  92.   end
  93. end
  94.  
  95. function depo()
  96.   if (turtle.getItemDetail(16)) then
  97.      if (turtle.getItemDetail(16).name == "minecraft:chest" and turtle.getItemDetail(11)) then
  98.         turtle.select(16)
  99.         turtle.placeUp()
  100.         for i = 2,15 do
  101.           if (turtle.getItemDetail(i)) then
  102.             turtle.select(i)
  103.             turtle.dropUp()
  104.           end
  105.         end
  106.      end
  107.   else
  108.     print("Out of chests")
  109.     while true do
  110.       turtle.turnRight()
  111.     end
  112.   end
  113. end
  114.  
  115. function pathing()
  116.   turtle.turnRight()
  117.   pathDetect()
  118.   turtle.forward()
  119.   pathDetect()
  120.   turtle.forward()
  121.   turtle.turnLeft()
  122.   pathDetect()
  123.   turtle.forward()
  124. end
  125.  
  126. function pathDetect()
  127.   while turtle.detect() do
  128.     if (turtle.up()) then
  129.     else
  130.       turtle.digUp()
  131.     end
  132.   end
  133. end
  134.  
  135. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement