mojira.dev
MC-227337

When a shulker bullet hits an entity, the explodes sound is not played and particles are not produced

When the shulker bullet hits the entity does not play an explodes sound and particles.

[media]

Not the same as when they hit the block.

[media]

Also inconsistency with the fireball.

[media]

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

Linked issues

Attachments

Comments 6

DogEatingSpaghetti

I think works as intended becouse normally they don’t explode when hitting an entity, right? I think it normally explodes only when colliding with blocks

Avoma

Can confirm.

[Mod]Les3awe

@unknown, the Bedrock version of the shulker bullet will play an explodes sound when hitting the entity.

Avoma

I can confirm this in 1.18.1.

Here's a code analysis of this issue. The following is based on a decompiled version of Minecraft 1.18.1 using MCP-Reborn. 

Code Analysis:

net.minecraft.world.entity.projectile.ShulkerBullet.java

public class ShulkerBullet extends Projectile {
   ...
   protected void onHitEntity(EntityHitResult $ehr) {
      super.onHitEntity($ehr);
      Entity entity = $ehr.getEntity();
      Entity entity1 = this.getOwner();
      LivingEntity livingentity = entity1 instanceof LivingEntity ? (LivingEntity)entity1 : null;
      boolean flag = entity.hurt(DamageSource.indirectMobAttack(this, livingentity).setProjectile(), 4.0F);
      if (flag) {
         this.doEnchantDamageEffects(livingentity, entity);
         if (entity instanceof LivingEntity) {
            ((LivingEntity)entity).addEffect(new MobEffectInstance(MobEffects.LEVITATION, 200), MoreObjects.firstNonNull(entity1, this));
         }
      }

   }
   ...

If we look at the above class, we can see that no sound or particles are produced when a shulker bullet hits an entity, unlike hitting a block.

Potential Fix (tentative):

Simply adding some lines of code that will play a sound and produce some explosion particles when a shulker bullet hits an entity, should resolve this problem. The following lines of code could be used in order to fix this:

((ServerLevel)this.level).sendParticles(ParticleTypes.EXPLOSION, this.getX(), this.getY(), this.getZ(), 2, 0.2D, 0.2D, 0.2D, 0.0D);
this.playSound(SoundEvents.SHULKER_BULLET_HIT, 1.0F, 1.0F);

The correct piece of code within its class should look something like the following:

net.minecraft.world.entity.projectile.ShulkerBullet.java

public class ShulkerBullet extends Projectile {
   ...
   protected void onHitEntity(EntityHitResult $ehr) {
      super.onHitEntity($ehr);
      ((ServerLevel)this.level).sendParticles(ParticleTypes.EXPLOSION, this.getX(), this.getY(), this.getZ(), 2, 0.2D, 0.2D, 0.2D, 0.0D);
      this.playSound(SoundEvents.SHULKER_BULLET_HIT, 1.0F, 1.0F);
      Entity entity = $ehr.getEntity();
      Entity entity1 = this.getOwner();
      LivingEntity livingentity = entity1 instanceof LivingEntity ? (LivingEntity)entity1 : null;
      boolean flag = entity.hurt(DamageSource.indirectMobAttack(this, livingentity).setProjectile(), 4.0F);
      if (flag) {
         this.doEnchantDamageEffects(livingentity, entity);
         if (entity instanceof LivingEntity) {
            ((LivingEntity)entity).addEffect(new MobEffectInstance(MobEffects.LEVITATION, 200), MoreObjects.firstNonNull(entity1, this));
         }
      }

   }
   ...
Avoma

Can confirm in 1.18.2.

Jon1337

In 24w37a

[Mod]Les3awe

(Unassigned)

Confirmed

Parity, Particles, Projectiles, Sound

vanilla-parity

1.16.5, 1.17 Pre-release 5, 1.17 Release Candidate 1, 1.17 Release Candidate 2, 1.17, ..., 25w05a, 25w09b, 1.21.5 Release Candidate 1, 1.21.5, 25w17a

Retrieved