The Bug:
Snow golems attack creepers.
Steps to Reproduce:
Summon a snow golem and a creeper by using the commands provided below.
/summon minecraft:snow_golem ~-3 ~ ~
/summon minecraft:creeper ~3 ~ ~
Wait around ten seconds or so for the snow golem to notice the creeper.
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
is duplicated by 2
relates to 1
Attachments
Comments 68
Regression of (and relates to) MC-61844
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.