SHARE
TWEET

test.lua

a guest Dec 14th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local component = require("component")
  2. local sides = require("sides")
  3. local term = require("term")
  4. local os = require("os")
  5.  
  6. local old_stacks = {}
  7.  
  8. function display_chest_content(side)
  9.   local items = component.inventory_controller.getAllStacks(side)
  10.   if not items then
  11.     return false
  12.   end
  13.  
  14.   print("Listing inventory on side " .. side)
  15.  
  16.   local size = math.floor(component.inventory_controller.getInventorySize(side))
  17.  
  18.   local stacks = {}
  19.   for k, v in ipairs(items) do
  20.     if v.size > 1 then
  21.       stacks[#stacks + 1] = v
  22.     end
  23.   end
  24.  
  25.   print(#stacks .. "/" .. size .. " stacks in inventory")
  26.  
  27.   table.sort(stacks, function(a, b) return a.size > b.size end)
  28.  
  29.   for n, stack in ipairs(stacks) do
  30.     local diff = ""
  31.     if old_stacks[stack.label] then
  32.       diff = math.floor(stack.size - old_stacks[stack.label].size)
  33.       if diff > 0 then
  34.         diff = "+" .. tostring(diff)
  35.       elseif diff <= 0 then
  36.         diff = ""
  37.       end
  38.     end
  39.  
  40.     local mean = ""
  41.     if old_stacks[stack.label] then
  42.       old_stacks[stack.label] = {
  43.         size=stack.size,
  44.         total=(tonumber(diff) or 0) + old_stacks[stack.label].total,
  45.         count=1 + old_stacks[stack.label].count
  46.       }
  47.  
  48.       mean = old_stacks[stack.label].total / old_stacks[stack.label].count
  49.       if mean > 0 then
  50.         mean = "+" .. string.format("%2.1f", mean)
  51.       elseif mean <= 0 then
  52.         mean = ""
  53.       end
  54.     else
  55.       old_stacks[stack.label] = {
  56.         size=stack.size,
  57.         total=0,
  58.         count=0
  59.       }
  60.     end
  61.  
  62.     print(stack.label .. string.rep("\t", 3 - math.floor(#stack.label / 8)) .. "| " .. math.floor(stack.size) .. "\t| " .. diff .. "\t| " .. mean)
  63.   end
  64. end
  65.  
  66. local refresh = 0
  67. while true do
  68.   term.clear()
  69.   print("Refreshed " .. refresh .. " times")
  70.   for i = 0, 5 do
  71.     display_chest_content(i)
  72.   end
  73.   os.sleep(60)
  74.   refresh = refresh + 1
  75. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top