The bug
Vindicators named "Johnny" don't attack ghasts.
Expected Result
Vindicators named "Johnny" would attack ghasts, as they attack every other living entity except armor stands (and baby villagers).
How to reproduce
/summon minecraft:ghast ~10 ~3 ~ {NoAI:1b,Silent:1b}
/summon minecraft:vindicator ~ ~ ~ {Johnny:1b}
Code analysis
Code analysis can be found in this comment.
Linked issues
relates to 1
Attachments
Comments 14
Can confirm in 1.18.2 and 22w12a. You can use the following commands to reproduce this issue.
/summon minecraft:ghast ~10 ~3 ~ {NoAI:1b,Silent:1b}
/summon minecraft:vindicator ~ ~ ~ {Johnny:1b}
Code analysis (Mojang mappings, 22w12a):
This is a tentative analysis, but it seems very reasonable by having looked at the code.
The code for Johnny vindicator attacking is found in Vindicator.VindicatorJohnnyAttackGoal
, which extends NearestAttackableTargetGoal<LivingEntity>
. In NearestAttackableTargetGoal#canUse(...)
, the function findTarget(...)
is called, which uses EntityGetter#getNearestEntity(...)
. This takes the mob's targeting conditions (this.targetConditions
) as a parameter and tests them by calling TargetingConditions#test(...)
. If the test fails, the entity is not returned.
In TargetingConditions#test(...)
, there is the following code:
Mob $$5;
if (this.isCombat && (!$$0.canAttack($$1) || !$$0.canAttackType($$1.getType()) || $$0.isAlliedTo($$1))) {
return false;
}
So the test fails, specifically, if canAttackType(EntityType)
returns false
. If we look at Mob#canAttackType(EntityType)
:
@Override
public boolean canAttackType(EntityType<?> $$0) {
return $$0 != EntityType.GHAST;
}
This returns false
if the entity is a ghast. As the target entity would be a ghast, the test fails, so the vindicator cannot attack ghasts. This might also be the cause of MC-235353, but I am not sure.
Can confirm in 20w51a.