use of com.minecolonies.api.entity.combat.threat.ThreatTable in project minecolonies by ldtteam.
the class EntityCitizen method callForHelp.
@Override
public void callForHelp(final Entity attacker, final int guardHelpRange) {
if (!(attacker instanceof LivingEntity) || !MineColonies.getConfig().getServer().citizenCallForHelp.get() || callForHelpCooldown != 0) {
return;
}
// Don't call for help when a guard gets woken up
if (citizenJobHandler.getColonyJob() instanceof AbstractJobGuard && citizenJobHandler.getColonyJob(AbstractJobGuard.class).isAsleep()) {
return;
}
callForHelpCooldown = CALL_HELP_CD;
List<AbstractEntityCitizen> possibleGuards = new ArrayList<>();
for (final ICitizenData entry : getCitizenColonyHandler().getColony().getCitizenManager().getCitizens()) {
if (entry.getEntity().isPresent()) {
// Checking for guard nearby
if (entry.getJob() instanceof AbstractJobGuard && entry.getId() != citizenData.getId() && BlockPosUtil.getDistanceSquared(entry.getEntity().get().blockPosition(), blockPosition()) < guardHelpRange && entry.getJob().getWorkerAI() != null) {
final ThreatTable table = ((EntityCitizen) entry.getEntity().get()).getThreatTable();
table.addThreat((LivingEntity) attacker, 0);
if (((AbstractEntityAIGuard<?, ?>) entry.getJob().getWorkerAI()).canHelp()) {
possibleGuards.add(entry.getEntity().get());
}
}
}
}
Collections.sort(possibleGuards, Comparator.comparingInt(guard -> (int) blockPosition().distSqr(guard.blockPosition())));
for (int i = 0; i < possibleGuards.size() && i <= CALL_TO_HELP_AMOUNT; i++) {
((AbstractEntityAIGuard<?, ?>) possibleGuards.get(i).getCitizenData().getJob().getWorkerAI()).startHelpCitizen((LivingEntity) attacker);
}
}
use of com.minecolonies.api.entity.combat.threat.ThreatTable in project minecolonies by Minecolonies.
the class EntityCitizen method callForHelp.
@Override
public void callForHelp(final Entity attacker, final int guardHelpRange) {
if (!(attacker instanceof LivingEntity) || !MineColonies.getConfig().getServer().citizenCallForHelp.get() || callForHelpCooldown != 0) {
return;
}
// Don't call for help when a guard gets woken up
if (citizenJobHandler.getColonyJob() instanceof AbstractJobGuard && citizenJobHandler.getColonyJob(AbstractJobGuard.class).isAsleep()) {
return;
}
callForHelpCooldown = CALL_HELP_CD;
List<AbstractEntityCitizen> possibleGuards = new ArrayList<>();
for (final ICitizenData entry : getCitizenColonyHandler().getColony().getCitizenManager().getCitizens()) {
if (entry.getEntity().isPresent()) {
// Checking for guard nearby
if (entry.getJob() instanceof AbstractJobGuard && entry.getId() != citizenData.getId() && BlockPosUtil.getDistanceSquared(entry.getEntity().get().blockPosition(), blockPosition()) < guardHelpRange && entry.getJob().getWorkerAI() != null) {
final ThreatTable table = ((EntityCitizen) entry.getEntity().get()).getThreatTable();
table.addThreat((LivingEntity) attacker, 0);
if (((AbstractEntityAIGuard<?, ?>) entry.getJob().getWorkerAI()).canHelp()) {
possibleGuards.add(entry.getEntity().get());
}
}
}
}
Collections.sort(possibleGuards, Comparator.comparingInt(guard -> (int) blockPosition().distSqr(guard.blockPosition())));
for (int i = 0; i < possibleGuards.size() && i <= CALL_TO_HELP_AMOUNT; i++) {
((AbstractEntityAIGuard<?, ?>) possibleGuards.get(i).getCitizenData().getJob().getWorkerAI()).startHelpCitizen((LivingEntity) attacker);
}
}
Aggregations