2

I searched up how to do this several times and I could only find ways to spawn items that cannot be picked up, and if it was a tutorial about stopping item despawning, it would still despawn after being picked up and dropped on the ground again.

I'm working on a game, fully with command blocks, and I have absolutely no idea how to stop items from despawning.

Could NBT tags be put on item entities too? So that when they get dropped, they still have the NBT tag?

Does anyone know how to stop them from despawning?

  • Are you trying to stop all items from despawning, or only some items from despawning? – pppery Jul 28 at 14:18
  • only specific items, is what I'm trying to do – TheBrickMonkey Jul 28 at 14:19
1

First, you can stop a specific item from despawning unless it is picked up and then dropped again by setting it's Age to -32768 with a command block.

Second, you can add arbitrary custom NBT data to an item, which will be preserved across drop-and-pickup cycles.

You can combine these two techniques to make specific items never despawn by running the command:

/execute as @e[type=item,nbt={Item:{tag:{noDespawn:1b}}}] run data merge entity @s {Age:-32768}

This would make any item given with a noDespawn:1b NBT tag (/give <player> <item>{noDespawn:1b}) never despawn, even if it is picked up and dropped again.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.