Advertisement
IMarvinTPA

Minecraft StripLayer

Dec 28th, 2012
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.59 KB | None | 0 0
  1. --pastebin get JWrTxV1z MakeRoom
  2. --pastebin get SpEd82Jp StripLayer
  3. local tArgs = { ... }
  4.  
  5. if #tArgs ~= 1 then
  6.         print( "Usage: MakeRoom <length>" )
  7.         return
  8. end
  9.  
  10. -- Mine in a quarry pattern until we hit something we can't dig
  11. local length = tonumber( tArgs[1] )
  12. if length < 1 then
  13.         print( "Room length must be positive" )
  14.         return
  15. end
  16.        
  17. local depth = 0
  18. local collected = 0
  19. local unloaded = 0
  20.  
  21. local function collect()
  22.         collected = collected + 1
  23.         if math.fmod(collected, 25) == 0 then
  24.                 print( "Mined "..collected.." items." )
  25.         end
  26. end
  27.  
  28. local function isFull()
  29.         local bFull = true
  30.         local nTotalItems = 0
  31.         for n=1,16 do
  32.                 local nCount = turtle.getItemCount(n)
  33.                 if nCount == 0 then
  34.                         bFull = false
  35.                 end
  36.                 nTotalItems = nTotalItems + nCount
  37.         end
  38.              
  39.         if bFull then
  40.                 print( "No empty slots left." )
  41.                 return true
  42.         end
  43.         return false
  44. end
  45.  
  46. local function unload()
  47.         print( "Unloading items..." )
  48.         turtle.turnRight()
  49.         turtle.turnRight()
  50.         turtle.select(3)
  51.         turtle.place()
  52.         --1: Flooring
  53.         --2: Fuel
  54.         --3: Chests
  55.         for n=4,16 do
  56.                 unloaded = unloaded + turtle.getItemCount(n)
  57.                 turtle.select(n)
  58.                 turtle.drop()
  59.         end
  60.         --collected = 0
  61.         turtle.select(1)
  62.         turtle.turnRight()
  63.         turtle.turnRight()     
  64. end
  65.  
  66.  
  67. local function tryDig()
  68.         while turtle.detect() do
  69.                 if turtle.dig() then
  70.                         collect()
  71.                         sleep(0.5)
  72.                 else
  73.                         return false
  74.                 end
  75.         end
  76.         return true
  77. end
  78.  
  79. local function tryDigUp()
  80.         while turtle.detectUp() do
  81.                 if turtle.digUp() then
  82.                         collect()
  83.                         sleep(0.5)
  84.                 else
  85.                         return false
  86.                 end
  87.         end
  88.         return true
  89. end
  90.  
  91. local function refuel()
  92.         local fuelLevel = turtle.getFuelLevel()
  93.         if fuelLevel == "unlimited" or fuelLevel > 0 then
  94.                 return
  95.         end
  96.        
  97.         local function tryRefuel()
  98.                 for n=1,16 do
  99.                         if turtle.getItemCount(n) > 0 then
  100.                                 turtle.select(n)
  101.                                 if turtle.refuel(1) then
  102.                                         turtle.select(1)
  103.                                         return true
  104.                                 end
  105.                         end
  106.                 end
  107.                 turtle.select(1)
  108.                 return false
  109.         end
  110.        
  111.         if not tryRefuel() then
  112.                 print( "Add more fuel to continue." )
  113.                 while not tryRefuel() do
  114.                         sleep(1)
  115.                 end
  116.                 print( "Resuming Tunnel." )
  117.         end
  118. end
  119.  
  120. local function tryUp()
  121.         refuel()
  122.         while not turtle.up() do
  123.                 if turtle.detectUp() then
  124.                         if not tryDigUp() then
  125.                                 return false
  126.                         end
  127.                 elseif turtle.attackUp() then
  128.                         collect()
  129.                 else
  130.                         sleep( 0.5 )
  131.                 end
  132.         end
  133.         return true
  134. end
  135.  
  136. local function tryDown()
  137.         refuel()
  138.         while not turtle.down() do
  139.                 if turtle.detectDown() then
  140.                         if not tryDigDown() then
  141.                                 return false
  142.                         end
  143.                 elseif turtle.attackDown() then
  144.                         collect()
  145.                 else
  146.                         sleep( 0.5 )
  147.                 end
  148.         end
  149.         return true
  150. end
  151.  
  152. local function tryForward()
  153.         refuel()
  154.         if isFull() then
  155.             unload()
  156.         end
  157.         while not turtle.forward() do
  158.                 if turtle.detect() then
  159.                         if not tryDig() then
  160.                                 return false
  161.                         end
  162.                 elseif turtle.attack() then
  163.                         collect()
  164.                 else
  165.                         sleep( 0.5 )
  166.                 end
  167.         end
  168.         return true
  169. end
  170.  
  171. local function hallway(hallLength)
  172.     for n=1,hallLength do
  173.         turtle.placeDown()
  174.         --turtle.turnLeft()
  175.         --tryDig()
  176.         --turtle.turnRight()
  177.         --turtle.turnRight()
  178.         --tryDig()
  179.         --turtle.turnLeft()
  180.        
  181.         if n<hallLength then
  182.                 tryDig()
  183.                 if not tryForward() then
  184.                         return false
  185.                 end
  186.         else
  187.                 return true
  188.         end
  189.     end
  190. end
  191.  
  192. print( "Tunnelling..." )
  193.  
  194. turtle.turnRight()
  195. turtle.turnRight()
  196. tryForward()
  197. hallway(1)
  198. turtle.turnRight()
  199. turtle.turnRight()
  200. tryForward()
  201.  
  202. for s=1,4 do
  203.     print( "Side: "..s )
  204.     hallway(length)
  205.     turtle.back()
  206.     turtle.turnLeft()
  207. end
  208.  
  209. turtle.turnRight()
  210. turtle.back()
  211. turtle.back()
  212. turtle.back()
  213. turtle.turnLeft()
  214. tryForward()
  215. --                cut + hall error + length mod.
  216. length = length - 6 + 1 + 1
  217. reduceRun = true
  218. while length > 1 do
  219.     print( "Length: "..length )
  220.     hallway(length)
  221.     if reduceRun then
  222.         length = length - 3
  223.         reduceRun = false
  224.     else
  225.         reduceRun = true
  226.     end
  227.     turtle.back()
  228.     turtle.turnLeft()
  229.     tryForward()
  230. end
  231.  
  232.  
  233. print( "Room complete." )
  234. print( "Mined "..collected.." items total." )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement