NekoLogi

builder.lua

Jan 31st, 2022 (edited)
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.10 KB | None | 0 0
  1. Stack = 0
  2. ItemIndex = 2
  3.  
  4. function TurnBackFloor(length)
  5.     print("Turning back...")
  6.     turtle.turnLeft()
  7.     turtle.turnLeft()
  8.     for i=1,length - 1 do
  9.         while not turtle.forward() do
  10.             turtle.dig()
  11.         end
  12.     end
  13. end
  14.  
  15. function TurnBackRoof(length)
  16.     print("Turning back...")
  17.     turtle.turnLeft()
  18.     turtle.turnLeft()
  19.     for i=1,length - 1 do
  20.         while not turtle.forward() do
  21.             turtle.dig()
  22.         end
  23. end
  24. end
  25.  
  26. function ReturnToStart(width,height)
  27.     print("Returning to start position...")
  28.     turtle.turnLeft()
  29.     turtle.turnLeft()
  30.     for i=1,width - 1 do
  31.         while not turtle.forward() do
  32.             turtle.dig()
  33.         end
  34.     end
  35.     turtle.turnLeft()
  36.     for i=1,height - 1 do
  37.         turtle.down()
  38.     end
  39. end
  40.  
  41. function ReturnToStartRoof(width,height)
  42.     print("Returning to start position...")
  43.     turtle.turnLeft()
  44.     for i=1,width - 1 do
  45.         while not turtle.forward() do
  46.             turtle.dig()
  47.         end
  48.     end
  49.     turtle.turnLeft()
  50.     for i=1,height - 1 do
  51.         turtle.down()
  52.     end
  53. end
  54.  
  55.  
  56. function MakeLine(length)
  57.     print("Building floor...")
  58.     for i=1,length do
  59.         if Stack == 64 then
  60.             ItemIndex = ItemIndex + 1
  61.             turtle.select(ItemIndex)
  62.             Stack = 0
  63.         end            
  64.         while not turtle.placeDown() do
  65.             turtle.digDown()
  66.         end
  67.         Stack = Stack + 1
  68.         if i ~= length then
  69.             while not turtle.forward() do
  70.                 turtle.dig()
  71.             end
  72.         end
  73.     end
  74. end
  75.  
  76. function NextLine()
  77.     print("Preparing for next line...")
  78.     turtle.turnRight()
  79.     while not turtle.forward() do
  80.         turtle.dig()
  81.     end
  82.     turtle.turnRight()
  83. end
  84.  
  85. function MakeFloor(width,length)
  86.     print("Building floor...")
  87.     for i=1,width do
  88.         MakeLine(length)
  89.         TurnBackFloor(length)
  90.         if i ~= width then
  91.             NextLine()
  92.         else
  93.             turtle.turnRight()
  94.         end
  95.     end
  96. end
  97.  
  98. function WallUp(height)
  99.     print("Building wall...")
  100.     for i=1,height do
  101.         if Stack == 64 then
  102.             ItemIndex = ItemIndex + 1
  103.             turtle.select(ItemIndex)
  104.             Stack = 0
  105.         end            
  106.         while not turtle.place() do
  107.             turtle.dig()
  108.         end
  109.         Stack = Stack + 1
  110.  
  111.         turtle.place()
  112.         if i ~= height then
  113.             while not turtle.up() do
  114.                 turtle.digUp()
  115.             end
  116.         end
  117.     end
  118.     for i=1,height - 1 do
  119.         while not turtle.down() do
  120.             turtle.digDown()
  121.         end
  122.     end
  123. end
  124.  
  125. function MakeLengthWall(length,height)
  126.     print("Starting to build wall...")
  127.    for i=1,length do
  128.         WallUp(height)
  129.         turtle.turnRight()
  130.         if i ~= length then
  131.             while not turtle.forward() do
  132.                 turtle.dig()
  133.             end
  134.             turtle.turnLeft()
  135.         end
  136.    end
  137. end
  138.  
  139. function MakeWidthWall(width,height)
  140.     print("Starting to build wall...")
  141.     for i=1,width do
  142.         WallUp(height)
  143.         turtle.turnRight()
  144.         if i ~= width then
  145.             while not turtle.forward() do
  146.                 turtle.dig()
  147.             end
  148.             turtle.turnLeft()
  149.         end
  150.     end
  151. end
  152.  
  153. function PrepareRoof(height)
  154.     print("Positioning to build roof...")
  155.     for i=1,height - 1 do
  156.         while not turtle.up() do
  157.             turtle.digUp()
  158.         end
  159.     end
  160. end
  161.  
  162. function MakeRoof(length,width)
  163.     print("Building roof...")
  164.     for i=1,width do
  165.         for e=1,length do
  166.             if Stack == 64 then
  167.                 ItemIndex = ItemIndex + 1
  168.                 turtle.select(ItemIndex)
  169.                 Stack = 0
  170.             end
  171.             if turtle.placeUp() then
  172.                 Stack = Stack + 1
  173.             end
  174.             if e ~= length then
  175.                 while not turtle.forward() do
  176.                     turtle.dig()
  177.                 end
  178.             end
  179.         end
  180.         TurnBackRoof(length)
  181.         if i ~= width then
  182.             NextLine()
  183.         end
  184.     end
  185. end
  186.  
  187. function CheckBuildLimit(length,width,height)
  188.     print("Calculating required item amount...")
  189.     if (length * width) > 64*15 then
  190.         if ((length * height) * 2) + ((width * height) * 2) > 64*15 then
  191.             if (length * width) > 64*15 then
  192.                 return true
  193.             end
  194.         end
  195.     end
  196.     return false
  197. end
  198.  
  199. function ResetPosition(width,height)
  200.     print("Moving back to starting position...")
  201.     turtle.turnLeft()
  202.     for i=1,width - 1 do
  203.         while not turtle.forward() do
  204.             turtle.dig()
  205.         end
  206.     end
  207.     for i=1,height do
  208.         while not turtle.down() do
  209.             turtle.digDown()
  210.         end
  211.     end
  212.     turtle.turnLeft()
  213. end
  214.  
  215. function RequestInput()
  216.     io.write("Enter length of room:")
  217.     local length = io.read()
  218.     io.write("Enter width of room:")
  219.     local width = io.read()
  220.     io.write("Enter height of room:")
  221.     local height = io.read()
  222.  
  223.     local room = {tonumber(length),tonumber(width),tonumber(height)}
  224.  
  225.     return room
  226. end
  227.  
  228. function Done()
  229.     print("Finished building room!")
  230.     print("Fuel remaining:")
  231.     print(turtle.getFuelLevel())
  232. end
  233.  
  234. function RequestResource()
  235.     io.write("Refill resources - ")
  236.     io.write("press enter when finished..")
  237.     _ = io.read()
  238. end
  239.  
  240. function Start()
  241.     local room = RequestInput()
  242.     if (CheckBuildLimit(room[1], room[2], room[3])) then
  243.         print("Area is too big!")
  244.         return
  245.     end
  246.     Stack = 0
  247.     ItemIndex = 2
  248.     turtle.select(ItemIndex)
  249.     MakeFloor(room[2],room[1])
  250.  
  251.     RequestResource()
  252.     Stack = 0
  253.     ItemIndex = 2
  254.     turtle.select(ItemIndex)
  255.     MakeLengthWall(room[1],room[3])
  256.     MakeWidthWall(room[2],room[3])
  257.     MakeLengthWall(room[1],room[3])
  258.     MakeWidthWall(room[2],room[3])
  259.     ReturnToStart(room[2],room[3])
  260.  
  261.     RequestResource()
  262.     Stack = 0
  263.     ItemIndex = 2
  264.     turtle.select(ItemIndex)
  265.     PrepareRoof(room[3])
  266.     MakeRoof(room[1],room[2])
  267.     ReturnToStartRoof(room[2],room[3])
  268.     Done()
  269. end
  270.  
  271. Start()
Add Comment
Please, Sign In to add comment