Track nbt entries

This commit is contained in:
Gabriel Tofvesson 2024-10-09 04:26:39 +02:00
parent df93ccf801
commit 3f3dd111c1
2 changed files with 18 additions and 3 deletions

View File

@ -49,6 +49,10 @@ function ItemGroup:getEnchantments()
return self:_getIdentityStack():getEnchantments()
end
function ItemGroup:getNBT()
return self:_getIdentityStack():getNBT()
end
function ItemGroup:_getIdentityStack()
return self[1]
end

View File

@ -19,6 +19,7 @@ function ItemStack:fromDetail(inv, detail, slot)
obj.maxCount = detail.maxCount
obj.enchantments = detail.enchantments
obj.displayName = detail.displayName
obj.nbt = detail.nbt
end
setmetatable(obj, self)
@ -37,7 +38,8 @@ function ItemStack:clone(withSlot)
count = self.count,
maxCount = self.maxCount,
enchantments = self.enchantments,
displayName = self.displayName
displayName = self.displayName,
nbt = self.nbt
}
setmetatable(obj, self)
@ -52,7 +54,7 @@ function ItemStack:toSerializable()
maxCount = self.maxCount
}
if self.count ~= nil then
if not self:isEmpty() then
-- Not empty
ser.name = self.name
ser.damage = self.damage
@ -60,6 +62,7 @@ function ItemStack:toSerializable()
ser.count = self.count
ser.enchantments = self.enchantments
ser.displayName = self.displayName
ser.nbt = self.nbt
end
return ser
@ -106,6 +109,10 @@ function ItemStack:getInventory()
return self.inv
end
function ItemStack:getNBT()
return self.nbt
end
function ItemStack:isEmpty()
return self.count == nil or self.count == 0
end
@ -134,7 +141,7 @@ function ItemStack:getSimpleName()
return simpleName
end
return Inventory.getSimpleName(self:getInventory()).."["..(self:getSlot() or "NO_SLOT").."]"
end
@ -163,6 +170,7 @@ function ItemStack:_modify(countDelta, stack)
self.maxCount = nil
self.enchantments = nil
self.displayName = nil
self.nbt = nil
else
-- If stack is empty, copy stack data from source
if self:isEmpty() then
@ -173,6 +181,7 @@ function ItemStack:_modify(countDelta, stack)
self.maxCount = stack.maxCount
self.enchantments = stack.enchantments
self.displayName = stack.displayName
self.nbt = stack.nbt
end
self.count = newCount
@ -243,6 +252,7 @@ function ItemStack:canTransfer(stack)
self.damage == stack.damage and
self.maxDamage == stack.maxDamage and
self.displayName == stack.displayName and
self.nbt == stack.nbt and
objEquals(self.enchantments, stack.enchantments))
end
@ -272,6 +282,7 @@ function ItemStack:matches(query)
queryField(query.maxDamage, self.maxDamage) and
queryField(query.enchantments, self.enchantments) and
queryField(query.maxCount, self.maxCount) and
queryField(query.nbt, self.nbt) and
queryField(query.displayName, self.displayName)
end