Advertisement
VADemon

SpawnerOutsideLamps

Nov 5th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.34 KB | None | 0 0
  1. -- Usage: place outside against the redwire
  2. -- Supply with inverted Lamps
  3. -- Supply with wires
  4.  
  5. -- It will build lamps into the wall and place wires VERTICALLY
  6.  
  7.  
  8. -- ItemSupply:
  9. -- rows, starting with 1
  10. wireBlock = 1
  11. lampBlock = 2
  12.  
  13. wireEnabled = true
  14. lampEnabled = true
  15.  
  16. chestSlot = 0   -- ender chest: slot or 0 to disable DOESNT WORK HERE
  17.  
  18. spawnerHeight = 2 * 2
  19.  
  20. -- moves row to the first slow of the row
  21. -- at least keep Target supply in slot
  22. function moveSupplyRow(row, target)
  23.     if not target then target = 16 end
  24.    
  25.     local start = (row-1)*4+2
  26.     for i = start, 16 do
  27.         if i ~= chestSlot then
  28.             -- exit if enough items
  29.             if turtle.getItemCount(start-1) >= target then break end
  30.            
  31.             turtle.select(i)
  32.             turtle.transferTo(start-1)
  33.         end
  34.     end
  35.    
  36.     if chestSlot ~= 0 and turtle.getItemCount(start-1) < target then
  37.         -- not enough items, fill from ender chest
  38.         local direction
  39.         local dirs = {"", "Up", "Down"}
  40.        
  41.         turtle.select(chestSlot)
  42.         for d = 1, #dirs do
  43.             direction = dirs[d]
  44.            
  45.             if turtle["place" .. direction]() then
  46.                 break
  47.             end
  48.            
  49.             if d == 3 then
  50.                 error("Couldnt refill from chest")
  51.             end
  52.         end
  53.        
  54.         for i = 1, 15 do
  55.             turtle["suck" .. direction]()
  56.             os.sleep(0.2)
  57.         end
  58.         -- free enderchest slot
  59.         turtle.select(chestSlot)
  60.         turtle["drop" .. direction]()
  61.         turtle["dig" .. direction]()
  62.     end
  63.    
  64.     turtle.select(row2slot(row))
  65. end
  66.  
  67. function row2slot(row)
  68.     return (row-1)*4+1
  69. end
  70.  
  71. function buildLevel()
  72.     if lampEnabled then
  73.         moveSupplyRow(lampBlock, 64)
  74.     end
  75.    
  76.     if wireEnabled then
  77.         moveSupplyRow(wireBlock, 64)
  78.     end
  79.  
  80.     for i = 1, spawnerHeight do
  81.         turtle[direction]()
  82.        
  83.         if i % 2 == 1 and i ~= spawnerHeight then
  84.             if lampEnabled then
  85.                 turtle.forward()
  86.                 turtle.dig()
  87.                 turtle.select(row2slot(lampBlock))
  88.                 turtle.place()
  89.                 turtle.back()
  90.             end
  91.         end
  92.        
  93.         if wireEnabled then
  94.             turtle.select(row2slot(wireBlock))
  95.             turtle.place()
  96.         end
  97.     end
  98.    
  99. end
  100.  
  101. buildLevels = 17
  102.  
  103. print("How many levels to build? Default: ".. tostring(buildLevels))
  104. buildLevels = tonumber(io.read()) or buildLevels
  105. print("--> ".. tostring(buildLevels) .. " levels")
  106.  
  107. print("Direction? 'up' or 'down'. Default: 'up'")
  108. direction = io.read()
  109. if direction == "" then
  110.     direction = "up"
  111. end
  112.  
  113. -- move away from wall after placement
  114. for n = 1, buildLevels do
  115.     buildLevel()
  116. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement