Couple of item questions

I’m trying to spawn a red dyed leather pants item into the world that does not despawn.

Location<World> location = ...
World world = location.getExtent();
ItemStack itemStack = ItemStack.builder()
        .itemType(ItemTypes.LEATHER_LEGGINGS)
        .quantity(1)
        .keyValue(Keys.DYE_COLOR, DyeColors.RED)
        .keyValue(Keys.AGE, -1)
        .build();

Item item = (Item) world.createEntity(EntityTypes.ITEM, location.getPosition());
item.offer(Keys.REPRESENTED_ITEM, itemStack.createSnapshot());
world.spawnEntity(item, Cause.source(EntitySpawnCause.builder().entity(item).type(SpawnTypes.PLUGIN).build()).build());

So I’m assuming .keyValue(Keys.DYE_COLOR, DyeColors.RED) should dye the item red.
And .keyValue(Keys.AGE, -1) should prevent the item from despawning?

If so, then I realise the AGE is not implemented yet (if I interpret this checklist correctly). DyeableData should be implemented though, right? But this spawns regular undyed leather leggings without color.

So my questions are what should be working and what not. And more importantly, if something isn’t implemented yet, are there any ways for me to work around it to get the same results (so to prevent an item from despawning, and to create dyed leather leggings itemstack).

You can test exactly what’s implemented and what isn’t with this simple command:
/entitydata @e[type=Item,c=1] {}
It’ll paste the entire NBT tag into the chat window, and you can see what’s modified.

OK so DYE_COLOR is for things that use the 4-bit MC colors - eg wool. For Leather and fireworks you instead use COLOR

As for AGE, as far as I know that key is for an animals age, such as baby pigs, sheep, etc. For that you want to be using EXPIRATION_TICKS instead.

Unfortunately however EXPIRATION_TICKS is not yet implemented for items.

When this is merged eventualy there will be the possibilty to set it to “infinite”.

Thanks, all these responses were very helpful.

For feature readers, as a temporary work around to prevent the item from despawning I’m spawning a new item on ExpireEntityEvent.TargetItem.

Now… which reply to mark as the reply that answered the question when every single reply solved a part of the puzzle… :slight_smile:

I think what also should work is
/summon Item ~ ~1 ~ {Item:{id:minecraft:stone,Count:1},Age:-32768}
to spawn an item with the vanilla command or
/entitydata <UUID> {Age:-32768}
to modify an already spawned item.