Advertisement
alsacchi

test.lua

Jan 28th, 2022
1,139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.18 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 }, itemcount = item.count }
  16.         else
  17.             table.insert(self.itemList[item.name]["slot"], slot)
  18.             self.itemList[item.name].itemcount = self.itemList[item.name].itemcount + item.count
  19.          end
  20.     end
  21. end
  22.  
  23. function Chest:connect()
  24.     self.wrap = peripheral.wrap(self.name)
  25. end
  26.  
  27. function Chest:print()
  28.     for item, slot in pairs(self.itemList) do
  29.         textutils.pagedPrint(("%s in %s"):format(item, textutils.serialise(slot)))
  30.     end
  31. end
  32.  
  33. function Chest:printItem(name)
  34.     textutils.pagedPrint(("Item %s => %s"):format(name, textutils.serialise(self.itemList[name])))
  35. end
  36.  
  37.  
  38. chest = Chest:new{name = "expandedstorage:chest_1"}
  39.  
  40. chest:connect()
  41. chest:init()
  42. chest:print()
  43. chest:printItem("minecraft:coal")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement