handle AE again
This commit is contained in:
@@ -14,7 +14,10 @@ function ChestAdapter:init(args)
|
|||||||
|
|
||||||
local chest
|
local chest
|
||||||
if not self.side then
|
if not self.side then
|
||||||
chest = Peripheral.getByMethod('list')
|
chest = Peripheral.getByMethod('list') or Peripheral.getByMethod('listAvailableItems')
|
||||||
|
if not chest then
|
||||||
|
chest = Peripheral.getByMethod('list')
|
||||||
|
end
|
||||||
else
|
else
|
||||||
chest = Peripheral.getBySide(self.side)
|
chest = Peripheral.getBySide(self.side)
|
||||||
if chest and not chest.list then
|
if chest and not chest.list then
|
||||||
@@ -31,20 +34,33 @@ function ChestAdapter:isValid()
|
|||||||
return not not self.list
|
return not not self.list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- handle both AE/RS and generic inventory
|
||||||
|
function ChestAdapter:getItemDetails(index, item)
|
||||||
|
if self.getItemMeta then
|
||||||
|
local s, detail = pcall(self.getItemMeta, index)
|
||||||
|
if not s or not detail or detail.name ~= item.name then
|
||||||
|
-- debug({ s, detail })
|
||||||
|
return
|
||||||
|
end
|
||||||
|
return detail
|
||||||
|
else
|
||||||
|
local detail = self.findItem(item)
|
||||||
|
if detail then
|
||||||
|
return detail.getMetadata()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function ChestAdapter:getCachedItemDetails(item, k)
|
function ChestAdapter:getCachedItemDetails(item, k)
|
||||||
local cached = itemDB:get(item)
|
local cached = itemDB:get(item)
|
||||||
if cached then
|
if cached then
|
||||||
return cached
|
return cached
|
||||||
end
|
end
|
||||||
|
|
||||||
local s, detail = pcall(self.getItemMeta, k)
|
local detail = self:getItemDetails(k, item)
|
||||||
if not s or not detail or detail.name ~= item.name then
|
if detail then
|
||||||
-- debug({ s, detail })
|
return itemDB:add(detail)
|
||||||
-- error('Inventory has changed')
|
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return itemDB:add(detail)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ChestAdapter:refresh(throttle)
|
function ChestAdapter:refresh(throttle)
|
||||||
|
|||||||
Reference in New Issue
Block a user