diff --git a/storage/itemstack.lua b/storage/itemstack.lua index e472465..e842dc3 100644 --- a/storage/itemstack.lua +++ b/storage/itemstack.lua @@ -1,6 +1,7 @@ local Inventory = require("storage.inventory") local Sentinel = require("storage.sentinel") local Logging = require("logging") +local Util = require("util") local Logger = Logging.getGlobalLogger() local ItemStack = Sentinel:tag({}, Sentinel.ITEMSTACK) @@ -13,7 +14,7 @@ function ItemStack:fromDetail(inv, detail, slot) } if detail == nil then - obj.maxCount = inv.getItemLimit(slot) + obj.maxCount = Util.getItemLimit(inv, slot) else obj.name = detail.name obj.damage = detail.damage @@ -117,7 +118,8 @@ function ItemStack:getNBT() end function ItemStack:isEmpty() - return self.count == nil or self.count == 0 + local count = self:getCount() + return count == nil or count == 0 end function ItemStack:getDisplayName() @@ -150,7 +152,7 @@ end function ItemStack:hasChanged(listObj, thorough) local listItem = listObj[self:getSlot()] - if listItem == nil or listItem.name ~= self.name or listItem.count ~= self:getCount() then + if listItem == nil or listItem.name ~= self:getName() or listItem.count ~= self:getCount() then return true end @@ -167,7 +169,7 @@ function ItemStack:_modify(countDelta, stack) if newCount == 0 then -- Clear data - self.maxCount = self.inv.getItemLimit(self.slot) + self.maxCount = Util.getItemLimit(self:getInventory(), self:getSlot()) self.name = nil self.damage = nil self.maxDamage = nil diff --git a/util/init.lua b/util/init.lua index 64cd615..5bda4f4 100644 --- a/util/init.lua +++ b/util/init.lua @@ -18,4 +18,17 @@ function Util.boundCheck(x, y, w, h) end end +-- Workaround for a bug in CC: Tweaked causing inventory.getItemLimit() to return nil immediately after item transfers +function Util.getItemLimit(inv, slot, maxTries) + local i = 1 + while not maxTries or i <= maxTries do + local result = inv.getItemLimit(slot) + if result ~= nil then + return result + end + i = i + 1 + end + return nil +end + return Util \ No newline at end of file