Compare commits
5 Commits
49833b2270
...
logistics-
Author | SHA1 | Date | |
---|---|---|---|
73dab0efac | |||
c40bdb5a09 | |||
9606e545e4 | |||
523696db16 | |||
cb19161ddd |
@@ -3,7 +3,7 @@ local component = require("component")
|
||||
local driver = {}
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
---------------------------------- Item Class ----------------------------------
|
||||
------------------------------- ItemStack Class -------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local ItemStack = {}
|
||||
@@ -11,25 +11,58 @@ ItemStack.__index = ItemStack
|
||||
|
||||
local function ItemStack_new(item)
|
||||
checkArg(1, item, "table");
|
||||
local out = {
|
||||
local output = {
|
||||
data = item.getValue1(),
|
||||
quantity = item.getValue2()
|
||||
}
|
||||
setmetatable(out, ItemStack)
|
||||
return out
|
||||
setmetatable(output, ItemStack)
|
||||
return output
|
||||
end
|
||||
|
||||
function ItemStack:getName()
|
||||
--- check for custom name
|
||||
if self.data.hasTagCompount() then
|
||||
local nbt = self.data.getTagCompount()
|
||||
if nbt.value.display and nbt.value.display.value.Name then
|
||||
if self.data.hasTagCompound() then
|
||||
local nbt = self.data.getTagCompound()
|
||||
-- if Long arry is in the NBT complex logistic pipes fails to
|
||||
-- serialize the NBT resulting in a empty nbt
|
||||
if not nbt then
|
||||
return self.data.getName() .. " <NBT ERROR>"
|
||||
elseif nbt.value.display and nbt.value.display.value.Name then
|
||||
return nbt.value.display.value.Name.value
|
||||
end
|
||||
end
|
||||
return self.data.getName()
|
||||
end
|
||||
|
||||
function ItemStack:getId()
|
||||
if not self.data.hasTagCompound() then
|
||||
return self.data.getIdName() .. "." .. self.data.getData()
|
||||
end
|
||||
return "complex"
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
----------------------------- ItemCollection Class -----------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
local ItemCollection = {}
|
||||
ItemCollection.__index = ItemCollection
|
||||
|
||||
local function ItemCollection_new(items)
|
||||
checkArg(1, items, "table");
|
||||
local output = {}
|
||||
output.searchTable = {}
|
||||
for i,item in pairs(items) do
|
||||
local itemStack = ItemStack_new(item)
|
||||
output[i] = itemStack
|
||||
output.searchTable[itemStack:getName()] = i
|
||||
end
|
||||
setmetatable(output, ItemCollection);
|
||||
return output
|
||||
end
|
||||
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-------------------------------- Private Driver --------------------------------
|
||||
--------------------------------------------------------------------------------
|
||||
@@ -49,11 +82,7 @@ function driver.getItems()
|
||||
if not pipe.getAvailableItems and not pipe.makeRequest then
|
||||
error("Logistics pipe is not a a requesting pipe")
|
||||
end
|
||||
local output = {}
|
||||
for _,item in pairs(pipe.getAvailableItems()) do
|
||||
table.insert(output, ItemStack_new(item))
|
||||
end
|
||||
return output
|
||||
return ItemCollection_new(pipe.getAvailableItems())
|
||||
end
|
||||
|
||||
return driver
|
||||
|
Reference in New Issue
Block a user