Advertisement
CelticCoder

buildTower

Jan 11th, 2024 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.05 KB | None | 0 0
  1. os.loadAPI("userInput.lua")
  2. os.loadAPI("buildSupport.lua")
  3. os.loadAPI("predictSupport.lua")
  4.  
  5. -- type dictates what part of the building is being made. type == 1 gets the cost of the floor and support pillars
  6. -- type == 2 gets the cost of the walls, and type 3 gets the ceiling
  7.  
  8. function blockCost(length, width, height, type)
  9.     if type == 1 then
  10.         return (width * length) + (height * 4)
  11.     end
  12.     if type == 2 then
  13.         return (2 * (height * (width - 2))) + (2 * (height * (length - 2)))
  14.     end
  15.     if type == 3 then
  16.         return (width * length)
  17.     end
  18. end
  19.  
  20. function returnDownCeiling(length, width, height, floors)
  21.     turtle.turnLeft()
  22.     width = width - 1
  23.     height = height + 1
  24.     for i = 1, width do
  25.         turtle.forward()
  26.     end
  27.     turtle.turnLeft()
  28.     for i = 1, length do
  29.         turtle.forward()
  30.     end
  31.     for i = 1, floors do
  32.         for j = 1, height do
  33.             turtle.down()
  34.         end
  35.     end
  36.     turtle.down()
  37.     turtle.turnLeft()
  38.     turtle.turnLeft()
  39. end
  40.  
  41. function returnDown(height, floors)
  42.     turtle.back()
  43.     height = height + 1
  44.     for i = 1, floors do
  45.         for j = 1, height do
  46.             turtle.down()
  47.         end
  48.     end
  49. end
  50.  
  51. function predictReturnDown(length, width, height, floors)
  52.     tcost = 0
  53.     width = width - 1
  54.     height = height + 1
  55.     for i = 1, width do
  56.         tcost = tcost + 1
  57.     end
  58.     for i = 1, length do
  59.         tcost = tcost + 1
  60.     end
  61.     for i = 1, floors do
  62.         for j = 1, height do
  63.             tcost = tcost + 1
  64.         end
  65.     end
  66.     tcost = tcost + 1
  67.     return tcost
  68. end
  69.  
  70. blockname = "minecraft:black_concrete"
  71. blockname2 = "minecraft:black_stained_glass_pane"
  72.  
  73. choice = -1
  74. choice2 = 2
  75. choice3 = -1
  76. bcost = 0
  77. bcost2 = 0
  78. fcost = 0
  79. floors = 0
  80. length = 0
  81. width = 0
  82. height = 0
  83.  
  84. preset = tonumber(userInput.getUserInput("Preset? (Yes = 0, No = 1) "))
  85. if preset == 0 then
  86.     length = 16
  87.     width = 16
  88.     height = 5
  89.     floors = 1
  90.     choice = 2
  91.     choice2 = 1
  92.     choice3 = 1
  93. end
  94.  
  95. while length == 0 do
  96.     length = tonumber(userInput.getUserInput("Length: "))
  97. end
  98. while width == 0 do
  99.     width = tonumber(userInput.getUserInput("Width: "))
  100. end
  101. while height == 0 do
  102.     height = tonumber(userInput.getUserInput("Height: "))
  103. end
  104.  
  105. while floors <= 0 do
  106.     floors = tonumber(userInput.getUserInput("How Many Floors to Make?"))
  107. end
  108.  
  109. while choice < 0 or choice > 2 do
  110.     print("How Many Block Variants to Use?")
  111.     choice = tonumber(userInput.getUserInput("Type 0 (for any available), 1, or 2"))
  112.     if choice == 1 then
  113.         while choice2 < 0 or choice2 > 1 do
  114.             print("Would you Like the Preset?")
  115.             choice2 = tonumber(userInput.getUserInput("Type 0 for Yes, 1 for No"))
  116.         end
  117.         if choice2 == 1 then
  118.             blockname = userInput.getUserInput("Please Input Block ID: ")
  119.         end
  120.     end
  121.     if choice == 2 then
  122.         while choice2 ~= 0 and choice2 ~= 1 do
  123.             print("Would you Like the Preset?")
  124.             choice2 = tonumber(userInput.getUserInput("Type 0 for Yes, 1 for No"))
  125.         end
  126.         if choice2 == 1 then
  127.             blockname = userInput.getUserInput("Please Input Block #1's ID: ")
  128.             blockname2 = userInput.getUserInput("Please Input Block #2's ID: ")
  129.         end
  130.     end
  131. end
  132.  
  133. while choice3 ~= 0 and choice3 ~= 1 do
  134.     print("Build Ceiling?")
  135.     choice3 = tonumber(userInput.getUserInput("Type 0 for Yes, 1 for No"))
  136. end
  137.  
  138. for i = 1, floors do
  139.     bcost = bcost + blockCost(length, width, height, 1)
  140.     if choice == 2 then
  141.         bcost2 = bcost2 + blockCost(length, width, height, 2)
  142.     else
  143.         bcost = bcost + blockCost(length, width, height, 2)
  144.     end
  145.     predictSupport.predictFullBuild(length, width, height)
  146. end
  147. if choice3 == 0 then
  148.     bcost = bcost + blockCost(length, width, height, 3)
  149.     predictSupport.predictFloor(length, width)
  150. end
  151. fcost = fcost + predictSupport.getCost()
  152.  
  153. if not preset then
  154.     choice2 = 3
  155. end
  156. while choice2 ~= 0 and choice2 ~= 1 do
  157.     print("Return Drone to Start After Build?")
  158.     choice2 = tonumber(userInput.getUserInput("Type 0 for Yes, 1 for No"))
  159. end
  160.  
  161. if choice2 == 0 then
  162.     fcost = fcost + predictReturnDown(length, width, height, floors)
  163. end
  164.  
  165. while turtle.getFuelLevel() < fcost do
  166.     print("Turtle Fuel Level Too Low for Build!")
  167.     print("Fuel Needed" .. fcost)
  168.     print("Current Fuel" .. turtle.getFuelLevel())
  169.     print("Please Input Fuel")
  170.     userInput.getUserInput("Press Enter to Continue")
  171.     os.loadAPI("turtleRefuel.lua")
  172. end
  173.  
  174. print("The Following Blocks are Needed:")
  175.  
  176. print( bcost .. " " .. blockname)
  177. if bcost2 ~= 0 then
  178.     print( bcost2 .. " " .. blockname2)
  179. end
  180. userInput.getUserInput("Press Enter to Continue")
  181.  
  182. for j = 1, floors do
  183.     print(choice)
  184.     if choice == 0 then
  185.         print("False 1")
  186.         buildSupport.fullBuild(length, width, height)
  187.     elseif choice == 1 and blockname ~= nil then
  188.         print("False 2")
  189.         buildSupport.fullBuildBlock(length, width, height, blockname)
  190.     elseif choice == 2 and blockname ~= nil and blockname2 ~= nil then
  191.         print("true")
  192.         buildSupport.fullBuildBlocks(length, width, height, blockname, blockname2)
  193.     end
  194. end
  195. if choice3 == 0 then
  196.     turtle.up()
  197.     if choice == 0 then
  198.         buildSupport.buildFloor(width, length)
  199.     else
  200.         buildSupport.buildFloorBlock(width, length, blockname)
  201.     end
  202.  
  203.     if choice2 == 0 then
  204.         returnDownCeiling(length, width, height, floors)
  205.     end
  206. end
  207.  
  208. if choice2 == 0 and choice3 ~= 0 then
  209.     returnDown(height, floors)
  210. end
  211.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement