Advertisement
IMarvinTPA

Minecraft Arches

Dec 28th, 2012
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.11 KB | None | 0 0
  1. --pastebin get 7ntRFDfp Arch
  2. local tArgs = { ... }
  3.  
  4. if #tArgs ~= 2 then
  5.         print( "Usage: Arch <count> <0|1 start column>" )
  6.         print( "Row 1 should have fuel" )
  7.         print( "Row 2 and 3 should be the outer shell blocks" )
  8.         print( "Row 4 should be the center shell blocks" )
  9.         return
  10. end
  11.  
  12. -- Mine in a quarry pattern until we hit something we can't dig
  13. local length = 5
  14. local tall = 4
  15.  
  16. local archCount = tonumber( tArgs[1] )
  17.  
  18. local startColumn = tonumber( tArgs[2] )
  19.  
  20. if archCount < 1 then
  21.         print( "Arch count must be positive" )
  22.         return
  23. end
  24.  
  25. if length < 1 then
  26.         print( "Tunnel length must be positive" )
  27.         return
  28. end
  29.  
  30. if tall < 1 then
  31.         print( "Tunnel height must be positive" )
  32.         return
  33. end
  34.        
  35. local depth = 0
  36. local collected = 0
  37. local unloaded = 0
  38.  
  39. local function collect()
  40.         collected = collected + 1
  41.         if math.fmod(collected, 25) == 0 then
  42.                 print( "Mined "..collected.." items." )
  43.         end
  44. end
  45.  
  46. local function isFull()
  47.         local bFull = true
  48.         local nTotalItems = 0
  49.         for n=1,16 do
  50.                 local nCount = turtle.getItemCount(n)
  51.                 if nCount == 0 then
  52.                         bFull = false
  53.                 end
  54.                 nTotalItems = nTotalItems + nCount
  55.         end
  56.              
  57.         if bFull then
  58.                 print( "No empty slots left." )
  59.                 return true
  60.         end
  61.         return false
  62. end
  63.  
  64. local function unload()
  65.         print( "Unloading items..." )
  66.         turtle.turnRight()
  67.         turtle.turnRight()
  68.         turtle.select(3)
  69.         turtle.place()
  70.         --1: Flooring
  71.         --2: Fuel
  72.         --3: Chests
  73.         --4: Torches
  74.         for n=5,16 do
  75.                 unloaded = unloaded + turtle.getItemCount(n)
  76.                 turtle.select(n)
  77.                 turtle.drop()
  78.         end
  79.         --collected = 0
  80.         turtle.select(1)
  81.         turtle.turnRight()
  82.         turtle.turnRight()     
  83. end
  84.  
  85.  
  86. local function tryDig()
  87.         while turtle.detect() do
  88.                 if turtle.dig() then
  89.                         collect()
  90.                         sleep(0.5)
  91.                 else
  92.                         return false
  93.                 end
  94.         end
  95.         return true
  96. end
  97.  
  98. local function tryDigUp()
  99.         while turtle.detectUp() do
  100.                 if turtle.digUp() then
  101.                         collect()
  102.                         sleep(0.5)
  103.                 else
  104.                         return false
  105.                 end
  106.         end
  107.         return true
  108. end
  109.  
  110. local function refuel()
  111.         local fuelLevel = turtle.getFuelLevel()
  112.         if fuelLevel == "unlimited" or fuelLevel > 0 then
  113.                 return
  114.         end
  115.        
  116.         local function tryRefuel()
  117.                 for n=1,16 do
  118.                     if turtle.getItemCount(n) > 0 then
  119.                             turtle.select(n)
  120.                             if turtle.refuel(1) then
  121.                                     turtle.select(1)
  122.                                     return true
  123.                             end
  124.                     end
  125.                 end
  126.                 turtle.select(1)
  127.                 return false
  128.         end
  129.        
  130.         if not tryRefuel() then
  131.                 print( "Add more fuel to continue." )
  132.                 while not tryRefuel() do
  133.                         sleep(1)
  134.                 end
  135.                 print( "Resuming Tunnel." )
  136.         end
  137. end
  138.  
  139. local function tryUp()
  140.         refuel()
  141.         while not turtle.up() do
  142.                 if turtle.detectUp() then
  143.                         if not tryDigUp() then
  144.                                 return false
  145.                         end
  146.                 elseif turtle.attackUp() then
  147.                         collect()
  148.                 else
  149.                         sleep( 0.5 )
  150.                 end
  151.         end
  152.         return true
  153. end
  154.  
  155. local function tryDown()
  156.         refuel()
  157.         while not turtle.down() do
  158.                 if turtle.detectDown() then
  159.                         --if not tryDigDown() then
  160.                                 return false
  161.                         --end
  162.                 elseif turtle.attackDown() then
  163.                         collect()
  164.                 else
  165.                         sleep( 0.5 )
  166.                 end
  167.         end
  168.         return true
  169. end
  170.  
  171. local function tryForward()
  172.         refuel()
  173.         while not turtle.forward() do
  174.                 if turtle.detect() then
  175.                         if not tryDig() then
  176.                                 return false
  177.                         end
  178.                 elseif turtle.attack() then
  179.                         collect()
  180.                 else
  181.                         sleep( 0.5 )
  182.                 end
  183.         end
  184.         return true
  185. end
  186.  
  187. local function tryBack()
  188.         refuel()
  189.         while not turtle.back() do
  190.             sleep( 0.5 )
  191.         end
  192.         return true
  193. end
  194.  
  195. local function placeOuter()
  196.     for n=5,12 do
  197.         if turtle.getItemCount(n) > 0 then
  198.                 turtle.select(n)
  199.                 if turtle.place() then
  200.                         turtle.select(1)
  201.                         return true
  202.                 end
  203.         end
  204.     end
  205.     turtle.select(1)
  206.     return false
  207. end
  208.  
  209. local function placeInner()
  210.     for n=13,16 do
  211.         if turtle.getItemCount(n) > 0 then
  212.                 turtle.select(n)
  213.                 if turtle.place() then
  214.                         turtle.select(1)
  215.                         return true
  216.                 end
  217.         end
  218.     end
  219.     turtle.select(1)
  220.     return false
  221. end
  222.  
  223.  
  224.  
  225. local function hallway(hallLength)
  226.     for n=1,hallLength do
  227.         turtle.placeDown()
  228.         turtle.turnLeft()
  229.         tryDig()
  230.         for m=2, tall do
  231.             tryDigUp()
  232.             tryUp()
  233.             tryDig()
  234.         end
  235.         turtle.turnRight()
  236.         turtle.turnRight()
  237.         tryDig()
  238.         for m=2, tall do
  239.             tryDown()
  240.         tryDig()
  241.         end
  242.         if math.fmod(n, 6) == 0 then
  243.             turtle.select(4)
  244.             turtle.place()
  245.             turtle.select(1)
  246.         end
  247.         turtle.turnLeft()
  248.        
  249.         if n<hallLength then
  250.                 tryDig()
  251.                 if not tryForward() then
  252.                         return false
  253.                 end
  254.         else
  255.                 return true
  256.         end
  257.     end
  258. end
  259.  
  260. print( "Building..." )
  261.  
  262. local function makeOuterPillar(dir)
  263.     for n = 1, tall do 
  264.         placeOuter()
  265.         if n < tall then
  266.             if (dir > 0) then
  267.                 if not tryUp() then
  268.                     return false
  269.                 end
  270.             else
  271.                 if not tryDown() then
  272.                     return false
  273.                 end
  274.             end
  275.         end
  276.     end
  277. end
  278.  
  279. local function makeMiddlePillar(dir)
  280.     if dir < 0 then
  281.         placeOuter()
  282.     else
  283.         placeInner()
  284.     end
  285.     if tall > 1 then
  286.         if (dir > 0) then
  287.             if not tryUp() then
  288.                 return false
  289.             end
  290.         else
  291.             if not tryDown() then
  292.                 return false
  293.             end
  294.         end
  295.     end
  296.     for n = 1, tall - 2 do 
  297.         placeInner()       
  298.         if (dir > 0) then
  299.             if not tryUp() then
  300.                 return false
  301.             end
  302.         else
  303.             if not tryDown() then
  304.                 return false
  305.             end
  306.         end
  307.     end
  308.     if tall > 1 then
  309.         if dir > 0 then
  310.             placeOuter()
  311.         else
  312.             placeInner()
  313.         end
  314.     end
  315. end
  316.  
  317. tryForward()
  318. turtle.turnRight()
  319. turtle.turnRight()
  320. local mdir = 1
  321. if startColumn == 1 then
  322.     makeOuterPillar(mdir)
  323.     tryBack()
  324.     mdir = -1 * mdir
  325. end
  326. for n = 1, archCount do
  327.     for l = 2, length - 1 do
  328.         makeMiddlePillar(mdir)
  329.         mdir = -1 * mdir
  330.         tryBack()
  331.     end
  332.     makeOuterPillar(mdir)
  333.     tryBack()
  334.     mdir = -1 * mdir
  335. end
  336.  
  337.  
  338.  
  339. print( "Arches complete." )
  340. print( "Mined "..collected.." items total." )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement