Files
opus-apps/milo/apis/miniAdapter.lua
kepler155c@gmail.com 04815b2d09 require rework round 3
2019-01-26 22:58:21 -05:00

40 lines
814 B
Lua

local class = require('class')
local itemDB = require('core.itemDB')
local Util = require('util')
local device = _G.device
local Adapter = class()
function Adapter:init(args)
if args.side then
local inventory = device[args.side]
if inventory then
Util.merge(self, inventory)
end
end
end
function Adapter:listItems(throttle)
local cache = { }
throttle = throttle or Util.throttle()
for k,v in pairs(self.list()) do
if v.count > 0 then
local key = table.concat({ v.name, v.damage, v.nbtHash }, ':')
local entry = cache[key]
if entry then
entry.count = entry.count + v.count
else
cache[key] = itemDB:get(v, function() return self.getItemMeta(k) end)
end
throttle()
end
end
self.cache = cache
end
return Adapter