Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local chest_list = { peripheral.find("minecraft:chest") }
- local chest_main = ""
- local item_list = {}
- local ssn = {}
- local function index_item(item, slot, chest)
- if item_list[item.name] == nil then item_list[item.name] = {} end
- local list_ = item_list[item.name]
- list_[#list_+1] = {item=item, slot=slot, chest=chest}
- end
- function ssn.init(chest_name)
- chest_main = chest_name
- for index, chest in pairs(chest_list) do
- if peripheral.getName(chest) == chest_main then
- table.remove(chest_list, index)
- chest_main = chest
- else
- for slot, item in pairs(chest.list()) do
- index_item(item, slot, chest)
- end
- end
- end
- end
- function ssn.sum(item_id)
- if item_list[item_id] == nil then return 0 end
- local sum = 0
- for index, info in pairs(item_list[item_id]) do
- sum = sum + info.item.count
- end
- return sum
- end
- function ssn.pull(item_id)
- if item_list[item_id] == nil then return false end
- if #item_list[item_id] == 0 then return false end
- local item = item_list[item_id]
- item[#item].chest.pushItems( peripheral.getName(chest_main), item[#item].slot)
- table.remove(item #item)
- end
- function ssn.free_capacity(chest)
- local cap = 0
- for i = 1, chest.size() do
- if chest.getItemDetail(i) == nil then
- cap = cap + 1
- end
- end
- return cap
- end
- function ssn.exist(item_id)
- return item_list[item_id] ~= nil
- end
- return ssn
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement