Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local sides = require("sides")
- local term = require("term")
- local os = require("os")
- local old_stacks = {}
- function display_chest_content(side)
- local items = component.inventory_controller.getAllStacks(side)
- if not items then
- return false
- end
- print("Listing inventory on side " .. side)
- local size = math.floor(component.inventory_controller.getInventorySize(side))
- local stacks = {}
- for k, v in ipairs(items) do
- if v.size > 1 then
- stacks[#stacks + 1] = v
- end
- end
- print(#stacks .. "/" .. size .. " stacks in inventory")
- table.sort(stacks, function(a, b) return a.size > b.size end)
- for n, stack in ipairs(stacks) do
- local diff = ""
- if old_stacks[stack.label] then
- diff = math.floor(stack.size - old_stacks[stack.label].size)
- if diff > 0 then
- diff = "+" .. tostring(diff)
- elseif diff <= 0 then
- diff = ""
- end
- end
- local mean = ""
- if old_stacks[stack.label] then
- old_stacks[stack.label] = {
- size=stack.size,
- total=(tonumber(diff) or 0) + old_stacks[stack.label].total,
- count=1 + old_stacks[stack.label].count
- }
- mean = old_stacks[stack.label].total / old_stacks[stack.label].count
- if mean > 0 then
- mean = "+" .. string.format("%2.1f", mean)
- elseif mean <= 0 then
- mean = ""
- end
- else
- old_stacks[stack.label] = {
- size=stack.size,
- total=0,
- count=0
- }
- end
- print(stack.label .. string.rep("\t", 3 - math.floor(#stack.label / 8)) .. "| " .. math.floor(stack.size) .. "\t| " .. diff .. "\t| " .. mean)
- end
- end
- local refresh = 0
- while true do
- term.clear()
- print("Refreshed " .. refresh .. " times")
- for i = 0, 5 do
- display_chest_content(i)
- end
- os.sleep(60)
- refresh = refresh + 1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement