Advertisement
VADemon

SpawnerBuildRedwire

Nov 5th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.87 KB | None | 0 0
  1. -- Usage: place at Stone brick level, turtle facing against the wall (it will turn itself anyway)
  2. -- Supply with stone Blocks,
  3. -- Supply with dirt Blocks (cursed earth)
  4.  
  5. -- it will build a whole floor row for a level (inside pre-built walls! https://pastebin.com/vBszs7pe )
  6.  
  7.  
  8. -- ItemSupply:
  9. -- rows, starting with 1
  10. wireBlock = 1   -- need 76+ per level (PLUS spawnerHeight)
  11. chestSlot = 16  -- ender chest: slot or 0 to disable
  12.  
  13.  
  14. spawnerHeight = (2) * 2 -- height between Fan levels
  15.  
  16. direction = "up"
  17.  
  18. -- moves row to the first slow of the row
  19. -- at least keep Target supply in slot
  20. function moveSupplyRow(row, target)
  21.     if not target then target = 16 end
  22.    
  23.     local start = (row-1)*4+2
  24.     for i = start, 16 do
  25.         if i ~= chestSlot then
  26.             -- exit if enough items
  27.             if turtle.getItemCount(start-1) >= target then break end
  28.            
  29.             turtle.select(i)
  30.             turtle.transferTo(start-1)
  31.         end
  32.     end
  33.    
  34.     if chestSlot ~= 0 and turtle.getItemCount(start-1) < target then
  35.         -- not enough items, fill from ender chest
  36.         local direction
  37.         local dirs = {"", "Up", "Down"}
  38.        
  39.         turtle.select(chestSlot)
  40.         for d = 1, #dirs do
  41.             direction = dirs[d]
  42.            
  43.             if turtle["place" .. direction]() then
  44.                 break
  45.             end
  46.            
  47.             if d == 3 then
  48.                 error("Couldnt refill from chest")
  49.             end
  50.         end
  51.        
  52.         for i = 1, 15 do
  53.             turtle["suck" .. direction]()
  54.             os.sleep(0.2)
  55.         end
  56.         -- free enderchest slot
  57.         turtle.select(chestSlot)
  58.         turtle["drop" .. direction]()
  59.         turtle["dig" .. direction]()
  60.     end
  61.    
  62.     turtle.select(row2slot(row))
  63. end
  64.  
  65. function row2slot(row)
  66.     return (row-1)*4+1
  67. end
  68.  
  69. function buildRow(n)
  70.     for i = 1, n do
  71.         turtle.place()
  72.         turtle.turnRight()
  73.         turtle.forward()
  74.         turtle.turnLeft()
  75.     end
  76. end
  77.  
  78. function buildCorner(n)
  79.     for i = 1, n do
  80.         -- Corner 1 Front
  81.         turtle.place()
  82.         -- Corner 1 Left
  83.         turtle.turnRight()
  84.         turtle.forward()
  85.         turtle.turnLeft()
  86.         turtle.forward()
  87.         turtle.turnLeft()
  88.         turtle.place()
  89.         --
  90.         turtle.turnRight()
  91.     end
  92. end
  93.  
  94. function buildLevel()
  95.     -- build complete row
  96.     for i = 1, 4 do
  97.         moveSupplyRow(wireBlock, target)
  98.         -- build first side half
  99.         buildRow(7)
  100.        
  101.         turtle.forward()
  102.        
  103.         buildCorner(6)
  104.        
  105.         turtle.forward()
  106.         turtle.turnLeft()
  107.         turtle.back()
  108.     end
  109.    
  110.     -- turtle can't move to start position because of cable block
  111.     turtle.turnRight()
  112.     turtle.forward()
  113.     turtle.turnLeft()
  114.     turtle.forward()
  115.    
  116.     for i = 1, spawnerHeight do
  117.         turtle[direction]()
  118.     end
  119. end
  120.  
  121. buildLevels = 17
  122. stoneEnabled = true
  123. dirtEnabled = true
  124.  
  125. print("How many levels to build? Default: ".. tostring(buildLevels))
  126. buildLevels = tonumber(io.read()) or buildLevels
  127. print("--> ".. tostring(buildLevels) .. " levels")
  128.  
  129. print("Direction? 'up' or 'down'. Default: 'up'")
  130. direction = io.read()
  131. if direction == "" then
  132.     direction = "up"
  133. end
  134.  
  135. -- move away from wall after placement
  136. turtle.back()
  137. for n = 1, buildLevels do
  138.     buildLevel()
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement