TransWikia.com

Preserving NBT tags on arrows

Arqade Asked by Justin Foster on January 13, 2021

I am attempting to create arrows that summon lightning once when they hit the ground. I got this working, however, I want this to only occur when a particular player fires an arrow. I got this concept to work with items instead of arrows by applying a custom tag with /give @p arrow{customTag:lightning}. Then when the arrow is thrown on the ground, lightning is summoned by a repeating command block with /execute at @e[nbt={OnGround:1b,Item:{tag:{customTag:lightning}}}] run summon lightning ~ ~ ~ and the item is killed with /kill @e[nbt={OnGround:1b,Item:{tag:{customTag:lightning}}}] in a chain command block.

I then tried to replicate this process with arrows fired from a bow instead of arrows dropped on the ground. However, I found out that the customTag is not preserved when the arrow is fired. All nbt tags appear to disappear once the arrow becomes a projectile. Is there any way to apply a customTag or other nbt tag to an arrow when it is an item that stays with the arrow even once it is fired from a bow.

One Answer

As far as I am aware, there is no way to directly preserve the tags in a useable way, I might be wrong though. But there is a workaround: You could apply a tag to the player (or check the inventory for the arrows with the tag, though that is a litte time consuming) and then let the players reapply the nbt-tags via /execute ... distance ... inGround:0b ...
So as soon as an arrow flies right next to the player this arrow gets the tag applied.

repeating Command Block:

/execute at @a[tag=ShootsLightning] run tag @e[type=minecraft:arrow, distance=0..3, nbt={inGround:0b}] add lightning

chain command block linked to the first one:

/execute at @e[tag=lightning, type=arrow, nbt={inGround:1b}] run summon minecraft:lightning ~ ~ ~

another repeating command block:

/kill @e[tag=lightning, type=arrow, nbt={inGround:1b}]

There are some problems with this. For example: Arrows which aren't shot by the player but fly near him will get the tag applied too.

Answered by user259487 on January 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP