Advertisement
pickar

Builder

Nov 12th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 0 0
  1. local lenth = 4         -- lenth
  2. local width = 5         -- width
  3. local height = 2        -- height of walls
  4. local floors = 1        -- how many floors+walls to build
  5. local walls = true      -- do you need walls or just floor
  6. local ceiling = true    -- do you need to build roof
  7. -------------------------------------------------------
  8. local t = turtle
  9. local currentSlot = 1
  10.  
  11. t.placeDownOld = t.placeDown
  12.  
  13. lenth = lenth - 2
  14. width = width - 2
  15.  
  16. function t.placeDown()
  17.     CheckSlot()
  18.     t.placeDownOld()
  19. end
  20.  
  21. function CalcBlocks()
  22.     local blocks = 0
  23.  
  24.     local w = width+2
  25.     local l = lenth+2
  26.  
  27.     blocks = blocks + w*l*floors
  28.     blocks = blocks + (walls and (w+l-2)*2*floors*height or 0)
  29.     blocks = blocks + (ceiling and w*l or 0)
  30.  
  31.     return blocks
  32. end
  33.  
  34. function CheckSlot()
  35.     if t.getItemCount(currentSlot) == 0 then
  36.         if currentSlot == 16 then
  37.             print("WAITING FOR BLOCKS")
  38.             currentSlot = 1
  39.             t.select(1)
  40.             while t.getItemCount() == 0 do
  41.                 sleep(1)
  42.             end
  43.         else
  44.             currentSlot = currentSlot + 1
  45.             t.select(currentSlot)
  46.             CheckSlot()
  47.         end
  48.     end
  49. end
  50.  
  51. function BuildFloor()
  52.     local side = 0
  53.  
  54.     t.up()
  55.  
  56.     if not(walls) then
  57.         width = width - 2
  58.         lenth = lenth - 2
  59.     end
  60.  
  61.     for i = 1, width+2 do
  62.         for i = 1, lenth+1 do
  63.             t.placeDown()
  64.             t.forward()
  65.         end
  66.         t.placeDown()
  67.  
  68.         if i ~= width+2 then
  69.             if side == 0 then
  70.                 t.turnRight()
  71.                 t.forward()
  72.                 t.turnRight()
  73.             elseif side == 1 then
  74.                 t.turnLeft()
  75.                 t.forward()
  76.                 t.turnLeft()
  77.             end
  78.             side = 1 - side
  79.         end
  80.     end
  81. end
  82.  
  83. function BuildWalls()
  84.     if width%2 == 0 then
  85.         t.turnLeft()
  86.         t.turnLeft()
  87.         for i = 1, lenth+1 do
  88.             t.forward()
  89.         end
  90.     end
  91.     t.turnLeft()
  92.     t.forward()
  93.  
  94.     for i = 1, height do
  95.         t.up()
  96.         for i = 1, 2 do
  97.             for i = 1, width do
  98.                 t.placeDown()
  99.                 t.forward()
  100.             end
  101.             t.placeDown()
  102.             t.turnLeft()
  103.             t.forward()
  104.             for i = 1, lenth do
  105.                 t.placeDown()
  106.                 t.forward()
  107.             end
  108.             t.placeDown()
  109.             t.turnLeft()
  110.             t.forward()
  111.         end
  112.     end
  113.  
  114.     for i = 1, width do
  115.         t.forward()
  116.     end
  117.     t.turnLeft()
  118.     for i = 1, lenth+1 do
  119.         t.forward()
  120.     end
  121.     t.turnLeft()
  122.     t.turnLeft()
  123. end
  124.  
  125. if t ~= nil then
  126.     term.clear()
  127.     term.setCursorPos(1, 1)
  128.  
  129.     print("PICKAR'S BUILDER v1.0")
  130.     print("YOU WILL NEED "..CalcBlocks().." BLOCKS")
  131.     print("ITS ".. (CalcBlocks()-CalcBlocks()%64)/64 .." STACK AND ".. CalcBlocks()%64 .." BLOCKS")
  132.     if walls then
  133.         if floors == 1 then
  134.             BuildFloor()
  135.             BuildWalls()
  136.         else
  137.             for i = 1, floors do
  138.                 BuildFloor()
  139.                 BuildWalls()
  140.             end
  141.         end
  142.         if ceiling then
  143.             BuildFloor()
  144.             BuildFloor()
  145.         end
  146.     else
  147.         BuildFloor()
  148.     end
  149. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement