mojira.dev

The Bug:

Snow golems attack creepers.

Steps to Reproduce:

  1. Summon a snow golem and a creeper by using the commands provided below.

    /summon minecraft:snow_golem ~-3 ~ ~
    /summon minecraft:creeper ~3 ~ ~
  2. Wait around ten seconds or so for the snow golem to notice the creeper.

  3. Take note as to whether or not snow golems attack creepers.

Observed Behavior:

Snow golems attack creepers.

Expected Behavior:

Snow golems would not be able to attack creepers.

Code Analysis:

Code analysis by @unknown can be found below.

The following is based on a decompiled version of Minecraft 1.19.2 using MCP-Reborn.

net.minecraft.world.entity.animal.SnowGolem.java

public class SnowGolem extends AbstractGolem implements Shearable, RangedAttackMob {
   ...
   protected void registerGoals() {
      ...
      this.targetSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, Mob.class, 10, true, false, (livingEntity) -> {
         return livingEntity instanceof Enemy;
      }));
   }
   ...

If we look at the above class, we can see that snow golems are designed to attack any living entity that is considered an enemy. A creeper is considered a monster and a monster is considered an enemy, therefore allowing snow golems to attack creepers. The game doesn't check if the said entity is a creeper before allowing a snow golem to attack it, therefore resulting in this problem occurring.

Fix:

Simply allowing snow golems to override the canAttackType() method located within the Mob.java class to make it so that they cannot attack creepers will resolve this problem. The following lines of code can be added somewhere within the SnowGolem.java class to fix this issue.

Fixed Code:

public boolean canAttackType(EntityType<?> entityType) {
   return entityType != EntityType.CREEPER && super.canAttackType(entityType);
}

Linked issues

Attachments

Comments 68

Iron Golems do actually attack Creepers occasionally, but I agree that Snow Golems shouldn't attack Creepers since they can't kill/damage them anyway.

I think it's fine that Snow Golems attack Creepers in general, but in creative mode...

Lucas, that talks only about iron golems.

@Sonic: Well then only relates to.

58 more comments

In 1.20.2 Pre-Release 2

Can confirm in 1.20.5 RC2.

Can confirm in 1.20.5.

Earthcomputer

Avoma

(Unassigned)

Confirmed

Gameplay

Normal

Mob behaviour

creeper, snow_golem

Minecraft 1.8, Minecraft 1.8.8, Minecraft 15w43a, Minecraft 1.9, Minecraft 1.9.1 Pre-Release 1, ..., 1.21.3, 1.21.4, 25w08a, 1.21.5, 1.21.6

Retrieved