The bug
When using the /execute store
command on a tipped arrow with custom potion effects, rather than replacing the respective NBT, it will duplicate the field first, THEN replace the respective NBT in the new field.
How to reproduce
Summon an arrow with
custom_potion_effects
NBT data:/summon arrow ~ ~ ~ {custom_potion_effects:[{ambient:0b,show_particles:1b,duration:1200,id:"minecraft:luck",amplifier:1b}]}
Run an example
execute store
command:/execute store success entity @e[limit=1,type=arrow] custom_potion_effects[0].duration int 1 run say store
Using
/data get
on the entity results in duplicate entries:/data get entity @e[type=arrow,limit=1] custom_potion_effects
Result
Arrow has the following entity data: [{duration: 1200, show_icon: 1b, amplifier: 1b, ambient: 0b, id: "minecraft:luck", show_particles: 1b}, {duration: 1, show_icon: 1b, amplifier: 1b, ambient: 0b, id: "minecraft:luck", show_particles: 1b}]
Using /data remove
doesn't seem to modify the custom_potion_effects
tag at all.
/data remove entity @e[limit=1,type=arrow] custom_potion_effects[0]
using this and then /data get
gives the same results as listed above.
Code analysis
Code analysis by @unknown can be found in this comment.
Related issues
relates to
Attachments
Comments


Can confirm for MC 17w46a.

In 18w31a the last command (/data remove entity @e[limit=1,type=arrow] CustomPotionEffects[0]
) gives me an error: {color:#d04437}Can't access element 0, either doesn't exist or parent isn't a list{color}
.

Can confirm this is still a bug in 1.16.4 pre-release 2. It has the same behaviour with the /data modify command too

In 1.16.4, I can remove the tag. However, the data doesn't update until 600 ticks after I run the command!
If the life was 0 when I ran the command (i.e. the arrow just landed), it updates at life:600
If I set the life to 100 when I run the command, the arrow updates at life:700
Can confirm in 20w48a.

it's an obvious and easy-to-fix bug in the code:
1.17 net/minecraft/world/entity/projectile/Arrow.java:
public void readAdditionalSaveData(CompoundTag arg) {
super.readAdditionalSaveData();
if (arg.contains("Potion", 8))
this.potion = PotionUtils.getPotion(arg);
for (MobEffectInstance mobEffectInstance : PotionUtils.getCustomEffects(arg))
addEffect(mobEffectInstance); //Adds effects in CustomPotionEffects tag
if (arg.contains("Color", 99)) {
setFixedColor(arg.getInt("Color"));
} else {
updateColor();
}
}
When loading an arrow entity from NBT, it only adds new effects instead of rewriting them. That means we can't remove or modify the arrows' original effects.
To fix this bug, just add this.effects.clear(); before loading its effects from NBT ( addEffect(mobEffectInstance); )
So same cause and consequences as MC-112826

Wasn't this fixed in 22w42a? MC-112826 was.

Not fixed in 22w42a, this is still present in 22w46a.


Can confirm for 1.19.4.

Seeing the recent effect NBT changes (snake_casing), does this still affect 1.20.2?

I am only partially able to reproduce this in 1.20.2, but I don't know if it's because of any error in my commands. The effect does not get duplicated, but I am not able to remove it using /data remove
either. I am using the following commands:
/summon arrow ~ ~ ~ {custom_potion_effects:[{ambient:0b,show_particles:1b,duration:1200,id:"minecraft:luck",amplifier:1b}]}
/execute store success entity @e[limit=1,type=arrow] custom_potion_effects[0].id byte 1 run say store
/data remove entity @e[limit=1,type=arrow] custom_potion_effects[0]
That could be an issue with the /execute store
command because id is no longer a byte, but a string; however, I am not very familiar with these commands, so I am not sure what the correct alternative would be. Regardless, I still can't use /data remove
, so I will add 1.20.2 as an affected version.
Update: the effect doesn't get duplicated when you use id
, but it does when you use duration
. So this hasn't been fixed. I will update the description accordingly.