mojira.dev
MC-44280

Entities don't receive knockback from projectiles fired from dispensers

Fireworks, eggs, snowballs, and splash potions of harming fired from dispensers don't knock back mobs, but they do when thrown by the player or a mob such as a snow golem or witch.

Steps to Reproduce:

  • Build the setup as shown in the attachment below.

[media]
  • Place some snowballs inside of the dispenser.

  • Summon a husk on the diamond block.

  • Use the lever to activate the dispenser and watch the husk closely.

Observed Behavior:
Projectiles fired from dispensers don't deal any knockback to entities.

Expected Behavior:
Projectiles fired from dispensers would deal knockback to entities.

Note

Arrows are not affected by this bug, as they knock back mobs when fired either from a bow or a dispenser.

Code analysis

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

Related issues

Attachments

Comments

migrated
[media][media][media][media]
JMan Redstone
Sonicwave

Confirmed in 1.8. Also affects Splash Potions of Harming.

ilmango

confirmed for 1.9 pre2. snowballs fly through mobs now. It's worse than before.

marcono1234

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 for this bug is that the net.minecraft.entity.EntityLivingBase.attackEntityFrom(DamageSource, float) method only knockbacks mobs if the indirect damage has an entity as owner. This is not the case for projectiles fired from a dispenser. The problem is that currently the coordinates of the thrower are used to determine the knockback.
This allows "exploits" like [[Tutorial] Guided & Regular Rocket Launcher in Vanilla Minecraft Using Fireballs! [MC 1.8]|https://www.youtube.com/watch?v=548wxRDL1U8].

A possible solution would be to use the motion of the projectile. This means however that the distance does not determine the strength completely anymore.
The following shows how this could be done, but the motion values very likely need to be adjusted.

// Added this
if (source instanceof net.minecraft.util.EntityDamageSourceIndirect && source.getSourceOfDamage() != null) {
    Entity damagingEntity = source.getSourceOfDamage();
    double d1 = -damagingEntity.motionX;
    double d0;

    for (d0 = -damagingEntity.motionZ; d1 * d1 + d0 * d0 < 1.0E-4D; d0 = (Math.random() - Math.random()) * 0.01D)
    {
        d1 = (Math.random() - Math.random()) * 0.01D;
    }

    this.attackedAtYaw = (float)(MathHelper.atan2(d0, d1) * (180D / Math.PI) - (double)this.rotationYaw);
    this.knockBack(entity, 0.4F, d1, d0);
    
}
// Replaced this
//if (entity != null)
else if (entity != null)
{
    double d1 = entity.posX - this.posX;
    double d0;

    for (d0 = entity.posZ - this.posZ; d1 * d1 + d0 * d0 < 1.0E-4D; d0 = (Math.random() - Math.random()) * 0.01D)
    {
        d1 = (Math.random() - Math.random()) * 0.01D;
    }

    this.attackedAtYaw = (float)(MathHelper.atan2(d0, d1) * (180D / Math.PI) - (double)this.rotationYaw);
    this.knockBack(entity, 0.4F, d1, d0);
}
else
{
    this.attackedAtYaw = (float)((int)(Math.random() * 2.0D) * 180);
}
Balázs Slemmer

Still present in 1.9.3-pre2.

Max M

Still present in 16w20a

marcono1234

Confirmed for

  • 16w32a

Nick Bambridge

@Marcono1234
If knockback requires an entity as the damage source, why do arrows fired from dispensers work as expected?

Can we copy the knockback strength and direction from the arrows code, or is that too tied up with damage > 0 hearts or something?

Skylinerw

@@unknown Arrows will set themselves as the attacker if no "owner" is present:

if (this.shootingEntity == null)
{
    damagesource = DamageSource.causeArrowDamage(this, this);
}
else
{
    damagesource = DamageSource.causeArrowDamage(this, this.shootingEntity);
}

Theoretically the same could be done with the eggs and snowballs (example below is from eggs, with the commented code being an addition, though I have not actually tried this myself):

if (result.entityHit != null)
{
    //if (this.getThrower() == null)
    //{
        result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this), 0.0F);
    //}
    //else
    //{
    //    result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 0.0F);
    //}
}
JUE13

Confirmed for 17w15a

Sonicwave

Confirmed for 1.12.2 and 17w47b.

Kraif

Confirmed for 1.13.1. Please, if you don't mind, I'd like to be the reporter of this ticket, I'll update it accordingly.

Nick Bambridge

Actually, I am still around, and I do wish to be acknowledged as the discoverer of the bug.

@Kraif What changes did you feel need to be made?
@Torabi You've been changing the reporter to Kraif on quite a few bugs recently. Maybe he should be made a mod instead?

Kraif

@unknown: I asked to be the reporter because your ticket was outdated. I'll update it accordingly. BTW: Everyone can see that you are the original reporter of this ticket by clicking "History" or "Activity", so don't worry!

Torabi

You haven't updated the issue for the past three years, and your last activity on the tracker was in december, nine months ago. The fact that you created the issue is still listed in the issue history, and the reporter field just allows regular users to update the issue directly, rather than leaving a comment for someone else to take care of it. Unfortunately, the JIRA software the tracker runs on does not allow for multiple users to have edit permissions on a single issue, without having those permissions across entire projects, like our helpers and mods do.

We have an internal selection process for bringing on new helpers and mods, and consider not only how active a user is, but the quality and tone of their interactions with the tracker and other users. We like to watch a user over a period of time, to see how well they understand the tracker and the community, before we consider offering them additional roles.

Nick Bambridge

Confirmed for version 1.13.2

Nick Bambridge

Confirmed for version 1.14.4

Nick Bambridge

Still present in 19w36a

Nick Bambridge

Still present in 19w37a.

Also attached screenshot of my test setup.

Dobbi

Still exists in 1.16 Pre-release 4, I would also like to add that splash potions are not listed above as one of the projectiles that fail to inflict knockback but I found out that they don't inflict knockback either.

Nick Bambridge

Still present in 1.16.1, including splash potions as noted by @Dobbi

Nick Bambridge

Still present in 1.16.3

Would it be possible to change me back to the reporter of this bug, so I can keep the affected versions up to date and add info regarding splash potions?

ProPork

can u add 1.16.3 i also checked

user-f2760

Probably related to MC-125936.

Avoma

Can confirm in 21w05b.

Avoma

Can confirm in 21w06a.

Avoma

Can confirm in 21w07a.

Avoma

Video attached.

Avoma

Can confirm in 21w11a.

Avoma

Can confirm in 21w14a.

Avoma

Can confirm in 21w17a.

A

Possibly same root cause as MC-225541

Avoma

Can confirm in 1.17.

Avoma

Can confirm in 1.17.1.

Avoma

This ticket relates to MC-78473.

Avoma

Can confirm this behavior in 21w39a. Here are some extra details regarding this problem.

The Bug:

Projectiles fired from dispensers don't deal any knockback to entities.

Steps to Reproduce:

  • Build the setup as shown in the attachment below.

[media]
  • Place some snowballs inside of the dispenser.

  • Summon a husk on the diamond block.

  • Use the lever to activate the dispenser and watch the husk closely.

Observed Behavior:

Projectiles fired from dispensers don't deal any knockback to entities.

Expected Behavior:

Projectiles fired from dispensers would deal knockback to entities.

Avoma

Can confirm in 1.18.1.

Avoma

Can confirm in 1.18.2.

Avoma

Can confirm in 22w17a.

Avoma

Can confirm in 1.19.

Avoma

Can confirm in 1.19.2.

Josh Birk

Can Confirm 1.19.3 Release Candidate 3

Avoma

@unknown, 1.19.3 Release Candidate 3 is already marked as affected. 🙂

Nick Bambridge

Shugoh

Confirmed

Gameplay

Low

Entities, Projectiles

dispenser, egg, knockback, snowball

Minecraft 1.7.4, Minecraft 1.7.9, Minecraft 1.8, Minecraft 1.8.3, Minecraft 15w47c, ..., 1.19.3, 1.20, 1.20.1, 1.20.2, 1.20.4

Minecraft 16w02a, 24w18a

Retrieved