Advertisement
Guest User

tunneler

a guest
Mar 27th, 2017
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1. -- Arguements and Arg Checking
  2. local tArgs = { ... }
  3. if #tArgs ~= 1 then
  4.     print( "Usage: tunnel <length>" )
  5.     return
  6. end
  7. local length = tonumber( tArgs[1] )
  8. if length < 1 then
  9.     print( "Tunnel length must be positive" )
  10.     return
  11. end
  12.  
  13. -- Collected block number / Increaser
  14. local collected = 0
  15. local function collect()
  16.     collected = collected + 1
  17.     if math.fmod(collected, 25) == 0 then
  18.         print( "Mined "..collected.." blocks." )
  19.     end
  20. end
  21.  
  22.  
  23. -- Digging functions
  24. local function tryDig()
  25.     while turtle.dig() do
  26.         collect()
  27.         sleep(0.5)
  28.         if not turtle.detect() then
  29.             return true
  30.         end
  31.     end
  32.     return not turtle.detect()
  33. end
  34.  
  35. local function tryDigUp()
  36.     while turtle.digUp() do
  37.         collect()
  38.         sleep(0.5)
  39.         if not turtle.detectUp() then
  40.             return true
  41.         end
  42.     end
  43.     return not turtle.detectUp()
  44. end
  45.  
  46. -- Functions for dropping off items into a chest from slot 1.
  47. local function depositChest()
  48.     turtle.up()
  49.     turtle.turnRight()
  50.     turtle.forward()
  51.     turtle.select(1)
  52.     turtle.placeDown()
  53.     sleep(0.5)
  54.     for slot=4,16 do
  55.         turtle.select(slot)
  56.         turtle.dropDown(turtle.getItemCount(slot))
  57.         sleep(0.5)
  58.     end
  59.     turtle.select(1)
  60. end
  61.  
  62. local function previousState()
  63.     turtle.turnLeft()
  64.     sleep(0.5)
  65.     turtle.turnLeft()
  66.     sleep(0.5)
  67.     turtle.forward()
  68.     sleep(0.5)
  69.     turtle.down()
  70.     sleep(0.5)
  71.     turtle.turnRight()
  72. end
  73.  
  74. local function checkSpace()
  75.     local space = 0
  76.     for slot=3,16 do
  77.         if turtle.getItemCount(slot) == 0 then
  78.             space = space + 1
  79.         end
  80.         --space = space + (turtle.getItemCount(slot)>0)
  81.     end
  82.     if space == 0 then
  83.         depositChest()
  84.         previousState()
  85.         return false
  86.     else
  87.         return true
  88.     end
  89. end
  90.  
  91. -- Main Program for digging the tunnel
  92. print( "Tunnelling..." )
  93. for n=1,length do
  94.     tryDig()
  95.     if not turtle.forward() then
  96.         print( "Aborting Tunnel." )
  97.         break
  98.     end
  99.  
  100.     turtle.select(2)
  101.     turtle.placeDown()
  102.     --if not checkSpace() then break end
  103.    
  104.     tryDigUp()
  105.     turtle.turnLeft()
  106.     tryDig()
  107.     turtle.up()
  108.     tryDig()
  109.     tryDigUp()
  110.     turtle.up()
  111.     tryDig()
  112.     turtle.turnRight()
  113.     turtle.turnRight()
  114.     tryDig()
  115.     turtle.down()
  116.     tryDig()
  117.  
  118.     if (n%7 == 6) then
  119.         turtle.select(3)
  120.         if (turtle.getItemDetail().name == "minecraft:torch") then
  121.             turtle.place()
  122.         end
  123.         turtle.select(2)
  124.     end
  125.    
  126.     turtle.down()
  127.     tryDig()
  128.     turtle.turnLeft()  
  129.     checkSpace()
  130.  
  131.     if (n == length) then
  132.         print( "Tunnel complete!")
  133.     end
  134. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement