Add pipe_driver

This commit is contained in:
Cody Young 2023-03-21 00:01:59 -05:00
parent 9ac9294484
commit 2ff57086e2
1 changed files with 51 additions and 0 deletions

View File

@ -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