Skip to content

Commit

Permalink
Don't target invisible citizens. (ldtteam#8829)
Browse files Browse the repository at this point in the history
Prevents raiders and regular mobs from targeting invisible citizens.
This is mostly intended to avoid targeting a netherworker who is "away", but it seems reasonable to avoid targeting anyone affected by an invisibility potion too. (Perhaps a research could make druids do that deliberately in the future.)
  • Loading branch information
Raycoms committed Dec 24, 2022
1 parent 746bca8 commit 2d5ad35
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected PathResult moveInAttackPosition(final LivingEntity target)
@Override
protected boolean isAttackableTarget(final LivingEntity target)
{
return target instanceof EntityCitizen || (target instanceof Player && !((Player) target).isCreative() && !target.isSpectator());
return (target instanceof EntityCitizen && !target.isInvisible()) || (target instanceof Player && !((Player) target).isCreative() && !target.isSpectator());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected PathResult moveInAttackPosition(final LivingEntity target)
@Override
protected boolean isAttackableTarget(final LivingEntity target)
{
return target instanceof EntityCitizen || (target instanceof Player && !((Player) target).isCreative() && !target.isSpectator());
return (target instanceof EntityCitizen && !target.isInvisible()) || (target instanceof Player && !((Player) target).isCreative() && !target.isSpectator());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static void onEntityAdded(@NotNull final EntityJoinWorldEvent event)
.getType()
.is(ModTags.mobAttackBlacklist)))
{
((Mob) event.getEntity()).targetSelector.addGoal(6, new NearestAttackableTargetGoal<>((Mob) event.getEntity(), EntityCitizen.class, true));
((Mob) event.getEntity()).targetSelector.addGoal(6, new NearestAttackableTargetGoal<>((Mob) event.getEntity(), EntityCitizen.class, true, citizen -> !citizen.isInvisible()));
((Mob) event.getEntity()).targetSelector.addGoal(7, new NearestAttackableTargetGoal<>((Mob) event.getEntity(), EntityMercenary.class, true));
}
}
Expand Down

0 comments on commit 2d5ad35

Please sign in to comment.