Add pipe_driver
This commit is contained in:
parent
9ac9294484
commit
2ff57086e2
|
@ -0,0 +1,51 @@
|
||||||
|
local component = require("component")
|
||||||
|
|
||||||
|
local driver = {}
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
---------------------------------- Item Class ----------------------------------
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local ItemStack = {}
|
||||||
|
|
||||||
|
function ItemStack.new(item)
|
||||||
|
checkARg(1, item, "table");
|
||||||
|
local out = {
|
||||||
|
data = item.getValue1(),
|
||||||
|
quantity = item.getValue2()
|
||||||
|
}
|
||||||
|
setmetatable(out, ItemStack)
|
||||||
|
return out
|
||||||
|
end
|
||||||
|
|
||||||
|
function ItemStack:getName()
|
||||||
|
return self.data.getName()
|
||||||
|
end
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
-------------------------------- Private Driver --------------------------------
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
driver.internal = {}
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
-------------------------------- Public Driver --------------------------------
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function driver.getItems()
|
||||||
|
if not component.isAvailable("logisticspipe") then
|
||||||
|
error("no logistics pipe available", 2)
|
||||||
|
end
|
||||||
|
local pipe = component.logisticspipe.getPipe()
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
return driver
|
Loading…
Reference in New Issue