alsacchi

Untitled

Jan 28th, 2022 (edited)
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.89 KB | None | 0 0
  1. Chest = {name = "", itemList = {}, wrap = nil}
  2.  
  3. function Chest:new(o, name)
  4.    o = o or {}
  5.    setmetatable(o, self)
  6.    self.__index = self
  7.    self.name = name or ""
  8.    return o
  9. end
  10.  
  11. function Chest:init(x)
  12.     for slot, item in pairs(self.wrap.list()) do
  13.         --print(("%s:%d in slot %d"):format(item.name, item.count, slot))
  14.         if self.itemList[item.name] == nil then
  15.             self.itemList[item.name] = { slot = { slot } }
  16.         else
  17.             table.insert(self.itemList[item.name]["slot"], slot)
  18.         end
  19.     end
  20. end
  21.  
  22. function Chest:connect(x)
  23.     self.wrap = peripheral.wrap(self.name)
  24. end
  25.  
  26. function Chest:print(x)
  27.     for item, slot in pairs(self.itemList) do
  28.         textutils.pagedPrint(("%s in %s"):format(item, textutils.serialise(slot)))
  29.     end
  30. end
  31.  
  32. chest = Chest:new{name = "expandedstorage:chest_1"}
  33.  
  34. chest:connect()
  35. chest:init()
  36. chest:print()
Add Comment
Please, Sign In to add comment