fix(item): deep copy cached NBT when cloning items - #2267
Merged
PetteriM1 merged 2 commits intoJun 16, 2026
Conversation
Item#clone only copied the serialized tag bytes, while cachedNBT was still shared through Object#clone. If the original item had already parsed its NBT, mutating lore or other named tag data on the cloned item could also mutate the original item. Deep copy cachedNBT during clone and reset the persistent data container wrapper so cloned items do not keep references bound to the source item. Signed-off-by: NuStar <3318029085@qq.com>
Signed-off-by: NuStar <3318029085@qq.com>
PetteriM1
approved these changes
Jun 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item#clone currently copies the serialized tag bytes, but cachedNBT and the persistent data wrapper can still be shared through Object#clone. This can let mutations on a cloned item's named tag data affect the source item if the source had already decoded its NBT.
This patch clears cachedNBT and resets the persistent data container wrapper on the cloned item, forcing both to be rebuilt lazily from the clone's own state.
test plugin TestCloneItemEdit