1
0
mirror of https://github.com/kepler155c/opus synced 2024-07-04 11:03:21 +00:00
opus/sys/apis/refinedProvider.lua

127 lines
2.7 KiB
Lua
Raw Normal View History

2017-04-15 15:38:08 +00:00
local class = require('class')
local Peripheral = require('peripheral')
local RefinedProvider = class()
function RefinedProvider:init(args)
local defaults = {
cache = { },
items = { },
name = 'refinedStorage',
}
Util.merge(self, defaults)
Util.merge(self, args)
2017-04-17 07:13:00 +00:00
local controller = Peripheral.getByType('refinedstorage:controller')
if controller then
Util.merge(self, controller)
end
2017-04-15 15:38:08 +00:00
end
function RefinedProvider:isValid()
2017-04-17 07:13:00 +00:00
return not not self.listAvailableItems
end
function RefinedProvider:isOnline()
return self.getNetworkEnergyStored() > 0
2017-04-15 15:38:08 +00:00
end
function RefinedProvider:getCachedItemDetails(item)
local key = table.concat({ item.name, item.damage, item.nbtHash }, ':')
local detail = self.cache[key]
if not detail then
2017-04-17 07:13:00 +00:00
detail = self.findItem(item)
2017-04-15 15:38:08 +00:00
if detail then
Util.merge(detail, detail.getMetadata())
if detail.displayName then
if detail.maxDamage and detail.maxDamage > 0 and detail.damage > 0 then
detail.displayName = detail.displayName .. ' (damaged)'
end
detail.lname = detail.displayName:lower()
-- backwards capability
detail.dmg = detail.damage
detail.id = detail.name
detail.qty = detail.count
detail.display_name = detail.displayName
self.cache[key] = detail
end
end
end
return detail
end
function RefinedProvider:listItems()
local items = { }
local list
pcall(function()
2017-04-17 07:13:00 +00:00
list = self.listAvailableItems()
2017-04-15 15:38:08 +00:00
end)
if list then
for _,v in pairs(list) do
local item = self:getCachedItemDetails(v)
if item then
item.count = v.count
item.qty = v.count
table.insert(items, item)
end
end
end
return items
end
function RefinedProvider:getItemInfo(fingerprint)
local key = table.concat({ fingerprint.name, fingerprint.damage, fingerprint.nbtHash }, ':')
local item = self.cache[key]
if not item then
return self:getCachedItemDetails(fingerprint)
end
2017-04-17 07:13:00 +00:00
local detail = self.findItem(item)
2017-04-15 15:38:08 +00:00
if detail then
item.count = detail.count
item.qty = detail.count
return item
end
end
2017-04-17 07:13:00 +00:00
function RefinedProvider:isCrafting(item)
for _,task in pairs(self.getCraftingTasks()) do
if task.name == item.name and
task.damage == item.damage and
task.nbtHash == item.nbtHash then
return true
end
end
return false
end
2017-04-15 15:38:08 +00:00
function RefinedProvider:craft(id, dmg, qty)
return false
end
function RefinedProvider:craftItems(items)
return false
end
function RefinedProvider:provide(item, qty, slot)
end
function RefinedProvider:extract(slot, qty)
2017-04-17 07:13:00 +00:00
-- self.pushItems(self.direction, slot, qty)
2017-04-15 15:38:08 +00:00
end
function RefinedProvider:insert(slot, qty)
2017-04-17 07:13:00 +00:00
-- self.pullItems(self.direction, slot, qty)
2017-04-15 15:38:08 +00:00
end
return RefinedProvider