Removes Milo trying to access damage on items (`nil` because of The Flattening). We might also need to reimplement showing durability in the item's display name - I got a little too carried away with removing mentions of "damage". Also renames nbtHash to nbt to be consistent with new CC:T naming. I tried not to touch anything related to MiloRemote for now, and there are probably still many bugs remaining that need to be ironed out. Most of the basic functionality works now, though.
44 lines
932 B
Lua
44 lines
932 B
Lua
local class = require('opus.class')
|
|
local itemDB = require('core.itemDB')
|
|
local Util = require('opus.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.nbt }, ':')
|
|
|
|
local entry = cache[key]
|
|
if entry then
|
|
entry.count = entry.count + v.count
|
|
else
|
|
cache[key] = itemDB:get(v, function() return self.getItemDetail(k) end)
|
|
end
|
|
throttle()
|
|
end
|
|
end
|
|
|
|
-- TODO: cache number of slots, free slots, used slots
|
|
-- useful for when inserting into chests
|
|
-- ie. insert only if chest does not have item and has free slots
|
|
|
|
self.cache = cache
|
|
end
|
|
|
|
return Adapter
|