Advertisement
VADemon

SpawnerBuildFloor

Nov 5th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 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. stoneBlock = 1
  11. dirtBlock = 2
  12.  
  13. spawnerHeight = 2
  14.  
  15. -- moves row to the first slow of the row
  16. -- at least keep Target supply in slot
  17. function moveSupplyRow(row, target)
  18.     if not target then target = 16 end
  19.    
  20.     local start = (row-1)*4+2
  21.     for i = start, (row)*4 do
  22.         -- exit if enough items
  23.         if turtle.getItemCount(start-1) >= target then break end
  24.        
  25.         turtle.select(i)
  26.         turtle.transferTo(start-1)
  27.     end
  28. end
  29.  
  30. function row2slot(row)
  31.     return (row-1)*4+1
  32. end
  33.  
  34. function buildLevel()
  35.     -- build complete row
  36.    
  37.     -- check if turtle is on the correct level
  38.     turtle.select(row2slot(stoneBlock))
  39.    
  40.     local ok, blockFront = turtle.inspect()
  41.     local blockSlot = turtle.getItemDetail(row2slot(stoneBlock))
  42.    
  43.     if ok and blockSlot then
  44.         if blockFront["name"] == blockSlot["name"] then
  45.             turtle.up() -- at dirt level
  46.            
  47.         elseif turtle.inspect() and select(2, turtle.inspect())["name"] == turtle.getItemDetail(row2slot(dirtBlock))["name"] then
  48.             -- dont move up, we are already on the correct level
  49.         else
  50.             error("The block in front of me is not DIRT! That doesn't seem right!")
  51.         end
  52.     else
  53.         error("I must be placed against Brick or Dirt Blocks! Also make sure to add building supplies")
  54.     end
  55.     -- END OF CHECK
  56.    
  57.     -- place stone
  58.     if stoneEnabled then
  59.         moveSupplyRow(stoneBlock)
  60.         turtle.select(row2slot(stoneBlock))
  61.         turtle.placeDown()
  62.     end
  63.    
  64.     if dirtEnabled then
  65.         moveSupplyRow(dirtBlock)
  66.     end
  67.    
  68.     while turtle.back() do
  69.         turtle.select(row2slot(dirtBlock))
  70.         turtle.place()
  71.        
  72.         turtle.select(row2slot(stoneBlock))
  73.         turtle.placeDown()
  74.     end
  75.    
  76.     turtle.up()
  77.     turtle.select(row2slot(dirtBlock))
  78.     turtle.placeDown()
  79.    
  80.     -- face against wall
  81.     turtle.turnRight(); turtle.turnRight()
  82.    
  83.     for i = 1, spawnerHeight do
  84.         if not turtle.up() then
  85.             error("Cannot move upwards!")
  86.         end
  87.     end
  88. end
  89.  
  90. buildLevels = 17
  91. stoneEnabled = true
  92. dirtEnabled = true
  93.  
  94. print("How many levels to build? Default: ".. tostring(buildLevels))
  95. buildLevels = tonumber(io.read()) or buildLevels
  96. print("--> ".. tostring(buildLevels) .. " levels")
  97.  
  98.  
  99. -- turn Around, it must be placed against a wall
  100. if not turtle.detect() then
  101.     turtle.turnRight(); turtle.turnRight()
  102. end
  103.  
  104. for n = 1, buildLevels do
  105.     buildLevel()
  106. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement