Advertisement
VADemon

AE2craftingRoom

Nov 7th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.11 KB | None | 0 0
  1. -- Usage: place turtle above the level of AE interfaces at a corner of an empty row
  2. -- Supply with Interfaces
  3. -- Supply with Assemblers
  4. -- Supply with acceleratorUpgrades
  5.  
  6. -- It will build AE2 crafting grid automatically
  7.  
  8.  
  9. -- ItemSupply:
  10. -- rows, starting with 1
  11. interfaceBlock = 1
  12. assemblerBlock = 2
  13. acceleratorUpgrade = 3
  14.  
  15. acceleratorEnabled = true
  16. -- for accelerators
  17. chestSlot = 16  -- ender chest: slot or 0 to disable
  18.  
  19. -- moves row to the first slow of the row
  20. -- at least keep Target supply in slot
  21. function moveSupplyRow(row, target)
  22.     if not target then target = 16 end
  23.    
  24.     local start = (row-1)*4+2
  25.     for i = start, 16 do
  26.         if i ~= chestSlot then
  27.             -- exit if enough items
  28.             if turtle.getItemCount(start-1) >= target then break end
  29.            
  30.             turtle.select(i)
  31.             turtle.transferTo(start-1)
  32.         end
  33.     end
  34.    
  35.     if chestSlot ~= 0 and turtle.getItemCount(start-1) < target then
  36.         -- not enough items, fill from ender chest
  37.         local direction
  38.         local dirs = {"", "Up", "Down"}
  39.        
  40.         turtle.select(chestSlot)
  41.         for d = 1, #dirs do
  42.             direction = dirs[d]
  43.            
  44.             if turtle["place" .. direction]() then
  45.                 break
  46.             end
  47.            
  48.             if d == 3 then
  49.                 error("Couldnt refill from chest")
  50.             end
  51.         end
  52.        
  53.         for i = 1, 15 do
  54.             turtle["suck" .. direction]()
  55.             os.sleep(0.2)
  56.         end
  57.         -- free enderchest slot
  58.         turtle.select(chestSlot)
  59.         turtle["drop" .. direction]()
  60.         turtle["dig" .. direction]()
  61.     end
  62.    
  63.     turtle.select(row2slot(row))
  64. end
  65.  
  66. function row2slot(row)
  67.     return (row-1)*4+1
  68. end
  69.  
  70. function putUpgrades(side, n)
  71.     if not acceleratorEnabled then return end
  72.     side = side or ""
  73.     n = n or 5
  74.    
  75.     if turtle.getItemCount(row2slot(acceleratorUpgrade)) < 11 then
  76.          moveSupplyRow(acceleratorUpgrade, 64)
  77.     end
  78.    
  79.     turtle.select(row2slot(acceleratorUpgrade))
  80.     turtle["drop" .. side](n)
  81. end
  82.  
  83. function buildLevel()
  84.     if acceleratorEnabled then
  85.         moveSupplyRow(acceleratorUpgrade, 64)
  86.     end
  87.    
  88.     moveSupplyRow(assemblerBlock, 64)
  89.     -- assembler Row
  90.     for i = 1, rowLength do
  91.         turtle.forward()
  92.         turtle.select(row2slot(assemblerBlock))
  93.         turtle.placeDown()
  94.         putUpgrades("Down")
  95.         turtle.forward()
  96.        
  97.         -- dont move outside
  98.         if i ~= rowLength then
  99.             turtle.forward()
  100.         end
  101.     end
  102.    
  103.     -- interface row backwards
  104.     turtle.turnLeft()
  105.     turtle.forward()
  106.     turtle.turnRight()
  107.    
  108.     moveSupplyRow(interfaceBlock, 64)
  109.     moveSupplyRow(assemblerBlock, 64)
  110.     for i = 1, rowLength do
  111.         if acceleratorEnabled then
  112.             moveSupplyRow(acceleratorUpgrade, 64)
  113.         end
  114.        
  115.         turtle.select(row2slot(assemblerBlock))
  116.         turtle.placeDown()
  117.         putUpgrades("Down")
  118.         turtle.back()
  119.         turtle.select(row2slot(assemblerBlock))
  120.         turtle.placeUp()
  121.         putUpgrades("Up")
  122.        
  123.         turtle.select(row2slot(interfaceBlock))
  124.         turtle.placeDown()
  125.        
  126.         turtle.back()
  127.         turtle.select(row2slot(assemblerBlock))
  128.         turtle.place()
  129.         putUpgrades("")
  130.         turtle.placeDown()
  131.         putUpgrades("Down")
  132.         turtle.back()
  133.     end
  134.    
  135.     -- assembler row 2
  136.     turtle.turnLeft()
  137.     turtle.forward()
  138.     turtle.turnRight()
  139.     turtle.forward()
  140.    
  141.     moveSupplyRow(assemblerBlock, 64)
  142.     -- assembler Row
  143.     for i = 1, rowLength do
  144.         turtle.forward()
  145.         turtle.select(row2slot(assemblerBlock))
  146.         turtle.placeDown()
  147.         putUpgrades("Down")
  148.         turtle.forward()
  149.        
  150.         -- dont move outside
  151.         if i ~= rowLength then
  152.             turtle.forward()
  153.         end
  154.     end
  155.    
  156.     for i = 1, (rowLength*3 - 1) do
  157.         turtle.back()
  158.     end
  159. end
  160.  
  161. buildLevels = 1
  162. rowLength = 6
  163.  
  164. print("Row Length? Default: ".. tostring(rowLength))
  165. rowLength = tonumber(io.read()) or rowLength
  166. print("--> ".. tostring(rowLength) .. " interfaces length")
  167.  
  168.  
  169. print("How many rows to build? Default: ".. tostring(buildLevels))
  170. buildLevels = tonumber(io.read()) or buildLevels
  171. print("--> ".. tostring(buildLevels) .. " levels")
  172.  
  173. print("Direction? 'Left' or 'Right'. Default: 'Left'")
  174. direction = io.read()
  175. if direction == "" then
  176.     direction = "Left"
  177. end
  178. print("--> " .. tostring(direction))
  179.  
  180. print("Use accelerators? Y/n Default: yes")
  181. acceleratorEnabled = string.lower(io.read()) == "y" and true or false
  182. print("--> ".. tostring(acceleratorEnabled))
  183.  
  184. -- move away from wall after placement
  185. for n = 1, buildLevels do
  186.     buildLevel()
  187. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement