Add guaranteed non-nil name for itemstack

This commit is contained in:
Gabriel Tofvesson 2024-10-08 19:58:41 +02:00
parent f70ad73ac0
commit d16558853c

View File

@ -112,6 +112,30 @@ function ItemStack:getDisplayName()
return self.displayName return self.displayName
end end
function ItemStack:getSimpleName()
local displayName = self:getDisplayName()
if displayName ~= nil then
return displayName
end
local name = self:getName()
if name ~= nil then
local _, e = name:find(":")
if e == nil then
return name
end
local simpleName = name:sub(e + 1)
if #simpleName == 0 then
return name
end
return simpleName
end
return self:getInventory():getName().."["..self:getSlot().."]"
end
function ItemStack:hasChanged(listObj, thorough) function ItemStack:hasChanged(listObj, thorough)
local listItem = listObj[self.slot] local listItem = listObj[self.slot]
if listItem == nil or listItem.name ~= self.name or listItem.count ~= self.count then if listItem == nil or listItem.name ~= self.name or listItem.count ~= self.count then