Compare commits

...

7 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
49833b2270 Require all needed libraries 2023-03-21 13:33:08 -05:00
0f4fe2bb81 Add NBT custom name lookup 2023-03-21 13:32:56 -05:00
2 changed files with 46 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ local component = require("component")
local driver = {}
--------------------------------------------------------------------------------
---------------------------------- Item Class ----------------------------------
------------------------------- ItemStack Class -------------------------------
--------------------------------------------------------------------------------
local ItemStack = {}
@@ -11,18 +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.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 --------------------------------
--------------------------------------------------------------------------------
@@ -42,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

View File

@@ -1,3 +1,4 @@
local component = require("component")
local pipe = component.logisticspipe.getPipe()
local items = pipe.getAvailableItems()
print("Requesting all items I can find... this might take up a lot of storage space!")