Advertisement
IMarvinTPA

Minecraft MakeRoom

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