Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-73964

Snow golems attack creepers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 1.8, Minecraft 1.8.8, Minecraft 15w43a, Minecraft 1.9, Minecraft 1.9.1 Pre-Release 1, Minecraft 1.9.1 Pre-Release 2, Minecraft 1.9.1 Pre-Release 3, Minecraft 1.9.4, Minecraft 16w21a, Minecraft 1.10.2, Minecraft 16w32a, Minecraft 16w32b, Minecraft 16w33a, Minecraft 1.11.2, Minecraft 17w06a, Minecraft 1.12 Pre-Release 2, Minecraft 1.12.2, Minecraft 18w16a, Minecraft 1.13, Minecraft 18w30b, Minecraft 1.13.2, Minecraft 18w43b, Minecraft 18w43c, Minecraft 18w44a, Minecraft 18w45a, Minecraft 18w48a, Minecraft 18w48b, Minecraft 18w49a, Minecraft 18w50a, Minecraft 19w08b, Minecraft 19w09a, 1.14.4, 19w34a, 19w44a, 1.15 Pre-release 1, 1.15.2, 20w12a, 20w13b, 20w15a, 20w17a, 20w19a, 20w20b, 20w21a, 20w22a, 1.16 Pre-release 3, 1.16 Pre-release 5, 1.16.2, 1.16.3 Release Candidate 1, 1.16.3, 1.16.4 Pre-release 2, 20w46a, 20w48a, 20w51a, 21w03a, 1.16.5, 21w05b, 21w06a, 21w07a, 21w08b, 21w11a, 21w17a, 21w20a, 1.17 Pre-release 1, 1.17 Pre-release 3, 1.17 Pre-release 4, 1.17 Pre-release 5, 1.17 Release Candidate 1, 1.17 Release Candidate 2, 1.17, 1.17.1 Pre-release 1, 1.17.1 Pre-release 2, 1.17.1 Pre-release 3, 1.17.1 Release Candidate 1, 1.17.1 Release Candidate 2, 1.17.1, 21w38a, 21w39a, 21w40a, 21w41a, 21w42a, 21w43a, 21w44a, 1.18 Pre-release 1, 1.18 Pre-release 7, 1.18, 1.18.1, 22w03a, 22w05a, 22w06a, 22w07a, 1.18.2 Release Candidate 1, 1.18.2, 22w12a, 22w14a, 22w17a, 22w18a, 1.19, 1.19.1, 1.19.2, 22w42a, 22w43a, 1.19.3, 1.19.4, 1.20, 1.20.1, 1.20.2 Pre-release 2, 1.20.4, 23w51b, 24w11a
    • Confirmed
    • Mob behaviour
    • Normal
    • Gameplay

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

        1. 2014-11-02_16.18.37.png
          2014-11-02_16.18.37.png
          99 kB
        2. 2014-11-02_16.31.41.png
          2014-11-02_16.31.41.png
          225 kB
        3. 2014-11-02_16.32.48.png
          2014-11-02_16.32.48.png
          236 kB
        4. 2015-09-02_15.53.36.png
          2015-09-02_15.53.36.png
          453 kB
        5. MC-73964.mp4
          4.24 MB
        6. MC-73964 - Fixed Code.png
          MC-73964 - Fixed Code.png
          12 kB

            Unassigned Unassigned
            Avoma [Mod] Avoma
            Votes:
            55 Vote for this issue
            Watchers:
            25 Start watching this issue

              Created:
              Updated:
              CHK: