mojira.dev
MC-122008

custom_potion_effects in arrow entities duplicates with '/execute store' and isn't affected by '/data remove'

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

  1. 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}]}
  2. 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
  3. 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

Attachments

Comments

migrated
[media][media]
migrated

Can confirm for MC 17w46a.

lord.quadrato

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}.

ekul6547

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

migrated

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

Avoma

Can confirm in 20w48a.

Former user

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); )

tryashtar

So same cause and consequences as MC-112826

migrated

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

ampolive

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

migrated

Relates to MC-128225, MC-179815, MC-153392, MC-207605, MC-135044, MC-138100.

This also appears to have the wrong category; the correct category is Commands, not Data Packs.

migrated

Can confirm for 1.19.4.

migrated

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

ampolive

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.

MukiTanuki

(Unassigned)

Confirmed

Platform

Low

Data Packs

/data-remove, /execute-store, CustomPotionEffects, duplication

Minecraft 17w47a, Minecraft 17w47b, Minecraft 17w48a, Minecraft 17w50a, Minecraft 18w01a, ..., 1.19.3, 23w05a, 1.19.4, 1.20.2, 1.20.4

24w09a

Retrieved