Compare commits

..

5 Commits

Author SHA1 Message Date
73dab0efac Add getId function 2023-03-26 15:18:38 -05:00
c40bdb5a09 Att items to correct output table 2023-03-21 14:49:07 -05:00
9606e545e4 Correct typo 2023-03-21 14:47:17 -05:00
523696db16 Change to use ItemCollection 2023-03-21 14:45:43 -05:00
cb19161ddd Correct typo 2023-03-21 13:37:05 -05:00

View File

@@ -3,7 +3,7 @@ local component = require("component")
local driver = {} local driver = {}
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
---------------------------------- Item Class ---------------------------------- ------------------------------- ItemStack Class -------------------------------
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local ItemStack = {} local ItemStack = {}
@@ -11,25 +11,58 @@ ItemStack.__index = ItemStack
local function ItemStack_new(item) local function ItemStack_new(item)
checkArg(1, item, "table"); checkArg(1, item, "table");
local out = { local output = {
data = item.getValue1(), data = item.getValue1(),
quantity = item.getValue2() quantity = item.getValue2()
} }
setmetatable(out, ItemStack) setmetatable(output, ItemStack)
return out return output
end end
function ItemStack:getName() function ItemStack:getName()
--- check for custom name --- check for custom name
if self.data.hasTagCompount() then if self.data.hasTagCompound() then
local nbt = self.data.getTagCompount() local nbt = self.data.getTagCompound()
if nbt.value.display and nbt.value.display.value.Name then -- 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 return nbt.value.display.value.Name.value
end end
end end
return self.data.getName() return self.data.getName()
end 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 -------------------------------- -------------------------------- Private Driver --------------------------------
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@@ -49,11 +82,7 @@ function driver.getItems()
if not pipe.getAvailableItems and not pipe.makeRequest then if not pipe.getAvailableItems and not pipe.makeRequest then
error("Logistics pipe is not a a requesting pipe") error("Logistics pipe is not a a requesting pipe")
end end
local output = {} return ItemCollection_new(pipe.getAvailableItems())
for _,item in pairs(pipe.getAvailableItems()) do
table.insert(output, ItemStack_new(item))
end
return output
end end
return driver return driver