CelticCoder

SmartBuildTower

Aug 11th, 2024 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. -- CONCRETE ON LEFT, GLASS ON RIGHT
  8.  
  9. function blockCost(length, width, height, type)
  10.     if type == 1 then
  11.         return (width * length) + (height * 4)
  12.     end
  13.     if type == 2 then
  14.         return (2 * (height * (width - 2))) + (2 * (height * (length - 2)))
  15.     end
  16.     if type == 3 then
  17.         return (width * length)
  18.     end
  19. end
  20.  
  21. function countItemInInventory(itemName)
  22.     local totalCount = 0
  23.    
  24.     -- Iterate over all slots in the turtle's inventory
  25.     for slot = 1, 16 do
  26.         local itemDetail = turtle.getItemDetail(slot)
  27.        
  28.         -- If there's an item in the slot and it matches the specified item name, add to the total count
  29.         if itemDetail and itemDetail.name == itemName then
  30.             totalCount = totalCount + itemDetail.count
  31.         end
  32.     end
  33.    
  34.     return totalCount
  35. end
  36.  
  37. function returnDown(height, floors, blockname, blockname2)
  38.     turtle.back()
  39.     height = height + 1
  40.     for i = 1, floors do
  41.         for j = 1, height do
  42.             turtle.down()
  43.         end
  44.     end
  45.  
  46.     turtle.turnLeft()
  47.     concretecount = countItemInInventory(blockname)
  48.     concreteneeded = 276 - concretecount
  49.     concretemod = concreteneeded % 64
  50.    
  51.     for i = 1, math.floor(concreteneeded/64) do
  52.         turtle.suck(64)
  53.     end
  54.     turtle.suck(concretemod)
  55.     if countItemInInventory(blockname) < 276 then
  56.         print("OUT OF CONCRETE")
  57.         os.exit(1)
  58.     end
  59.  
  60.     turtle.turnLeft()
  61.     turtle.turnLeft()
  62.     glasscount = countItemInInventory(blockname2)
  63.     glassneeded = 280 - glasscount
  64.     glassmod = glassneeded % 64
  65.  
  66.     for i = 1, math.floor(glassneeded/64) do
  67.         turtle.suck(64)
  68.     end
  69.     turtle.suck(glassmod)
  70.     if countItemInInventory(blockname2) < 280 then
  71.         print("OUT OF GLASS")
  72.         os.exit(1)
  73.     end
  74.  
  75.     turtle.turnLeft()
  76.     for i = 1, floors do
  77.         for j = 1, height do
  78.             turtle.up()
  79.         end
  80.     end
  81.     turtle.forward()
  82. end
  83.  
  84. function predictReturnDown(length, width, height, floors)
  85.     tcost = 0
  86.     width = width - 1
  87.     height = height + 1
  88.     for i = 1, width do
  89.         tcost = tcost + 1
  90.     end
  91.     for i = 1, length do
  92.         tcost = tcost + 1
  93.     end
  94.     for i = 1, floors do
  95.         for j = 1, height do
  96.             tcost = tcost + 1
  97.         end
  98.     end
  99.     tcost = tcost + 1
  100.     return tcost
  101. end
  102.  
  103. blockname = "minecraft:black_concrete"
  104. blockname2 = "minecraft:black_stained_glass_pane"
  105.  
  106. choice = 2
  107. choice2 = 1
  108. choice3 = 1
  109. bcost = 0
  110. bcost2 = 0
  111. fcost = 0
  112. floors = 1
  113. length = 16
  114. width = 16
  115. height = 5
  116.  
  117. floors = tonumber(userInput.getUserInput("How Many Floors to Make?"))
  118.  
  119. for i = 1, floors do
  120.     bcost = bcost + blockCost(length, width, height, 1)
  121.     if choice == 2 then
  122.         bcost2 = bcost2 + blockCost(length, width, height, 2)
  123.     else
  124.         bcost = bcost + blockCost(length, width, height, 2)
  125.     end
  126.     predictSupport.predictFullBuild(length, width, height)
  127. end
  128. if choice3 == 0 then
  129.     bcost = bcost + blockCost(length, width, height, 3)
  130.     predictSupport.predictFloor(length, width)
  131. end
  132. fcost = fcost + predictSupport.getCost()
  133.  
  134. while choice2 ~= 0 and choice2 ~= 1 do
  135.     print("Return Drone to Start After Build?")
  136.     choice2 = tonumber(userInput.getUserInput("Type 0 for Yes, 1 for No"))
  137. end
  138.  
  139. if choice2 == 0 then
  140.     fcost = fcost + predictReturnDown(length, width, height, floors)
  141. end
  142.  
  143. while turtle.getFuelLevel() < fcost do
  144.     print("Turtle Fuel Level Too Low for Build!")
  145.     print("Fuel Needed" .. fcost)
  146.     print("Current Fuel" .. turtle.getFuelLevel())
  147.     print("Please Input Fuel")
  148.     userInput.getUserInput("Press Enter to Continue")
  149.     os.loadAPI("turtleRefuel.lua")
  150. end
  151.  
  152. for j = 1, floors do
  153.     print(choice)
  154.     if choice == 0 then
  155.         print("False 1")
  156.         buildSupport.fullBuild(length, width, height)
  157.     elseif choice == 1 and blockname ~= nil then
  158.         print("False 2")
  159.         buildSupport.fullBuildBlock(length, width, height, blockname)
  160.     elseif choice == 2 and blockname ~= nil and blockname2 ~= nil then
  161.         print("true")
  162.         buildSupport.fullBuildBlocks(length, width, height, blockname, blockname2)
  163.     end
  164.     returnDown(height, j, blockname, blockname2)
  165. end
  166. returnDown(height, floors)
  167.  
  168.  
Add Comment
Please, Sign In to add comment