Difficulty diff = event.getEntity().getWorld().getDifficulty();
if (event.getReason() != TargetReason.CLOSEST_PLAYER && event.getReason() != TargetReason.RANDOM_TARGET)
return; // Just making sure
LivingEntity enemy = (LivingEntity) event.getEntity();
if (event.getTarget() instanceof Player && !enemy.hasLineOfSight(event.getTarget())) // the target.
if (!((Player) event.getTarget()).isSprinting()) {
CraftBookPlugin.logDebugMessage("Disabling entity target - Player is not visible.", "ai-mechanics.entity-target.vision");
event.setCancelled(true);
return;
}
if (event.getTarget().getLocation().getBlock().getLightLevel() > (diff == Difficulty.HARD ? 4 : 6) && enemy.hasLineOfSight(event.getTarget())) return; // They can clearly see the target.
if (event.getTarget() instanceof Player)
if (((Player) event.getTarget()).isSneaking()) {
int distance = (int) Math.floor(event.getTarget().getLocation().distanceSquared(enemy.getLocation()));
if (distance != 0 && CraftBookPlugin.inst().getRandom().nextInt(distance) > (diff == Difficulty.HARD ? 4 : 2)) {
CraftBookPlugin.logDebugMessage("Disabling entity target - Player is sneaking.", "ai-mechanics.entity-target.vision");
event.setCancelled(true);
}
}