mojira.dev
MC-21098

Throwing projectiles at minecarts, boats (with chest), (glow) item frames, and paintings in creative mode will delete them

The Bug:

Throwing projectiles at minecarts, boats, item frames, or paintings in creative mode will delete them.

Steps to Reproduce:

  • Switch into creative mode and obtain any throwable projectile, for example, some snowballs.

  • Summon either a minecart, boat, item frame, or painting.

  • Throw the projectile at the entity you just summoned.

  • Take note as to whether or not throwing projectiles at minecarts, boats, item frames, or paintings in creative mode will delete them.

Observed Behavior:

Throwing projectiles at minecarts, boats, item frames, or paintings in creative mode will delete them.

Expected Behavior:

Throwing projectiles at minecarts, boats, item frames, or paintings in creative mode would not delete them.

Code Analysis:

Code analysis by @unknown can be found in this comment.

Linked issues

MC-273424 TNT minecarts that get hit by wind charges disappear Resolved MC-272848 EnderPearl bug Resolved MC-275924 Minecart disappear after wind charge thrown near it Resolved MC-272641 When a projectile collides with a boat, the boat is destroyed Resolved MC-233792 Ender pearls can destroy paintings, item frames and glow item frames in Creative mode Resolved

Attachments

Comments 31

Working as intended.
All entities drop nothing when destroyed by snowballs in creative.

Confirmed for

  • 1.9

The bug is that normally projectiles like snowballs, eggs and enderpearls deal 0 damage, however when you throw them in Creative mode they destroy boats and minecarts instantaneously.

Please link to this comment in the description

The following is based on decompiled version of Minecraft 1.9 using MCP 9.24 beta. All method and class names are the names used in the decompiled version.

The reason why this happens is because the methods net.minecraft.entity.item.EntityMinecart.attackEntityFrom(DamageSource, float) and net.minecraft.entity.item.EntityBoat.attackEntityFrom(DamageSource, float) only test if the player damaging the entity is in creative mode however they should make sure that the damage was dealt directly.

/**
 * Called when the entity is attacked.
 */
public boolean attackEntityFrom(DamageSource source, float amount)
{
    if (!this.worldObj.isRemote && !this.isDead)
    {
        if (this.isEntityInvulnerable(source))
        {
            return false;
        }
        else
        {
            this.setRollingDirection(-this.getRollingDirection());
            this.setRollingAmplitude(10);
            this.setBeenAttacked();
            this.setDamage(this.getDamage() + amount * 10.0F);
            // Replaced this
            //boolean flag = source.getEntity() instanceof EntityPlayer && ((EntityPlayer)source.getEntity()).capabilities.isCreativeMode;
            boolean flag = source.getDamageType().equals("player") && source.isCreativePlayer();

            if (flag || this.getDamage() > 40.0F)
            {
                this.removePassengers();

                if (flag && !this.hasCustomName())
                {
                    this.setDead();
                }
                else
                {
                    this.killMinecart(source);
                }
            }

            return true;
        }
    }
    else
    {
        return true;
    }
}

Confirmed for 16w39c

21 more comments

Can confirm in 1.18.1.

Can confirm in 1.18.2.

Can confirm in 1.19.

Can confirm in 1.19.2.

Can confirm in 1.21-rc1.
Edit: this issue occurs even when the summoned entity has the {Invulnerable:1} tag.

Patrick

[Mod] turbo

(Unassigned)

Confirmed

Platform

Normal

Entities, Projectiles

boat, boat-with-chest, egg, ender_pearl, glow_item_frame, item_frame, minecart, painting, snowball, trident

Minecraft 1.6.1, Minecraft 1.9, Minecraft 1.10.2, Minecraft 16w32a, Minecraft 16w32b, ..., 1.21.4, 25w04a, 1.21.8, 25w32a, 1.21.10

Retrieved