Advertisement
PyroDeathAdder

ComputerCraft mine 2.0

Apr 5th, 2020
1,054
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.84 KB | None | 0 0
  1. function veinMine() --vein mines ores that are adjasent to each other
  2.     --list of unwanted blocks
  3.     unwanted = {['minecraft:cobblestone']=true,['minecraft:stone']=true,['minecraft:dirt']=true,['minecraft:gravel']=true,['minecraft:sandstone']=true,['minecraft:sand']=true,['minecraft:torch']=true}
  4.     for i = 1, 4 do
  5.         success, data = turtle.inspect()
  6.         if success and unwanted[data.name] == nil and data.state.level == nil then
  7.             turtle.dig()
  8.             turtle.forward()
  9.             veinMine()
  10.             turtle.back()
  11.         end
  12.         turtle.turnRight()
  13.     end
  14.     success, data = turtle.inspectUp()
  15.     if success and unwanted[data.name] == nil and data.state.level == nil then
  16.         turtle.digUp()
  17.         turtle.up()
  18.         veinMine()
  19.         turtle.down()
  20.     end
  21.     success, data = turtle.inspectDown()
  22.     if success and unwanted[data.name] == nil and data.state.level == nil then
  23.         turtle.digDown()
  24.         turtle.down()
  25.         veinMine()
  26.         turtle.up()
  27.     end
  28. end
  29.  
  30. function clearInv() --clears the players inventory of useless blocks that are not needed
  31.     --drop all non essential items [cobble, diorite, andesite ect..]
  32.     for n=1,15 do
  33.         p = turtle.getItemDetail(n)
  34.         if p ~= nil then
  35.             if p.name == "minecraft:cobblestone" or p.name == "minecraft:stone" then
  36.                 turtle.select(n)
  37.                 turtle.dropDown()
  38.             end
  39.         end
  40.     end
  41.     turtle.select(16)
  42. end
  43.  
  44. function miniTunnel(len, blocks, torches, ore_collect) --mini tunnels that are 1 wide
  45.     sinceLastTorch = 0
  46.     for i=1,len do
  47.         if blocks then
  48.             while turtle.detect() do
  49.                 turtle.dig()
  50.                 os.sleep(0.5)
  51.             end
  52.         end
  53.         --if needed check for ores before placing torch
  54.         --move down
  55.         --look left -> if ore mine
  56.         --look right -> if ore mine
  57.         --move up -> repeat 1 - 3 x2
  58.         if ore_collect and i >= 3 then
  59.             turtle.down()
  60.             veinMine()
  61.             turtle.up()
  62.             veinMine()
  63.             turtle.up()
  64.             veinMine()
  65.             turtle.down()
  66.         end
  67.  
  68.         if i % 13 == 3 and torches then
  69.             turtle.select(16)
  70.             turtle.placeDown()
  71.             sinceLastTorch = 0
  72.             clearInv()
  73.         end
  74.         turtle.forward()
  75.         sinceLastTorch = sinceLastTorch + 1
  76.         if blocks then
  77.             --mine block above and below turtle [height of 3]
  78.             while turtle.detectUp() or turtle.detectDown() do
  79.                 turtle.digUp()
  80.                 turtle.digDown()
  81.             end
  82.         end
  83.     end
  84.     if sinceLastTorch >= 7 and torches then
  85.         turtle.select(16)
  86.         turtle.placeDown()
  87.         sinceLastTorch = 0
  88.     end
  89. end
  90.  
  91. function checkSpace(moved)--check how much space is in the inventory, if more than threshold[set to 10/16] clear items
  92.     clearInv()
  93.     storage = 0
  94.     for i=1,15 do
  95.         details = turtle.getItemDetail(i)
  96.         if details ~= nil then
  97.             storage = storage + 1
  98.         end
  99.     end
  100.  
  101.     if storage >= 10 then
  102.         --move back to start to drop off items if not at end
  103.         if length ~= 1 then
  104.             turtle.turnLeft()
  105.             turtle.turnLeft()
  106.             for i=1,m do
  107.                 turtle.forward()
  108.             end
  109.             for i=1,15 do
  110.                 turtle.select(i)
  111.                 turtle.dropDown()
  112.             end
  113.             turtle.turnLeft()
  114.             turtle.turnLeft()
  115.             for i=1,moved do
  116.                 turtle.forward()
  117.             end
  118.         end
  119.     end
  120. end
  121.  
  122. function Tunnel(len, side_tunnels) --the main 3x3 tunnel function
  123.     local length = tonumber(len)
  124.     local tunnelLength = length
  125.     local sideTunnels = tonumber(side_tunnels) + 1
  126.     local moved = 1
  127.  
  128.     while (turtle.detect() and length >= 1) or length >= 1 do
  129.         --main tunnel section
  130.         miniTunnel(1,true, false, false)
  131.         turtle.turnLeft()
  132.         miniTunnel(1,true, false, false)
  133.         turtle.turnRight()
  134.         turtle.turnRight()
  135.         miniTunnel(1, false, false, false)
  136.         miniTunnel(1, true, false, false)
  137.         turtle.turnLeft()
  138.         turtle.turnLeft()
  139.         miniTunnel(1, false, false, false)
  140.         turtle.turnRight()
  141.         --check if torch needed
  142.         if length % 3 == 1 then
  143.             turtle.turnLeft()
  144.             miniTunnel(sideTunnels, true, true, true)
  145.             turtle.turnRight()
  146.             turtle.turnRight()
  147.             miniTunnel(sideTunnels, false, false, false)
  148.             turtle.turnLeft()
  149.             checkSpace(moved)
  150.             turtle.turnRight()
  151.             miniTunnel(sideTunnels, true, true, true)
  152.             turtle.turnLeft()
  153.             turtle.turnLeft()
  154.             miniTunnel(sideTunnels, false, false, false)
  155.             turtle.turnRight()
  156.             checkSpace(moved)
  157.         end
  158.         length = length - 1
  159.         moved = moved + 1
  160.     end
  161.  
  162.     returnHome(tunnelLength)
  163. end
  164.  
  165. function returnHome(l) --after everything is done return the turtle to the chest
  166.     clearInv()
  167.     turtle.turnRight()
  168.     turtle.turnRight()
  169.     for i=1,l do
  170.         turtle.forward()
  171.     end
  172.     for i=1,15 do
  173.         turtle.select(n)
  174.         turtle.dropDown()
  175.     end
  176. end
  177.  
  178. local tArgs = { ... } --getting arguments
  179. local size = tonumber( tArgs[1] )
  180. if #tArgs ~= 2 then --checking argument size
  181.     print( "Usage: mine <length> <strip's length>" )
  182.     return
  183. end
  184.  
  185. local size = tonumber( tArgs[1] ) --checking tunnel size
  186. if size < 1 then
  187.     print( "Mine length must be positive" )
  188.     return
  189. end
  190.  
  191. size = tonumber( tArgs[2] ) --checking strip size
  192. if size < 1 then
  193.     print( "Strip length must be positive" )
  194.     return
  195. end
  196.  
  197. Tunnel(tArgs[1], tArgs[2]) --start the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement