Prevent Items From Despawning

This simple tutorial makes it possible for items to never despawn!

Supported Versions:

1.21.81.21.9+

Tutorial Steps:

  1. Use Command Row 1 or Command Row 2 to either summon the item with tag or give items near you with tags
  2. Put down a repeat command block in a spawn chunk or area that is always loaded and put Command Row 3 inside
  3. Here you can either have the age set to -32768 or -1. -32768 will make the item never despawn even if the command block is turned off! -1 will despawn items after 5 minutes if the command block is off but may be laggier. The choice is yours!
  4. Have a lever running the command and your good to go!

Commands by Row:

Row 1

1. [impulse] /give @p diamond[minecraft:custom_data={noDespawn:1}]

Row 2

2. [impulse] /execute as @e[type=item,distance=..5] run data merge entity @s {Item:{components:{"minecraft:custom_data":{noDespawn:1}}}}

Row 3

3. [repeat] /execute as @e[type=item,nbt={Item:{components:{"minecraft:custom_data":{noDespawn:1}}}},nbt=!{Age:-32768s}] run data merge entity @s {Age:-32768}

Preview

impulse
impulse
repeat

Video

Too lazy to copy and paste each command?