Skip to content

fix(item): deep copy cached NBT when cloning items - #2267

Merged
PetteriM1 merged 2 commits into
CloudburstMC:masterfrom
NuStarWorld:fix/item-shallow-copy
Jun 16, 2026
Merged

fix(item): deep copy cached NBT when cloning items#2267
PetteriM1 merged 2 commits into
CloudburstMC:masterfrom
NuStarWorld:fix/item-shallow-copy

Conversation

@NuStarWorld

@NuStarWorld NuStarWorld commented May 31, 2026

Copy link
Copy Markdown
Contributor

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

  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
PetteriM1 merged commit 1192336 into CloudburstMC:master Jun 16, 2026
1 check passed
@NuStarWorld
NuStarWorld deleted the fix/item-shallow-copy branch June 17, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants