Advertisement
PyroDeathAdder

ComputerCraft mine

Apr 4th, 2020
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.86 KB | None | 0 0
  1. function clearInv()
  2.     --drop all non essential items [cobble, diorite, andesite ect..]
  3.     for n=1,15 do
  4.         p = turtle.getItemDetail(n)
  5.         if p ~= nil then
  6.             if p.name == "minecraft:cobblestone" or p.name == "minecraft:stone" then
  7.                 turtle.select(n)
  8.                 turtle.dropDown()
  9.             end
  10.         end
  11.     end
  12.     turtle.select(16)
  13. end
  14.  
  15. function miniTunnel(l, b, t)
  16.     for n=1,l do
  17.         if b then
  18.             while turtle.detect() do
  19.                 turtle.dig()
  20.                 os.sleep(0.5)
  21.             end
  22.         end
  23.         if n % 8 == 3 and t then
  24.             turtle.select(16)
  25.             turtle.placeDown()
  26.             clearInv()
  27.         end
  28.         turtle.forward()
  29.         if b then
  30.             --mine block above and below turtle [height of 3]
  31.             while turtle.detectUp() or turtle.detectDown() do
  32.                 turtle.digUp()
  33.                 turtle.digDown()
  34.             end
  35.         end
  36.     end
  37. end
  38.  
  39. function checkSpace(m)
  40.     clearInv()
  41.     storage = 0
  42.     for n=1,15 do
  43.         p = turtle.getItemDetail(n)
  44.         if p ~= nil then
  45.             storage = storage + 1
  46.         end
  47.     end
  48.  
  49.     if storage >= 10 then
  50.         --move back to start to drop off items if not at end
  51.         if length ~= 1 then
  52.             turtle.turnLeft()
  53.             turtle.turnLeft()
  54.             for n=1,m do
  55.                 turtle.forward()
  56.             end
  57.             for n=1,15 do
  58.                 turtle.select(n)
  59.                 turtle.dropDown()
  60.             end
  61.             turtle.turnLeft()
  62.             turtle.turnLeft()
  63.             for n=1,m do
  64.                 turtle.forward()
  65.             end
  66.         end
  67.     end
  68. end
  69.  
  70. function Tunnel(l, st)
  71.     local length = tonumber(l)
  72.     local tunnelLength = length
  73.     local sideTunnels = tonumber(st) + 1
  74.     local moved = 1
  75.  
  76.     while (turtle.detect() and length >= 1) or length >= 1 do
  77.         --main tunnel section
  78.         miniTunnel(1,true, false)
  79.         turtle.turnLeft()
  80.         miniTunnel(1,true, false)
  81.         turtle.turnRight()
  82.         turtle.turnRight()
  83.         miniTunnel(1, false, false)
  84.         miniTunnel(1, true, false)
  85.         turtle.turnLeft()
  86.         turtle.turnLeft()
  87.         miniTunnel(1, false, false)
  88.         turtle.turnRight()
  89.         --check if torch needed
  90.         if length % 3 == 1 then
  91.             turtle.turnLeft()
  92.             miniTunnel(sideTunnels, true, true)
  93.             turtle.turnRight()
  94.             turtle.turnRight()
  95.             miniTunnel(sideTunnels, false, false)
  96.             turtle.turnLeft()
  97.             checkSpace(moved)
  98.             turtle.turnRight()
  99.             miniTunnel(sideTunnels, true, true)
  100.             turtle.turnLeft()
  101.             turtle.turnLeft()
  102.             miniTunnel(sideTunnels, false, false)
  103.             turtle.turnRight()
  104.             checkSpace(moved)
  105.         end
  106.         length = length - 1
  107.         moved = moved + 1
  108.     end
  109.  
  110.     returnHome(tunnelLength)
  111. end
  112.  
  113. function returnHome(l)
  114.     clearInv()
  115.     turtle.turnRight()
  116.     turtle.turnRight()
  117.     for n=1,l do
  118.         turtle.forward()
  119.     end
  120.     for n=1,15 do
  121.         turtle.select(n)
  122.         turtle.dropDown()
  123.     end
  124. end
  125.  
  126. local tArgs = { ... }
  127. local size = tonumber( tArgs[1] )
  128. if #tArgs ~= 2 then
  129.     print( "Usage: mine <length> <strip's length>" )
  130.     return
  131. end
  132.  
  133. local size = tonumber( tArgs[1] )
  134. if size < 1 then
  135.     print( "Mine length must be positive" )
  136.     return
  137. end
  138.  
  139. size = tonumber( tArgs[2] )
  140. if size < 1 then
  141.     print( "Strip length must be positive" )
  142.     return
  143. end
  144.  
  145. Tunnel(tArgs[1], tArgs[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement