CelticCoder

SmartBuildTower

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