#Placing a players head into an ender chest

1 messages · Page 1 of 1 (latest)

languid crest
#

Hey guys, i am developing a datapack and i want to place the players playerhead inside his ender chest with some custom nbt data.
So far i have created a loot table file, that gives the player head and using these commands, i can place them inside the ender chest:

loot replace entity @e[type=item_frame,tag=head_getter,limit=1] container.0 loot namespace:player_head

data modify storage minecraft:menu head_item set from entity @e[type=item_frame,tag=head_getter,limit=1] Item
data modify storage minecraft:menu head_item.tag merge value {custom_data:{isMenu:1b,page:1,selection:4}}

item replace entity @s enderchest.25 from entity @e[type=item_frame,tag=head_getter,limit=1] container.0

Not sure if this ís actually the best way to do it, this just works, but the nbt data (custom_data) is not added to the item. How can i add that data?
I thought about something like:

data modify entity @s EnderItems[{Slot:25b}].components.custom_data set value {isMenu:1b,page:1,selection:4}

but that doesnt work and i think the "path" changed in 1.21, but i am unsure about this.

Could someone help me with this? Maybe someone knows a better way to do it?

round prism
#

The reason that second code block doesn't work is that you can't modify the NBT data of players

#

You can add the custom data using an item modifier though, which will work on players

languid crest
round prism
#

An item modifier is a JSON file that lets you perform changes or functions on items. The functions you do in loot tables are examples of item modifiers, they're just in-line. You can also apply them separately to existing item stacks using the item modify command.

You can make one here, and save the output as a JSON file in your data pack under data/<namespace>/item_modifier
https://misode.github.io/item-modifier/

Specifically, you're going to want a set_custom_data function. That'll let you add the custom data to the item in the player's ender chest by targeting that slot directly in the item modify command

languid crest
#

Ok, i think i might have understood what you mean, i will test that later and hope it works. Thank you 🙂

languid crest
#

Thanks btw, i got it working with the item_modifier

round prism
#

Since the bot is down I'll go ahead and manually close the thread, but feel free to reply if you discover you need more help with this