Minecraft – I have a problem where I tag snowballs but the tag dissapears when the snowball is in the air

minecraft-commandsminecraft-java-edition

I am trying to make a cool minigame. In the minigame each player has snowballs and they can set up wool combinations in their inventory which will change their snowball abilities. So far my command string for 1 combination is:

Command block 1, repeating
replaceitem entity @p[nbt={Inventory:[{Slot:6b,id:"minecraft:red_wool"}]},nbt={Inventory:[{Slot:7b,id:"minecraft:blue_wool"}]},nbt={Inventory:[{Slot:8b,id:"minecraft:yellow_wool"}]}] container 0 snowball{Tags:["Path"]}

Command block 2, repeating
execute @e[tag=Path,type=snowball] run setblock ~ ~-2 ~ white_wool keep

With these commands the snowball will leave behind a path for the player to walk across when he has red wool in his 6'th slot, blue wool in his 7'th slot, and yellow wool in his 8'th slot. The problem is that once the snowball is in the air it looses its tag and is just a snowball. I got it to work for all snowballs (not just when the player has a specific combination) with the command:

Command block 1, repeating
execute @e[type=snowball] run setblock ~ ~-2 ~ white_wool keep

It just refuses to work with tags. I also got it to work with combinations, but not tags:

command block 1, repeating
execute @e[type=arrow] if entity @p[nbt={Inventory:[{Slot:6b,id:"minecraft:red_wool"}]},nbt={Inventory:[{Slot:7b,id:"minecraft:blue_wool"}]},nbt={Inventory:[{Slot:8b,id:"minecraft:yellow_wool"}]}] run setblock ~ ~-2 ~ white_wool keep

The problem with this is that if one player has this combination all players' will leave a path behind.

Best Answer

Apart from the NBT error (Tags needs to be in EntityTag), this is caused by the bug MC-123289: Snowball entities don't copy the NBT tags of their item when thrown, so the tag you have given it simply gets deleted when the snowball is thrown.

A workaround for this would be to tag the snowball based on a nearby player who matches conditions. Be careful to only apply that to new snowballs (not yet tagged), otherwise it could change from passing by other players. Even with that, it could still happen that a player throws a snowball in the direction of another player and that player gets selected instead, but only if they are really close, which shouldn't be a problem for your usecase.