Alexr360

Fill Level

Feb 19th, 2024 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. -- Function to count the total number of items in the chest
  2. local function countItems(chest)
  3.     local itemCount = 0
  4.     for _, item in ipairs(chest.list()) do
  5.         itemCount = itemCount + item.count
  6.     end
  7.     return itemCount
  8. end
  9.  
  10. -- Function to calculate the percentage of slots filled
  11. local function calculateFillPercentage(chest)
  12.     local totalSlots = chest.size()
  13.     local filledSlots = countItems(chest)
  14.     return (filledSlots / totalSlots) * 100
  15. end
  16.  
  17. -- Main function
  18. local function main()
  19.     local chest = peripheral.find("adpother:diamond_filter_frame")
  20.     if chest then
  21.         local fillPercentage = calculateFillPercentage(chest)
  22.         print(string.format("Chest fill level: %.2f%%", fillPercentage))
  23.     else
  24.         print("No chest detected.")
  25.     end
  26. end
  27.  
  28. -- Call the main function
  29. main()
  30.  
Add Comment
Please, Sign In to add comment