Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Chest = {name = "", itemList = {}, wrap = nil}
- function Chest:new(o, name)
- o = o or {}
- setmetatable(o, self)
- self.__index = self
- self.name = name or ""
- return o
- end
- function Chest:init(x)
- for slot, item in pairs(self.wrap.list()) do
- --print(("%s:%d in slot %d"):format(item.name, item.count, slot))
- if self.itemList[item.name] == nil then
- self.itemList[item.name] = { slot = { slot }, itemcount = item.count }
- else
- table.insert(self.itemList[item.name]["slot"], slot)
- self.itemList[item.name].itemcount = self.itemList[item.name].itemcount + item.count
- end
- end
- end
- function Chest:connect()
- self.wrap = peripheral.wrap(self.name)
- end
- function Chest:print()
- for item, slot in pairs(self.itemList) do
- textutils.pagedPrint(("%s in %s"):format(item, textutils.serialise(slot)))
- end
- end
- function Chest:printItem(name)
- textutils.pagedPrint(("Item => %s"):format(textutils.serialise(self.itemList[name])))
- end
- chest = Chest:new{name = "expandedstorage:chest_1"}
- chest:connect()
- chest:init()
- chest:print()
- chest:printItem("minecraft:coal")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement