#Better way to write this function?

1 messages · Page 1 of 1 (latest)

grave oakBOT
#

is there a better way to write this function? i was thinking item modifiers but i dont really know how they work

## Add Tag
# Util function for adding an entity tag to a spawn egg

## Args
# tag : string

execute unless block ~ ~ ~ #air run return fail
setblock ~ ~ ~ minecraft:barrel
item replace block ~ ~ ~ container.0 from entity @s weapon.mainhand
$data modify block ~ ~ ~ Items[0].components."minecraft:entity_data".Tags append value $(tag)
item replace entity @s weapon.mainhand from block ~ ~ ~ container.0
setblock ~ ~ ~ air
balmy iceBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

balmy iceBOT
# balmy ice <@&1201956957406109788>

<@&1166082198152159386> <@&1202694677766348840>

🙇 Helpers Arise!

Please note that you still might not immediately get a response since all helpers are human beings and volunteers (and also might be sleeping right now)

lost steppe
#

An item modifier instead of the data command there would be better, yes

winged dove
#

how would i do it with item modifiers though?

lost steppe
#

In fact you can do an item modifier instead of copying the item to a container first

#

Make an item modifier, then use it with the item modify command

winged dove
#

i dont understand the generator, what would be the option for modifying components

#

theres one for setting and one for copying

#

does setting also modify?

lost steppe
#

Ah, I wasn't looking too closely at what you were doing with your data command. I don't believe there's a way to append tags like that with an item modifier

#

So what you have is the best way to do it, but it's possible that with better context as to what you're trying to do, an alternative could be found that does use an item modifier

winged dove
#

i have a handful of special spawn eggs for entities in my map, and i use tags for enabling and disabling them, the function modifies the spawn egg im holding to add a tag to the entity that it's going to spawn

#

since the egg is special, it needs to keep its data

sterile sierra
#

to append to a tag inside the custom_data component, you can use the copy_custom_data function

winged dove
#

its not custom data

sterile sierra
#

oh nvm I misread "entity data" as "custom data"

#

yeah an operation like that doesn't exist for entity_data

winged dove
#

unfortunate

sterile sierra
#

actually, an inline item modifier could probably do it

winged dove
#

what makes inline modifiers special?

sterile sierra
#

that they're set using a command, so macro commands let you set their contents

#

oh but that still wouldn't let you actually append

#

I only thought of how to make set_entity_data set a dynamic value

winged dove
#

oh

#

yeah

#

i mean i could probably throw the entire item's components into a big macro maybe, but i dont know if its worth it

lost steppe
#

If you're doing this function a lot, then probably

winged dove