Gokborg

Mining

Apr 4th, 2020
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.52 KB | None | 0 0
  1. tunnelLength = 32
  2. gapBetweenTunnels = 2
  3. freakOutOres = {
  4.     "minecraft:diamond_ore",
  5.     "immersiveengineering:ore_silver",
  6. }
  7. bridgeBlocks = {
  8.     "minecraft:granite",
  9.     "minecraft:cobblestone",
  10. }
  11.  
  12.  
  13. UP = 1
  14. DOWN = 2
  15.  
  16. function freakOut()
  17.     print("FREAKING THE FUCK OUT!!!!")
  18.     read()
  19. end
  20.  
  21. function hasItem(name)
  22.     for i = 1, 16 do
  23.         local block = turtle.getItemDetail(i)
  24.         if block ~= nil then
  25.             if block.name == name then
  26.                 return true, i, block
  27.             end
  28.         end
  29.     end
  30.     return false, nil, nil
  31. end
  32.  
  33. function isInFront(name)
  34.     local success, block = turtle.inspect()
  35.     if success == true then
  36.         if block.name == name then
  37.             return true
  38.         end
  39.     end
  40.     return false
  41. end
  42.  
  43. function dig(dir)
  44.     local success, block = turtle.inspect()
  45.     if success == true then
  46.         for _, v in pairs(freakOutOres) do
  47.             if v == block.name then
  48.                 freakOut()
  49.             end
  50.         end
  51.     end
  52.     dir = dir or 0
  53.     if dir == UP then
  54.         turtle.digUp()
  55.     elseif dir == DOWN then
  56.         turtle.digDown()
  57.     else
  58.         turtle.dig()
  59.     end
  60.    
  61. end
  62.  
  63. function tryPlaceBridgeBlock()
  64.     for _, v in pairs(bridgeBlocks) do
  65.         local success, index, block = hasItem(v)
  66.         if success == true then
  67.             turtle.select(index)
  68.             turtle.placeDown()
  69.             break
  70.         end
  71.     end
  72. end
  73.  
  74. function tryPlaceBridgeBlockOnFloor()
  75.     local success, block = turtle.inspectDown()
  76.     if success == false then
  77.         tryPlaceBridgeBlock()
  78.     elseif success == true then
  79.         if block.name == "minecraft:lava" or block.name == "minecraft:water" then
  80.             tryPlaceBridgeBlock()
  81.         end
  82.     end
  83. end
  84.  
  85. turtle.turnLeft()
  86. turtle.turnLeft()
  87. if isInFront("minecraft:chest") == false then
  88.     error("No chest found!")
  89. end
  90. turtle.turnRight()
  91. turtle.turnRight()
  92. print("Chest found, lets get mining!")
  93. offsetFromChest = 0
  94. while true do
  95.     turtle.turnLeft()
  96.    
  97.     --Forward Action Tunnel 1 1x2
  98.     for i = 0, tunnelLength do
  99.         dig()
  100.         turtle.forward()
  101.         dig(UP)
  102.     end
  103.    
  104.     --Back to original spot
  105.     for i = 0, tunnelLength do
  106.         tryPlaceBridgeBlockOnFloor()
  107.         turtle.back()
  108.     end
  109.    
  110.     --Face the direction of action tunnel 2
  111.     turtle.turnRight()
  112.     turtle.turnRight()
  113.    
  114.     --Forward Action Tunnel 2 1x2
  115.     for i = 0, tunnelLength do
  116.         dig()
  117.         turtle.forward()
  118.         dig(UP)
  119.     end
  120.    
  121.     --Back to original - 1 so that it isn't in the center
  122.     for i = 0, tunnelLength - 1 do
  123.         tryPlaceBridgeBlockOnFloor()
  124.         turtle.back()
  125.     end
  126.     turtle.turnLeft()
  127.    
  128.     --Refuel on any coal it has
  129.     local success, index, block = hasItem("minecraft:coal")
  130.     if success == true then
  131.         turtle.select(index)
  132.         turtle.refuel(block.count)
  133.     end
  134.    
  135.     --excavate 3 x 3 space in center
  136.     for i = 0, gapBetweenTunnels do
  137.         dig()
  138.         turtle.forward()
  139.         local success, block = turtle.inspectDown()
  140.         dig(UP)
  141.         turtle.up()
  142.         dig(UP)
  143.         turtle.turnLeft()
  144.         dig()
  145.         turtle.forward()
  146.         dig(UP)
  147.         dig(DOWN)
  148.         dig()
  149.         turtle.forward()
  150.         dig(UP)
  151.         dig(DOWN)
  152.         turtle.back()
  153.         turtle.back()
  154.         turtle.turnRight()
  155.         turtle.down()
  156.     end
  157.     turtle.turnLeft()
  158.     turtle.forward()
  159.     turtle.turnLeft()
  160.    
  161.     --Keeps dumping away cobblestone!
  162.     local success, index, block = hasItem("minecraft:cobblestone")
  163.     while success do
  164.         turtle.select(index)
  165.         turtle.drop()
  166.         success, index, block = hasItem("minecraft:cobblestone")
  167.     end
  168.    
  169.     --Facing towards chest runs forward
  170.     offsetFromChest = offsetFromChest + gapBetweenTunnels + 1
  171.     for i = 1, offsetFromChest do
  172.         turtle.forward()
  173.     end
  174.    
  175.     --Drops all items in chest
  176.     for i = 1, 16 do
  177.         turtle.select(i)
  178.         turtle.drop()
  179.     end
  180.     turtle.turnRight()
  181.     turtle.turnRight()
  182.     for i = 1, offsetFromChest do
  183.         turtle.forward()
  184.     end
  185. end
Add Comment
Please, Sign In to add comment