Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to count the total number of items in the chest
- local function countItems(chest)
- local itemCount = 0
- for _, item in ipairs(chest.list()) do
- itemCount = itemCount + item.count
- end
- return itemCount
- end
- -- Function to calculate the percentage of slots filled
- local function calculateFillPercentage(chest)
- local totalSlots = chest.size()
- local filledSlots = countItems(chest)
- return (filledSlots / totalSlots) * 100
- end
- -- Main function
- local function main()
- local chest = peripheral.find("adpother:diamond_filter_frame")
- if chest then
- local fillPercentage = calculateFillPercentage(chest)
- print(string.format("Chest fill level: %.2f%%", fillPercentage))
- else
- print("No chest detected.")
- end
- end
- -- Call the main function
- main()
Add Comment
Please, Sign In to add comment