Compare commits
5 Commits
49833b2270
...
logistics-
Author | SHA1 | Date | |
---|---|---|---|
73dab0efac | |||
c40bdb5a09 | |||
9606e545e4 | |||
523696db16 | |||
cb19161ddd |
@@ -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
|
||||||
|
Reference in New Issue
Block a user