diff --git a/storage/inventory.lua b/storage/inventory.lua new file mode 100644 index 0000000..7b0fe79 --- /dev/null +++ b/storage/inventory.lua @@ -0,0 +1,21 @@ +local Inventory = {} + +function Inventory.getName(inv) + return peripheral.getName(inv) +end + +function Inventory.getSimpleName(inv) + if inv == nil then + return "[NO_INV]" + end + local name = peripheral.getName(inv) + local _, e = name:find(":") + + if e == nil then + return name + end + + return name:sub(e + 1) +end + +return Inventory \ No newline at end of file diff --git a/storage/itemstack.lua b/storage/itemstack.lua index 8f545ef..867d999 100644 --- a/storage/itemstack.lua +++ b/storage/itemstack.lua @@ -1,3 +1,5 @@ +local Inventory = require("storage.inventory") + local ItemStack = {} ItemStack.__index = ItemStack @@ -132,9 +134,8 @@ function ItemStack:getSimpleName() return simpleName end - - local inventory = self:getInventory() - return (((inventory and inventory:getName()) or inventory and "[UNKNOWN_INV]") or "[NO_INV]").."["..(self:getSlot() or "NO_SLOT").."]" + + return Inventory.getSimpleName(self:getInventory()).."["..(self:getSlot() or "NO_SLOT").."]" end function ItemStack:hasChanged(listObj, thorough)