Search in sources :

Example 1 with ThreatTable

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);
    }
}
Also used : net.minecraft.util(net.minecraft.util) IItemHandler(net.minecraftforge.items.IItemHandler) SittingEntity(com.minecolonies.coremod.entity.SittingEntity) LanguageHandler(com.ldtteam.structurize.util.LanguageHandler) com.minecolonies.coremod.entity.citizen.citizenhandlers(com.minecolonies.coremod.entity.citizen.citizenhandlers) Compatibility(com.minecolonies.api.compatibility.Compatibility) CompoundNBT(net.minecraft.nbt.CompoundNBT) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StandardFactoryController(com.minecolonies.api.colony.requestsystem.StandardFactoryController) com.minecolonies.api.entity.citizen.citizenhandlers(com.minecolonies.api.entity.citizen.citizenhandlers) ThreatTable(com.minecolonies.api.entity.combat.threat.ThreatTable) Status(com.minecolonies.api.entity.ai.Status) CustomGoalSelector(com.minecolonies.api.entity.CustomGoalSelector) ResearchConstants(com.minecolonies.api.research.util.ResearchConstants) ContainerCitizenInventory(com.minecolonies.api.inventory.container.ContainerCitizenInventory) StringTextComponent(net.minecraft.util.text.StringTextComponent) ModItems(com.minecolonies.api.items.ModItems) Network(com.minecolonies.coremod.Network) CitizenConstants(com.minecolonies.api.util.constant.CitizenConstants) Constants(com.minecolonies.api.util.constant.Constants) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) DesiredActivity(com.minecolonies.api.entity.ai.DesiredActivity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) EntityCitizenWalkToProxy(com.minecolonies.coremod.entity.pathfinding.EntityCitizenWalkToProxy) IThreatTableEntity(com.minecolonies.api.entity.combat.threat.IThreatTableEntity) Team(net.minecraft.scoreboard.Team) com.minecolonies.coremod.entity.ai.minimal(com.minecolonies.coremod.entity.ai.minimal) SwimGoal(net.minecraft.entity.ai.goal.SwimGoal) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) ITickRateStateMachine(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.ITickRateStateMachine) Capability(net.minecraftforge.common.capabilities.Capability) EntityAIInteractToggleAble(com.minecolonies.coremod.entity.ai.minimal.EntityAIInteractToggleAble) TeleportHelper(com.minecolonies.coremod.util.TeleportHelper) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EventType(com.minecolonies.api.sounds.EventType) LookAtWithoutMovingGoal(net.minecraft.entity.ai.goal.LookAtWithoutMovingGoal) Vector3d(net.minecraft.util.math.vector.Vector3d) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) MineColonies(com.minecolonies.coremod.MineColonies) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) LocalDate(java.time.LocalDate) IGuardBuilding(com.minecolonies.api.colony.buildings.IGuardBuilding) IState(com.minecolonies.api.entity.ai.statemachine.states.IState) com.minecolonies.coremod.colony.jobs(com.minecolonies.coremod.colony.jobs) ShieldItem(net.minecraft.item.ShieldItem) NotNull(org.jetbrains.annotations.NotNull) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) java.util(java.util) IPermissions(com.minecolonies.api.colony.permissions.IPermissions) OpenInventoryMessage(com.minecolonies.coremod.network.messages.server.colony.OpenInventoryMessage) Container(net.minecraft.inventory.container.Container) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TickingTransition(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickingTransition) NameTagItem(net.minecraft.item.NameTagItem) Action(com.minecolonies.api.colony.permissions.Action) ITextComponent(net.minecraft.util.text.ITextComponent) LazyOptional(net.minecraftforge.common.util.LazyOptional) ItemStack(net.minecraft.item.ItemStack) LookAtGoal(net.minecraft.entity.ai.goal.LookAtGoal) EffectInstance(net.minecraft.potion.EffectInstance) Attributes(net.minecraft.entity.ai.attributes.Attributes) net.minecraft.entity(net.minecraft.entity) com.minecolonies.api.util(com.minecolonies.api.util) INCREMENT_AND_DECREMENT_OPERATORS_SHOULD_NOT_BE_USED_IN_A_METHOD_CALL_OR_MIXED_WITH_OTHER_OPERATORS_IN_AN_EXPRESSION(com.minecolonies.api.util.constant.Suppression.INCREMENT_AND_DECREMENT_OPERATORS_SHOULD_NOT_BE_USED_IN_A_METHOD_CALL_OR_MIXED_WITH_OTHER_OPERATORS_IN_AN_EXPRESSION) com.minecolonies.api.colony(com.minecolonies.api.colony) TickRateStateMachine(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateStateMachine) Effects(net.minecraft.potion.Effects) PlayerInventory(net.minecraft.entity.player.PlayerInventory) AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) AbstractEntityAIGuard(com.minecolonies.coremod.entity.ai.citizen.guard.AbstractEntityAIGuard) IWalkToProxy(com.minecolonies.api.entity.ai.pathfinding.IWalkToProxy) Month(java.time.Month) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) World(net.minecraft.world.World) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) BlockPos(net.minecraft.util.math.BlockPos) MovementHandler(com.minecolonies.coremod.entity.pathfinding.MovementHandler) PathResult(com.minecolonies.api.entity.pathfinding.PathResult) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) InventoryCitizen(com.minecolonies.api.inventory.InventoryCitizen) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) Clock(java.time.Clock) CitizenDiedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent) ItemEntity(net.minecraft.entity.item.ItemEntity) IJob(com.minecolonies.api.colony.jobs.IJob) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) AbstractEntityAIGuard(com.minecolonies.coremod.entity.ai.citizen.guard.AbstractEntityAIGuard) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ThreatTable(com.minecolonies.api.entity.combat.threat.ThreatTable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen)

Example 2 with ThreatTable

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);
    }
}
Also used : net.minecraft.util(net.minecraft.util) IItemHandler(net.minecraftforge.items.IItemHandler) SittingEntity(com.minecolonies.coremod.entity.SittingEntity) com.minecolonies.coremod.entity.citizen.citizenhandlers(com.minecolonies.coremod.entity.citizen.citizenhandlers) Compatibility(com.minecolonies.api.compatibility.Compatibility) CompoundNBT(net.minecraft.nbt.CompoundNBT) StandardFactoryController(com.minecolonies.api.colony.requestsystem.StandardFactoryController) com.minecolonies.api.entity.citizen.citizenhandlers(com.minecolonies.api.entity.citizen.citizenhandlers) ThreatTable(com.minecolonies.api.entity.combat.threat.ThreatTable) Status(com.minecolonies.api.entity.ai.Status) CustomGoalSelector(com.minecolonies.api.entity.CustomGoalSelector) ResearchConstants(com.minecolonies.api.research.util.ResearchConstants) ContainerCitizenInventory(com.minecolonies.api.inventory.container.ContainerCitizenInventory) ModItems(com.minecolonies.api.items.ModItems) Network(com.minecolonies.coremod.Network) CitizenConstants(com.minecolonies.api.util.constant.CitizenConstants) Constants(com.minecolonies.api.util.constant.Constants) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) DesiredActivity(com.minecolonies.api.entity.ai.DesiredActivity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) EntityCitizenWalkToProxy(com.minecolonies.coremod.entity.pathfinding.EntityCitizenWalkToProxy) Skill(com.minecolonies.api.entity.citizen.Skill) IThreatTableEntity(com.minecolonies.api.entity.combat.threat.IThreatTableEntity) Team(net.minecraft.scoreboard.Team) com.minecolonies.coremod.entity.ai.minimal(com.minecolonies.coremod.entity.ai.minimal) SwimGoal(net.minecraft.entity.ai.goal.SwimGoal) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) ITickRateStateMachine(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.ITickRateStateMachine) Capability(net.minecraftforge.common.capabilities.Capability) EntityAIInteractToggleAble(com.minecolonies.coremod.entity.ai.minimal.EntityAIInteractToggleAble) TeleportHelper(com.minecolonies.coremod.util.TeleportHelper) Nullable(org.jetbrains.annotations.Nullable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) EventType(com.minecolonies.api.sounds.EventType) LookAtWithoutMovingGoal(net.minecraft.entity.ai.goal.LookAtWithoutMovingGoal) Vector3d(net.minecraft.util.math.vector.Vector3d) WorkerBuildingModule(com.minecolonies.coremod.colony.buildings.modules.WorkerBuildingModule) MineColonies(com.minecolonies.coremod.MineColonies) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) LocalDate(java.time.LocalDate) IGuardBuilding(com.minecolonies.api.colony.buildings.IGuardBuilding) IState(com.minecolonies.api.entity.ai.statemachine.states.IState) com.minecolonies.coremod.colony.jobs(com.minecolonies.coremod.colony.jobs) ShieldItem(net.minecraft.item.ShieldItem) NotNull(org.jetbrains.annotations.NotNull) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) net.minecraft.util.text(net.minecraft.util.text) java.util(java.util) IPermissions(com.minecolonies.api.colony.permissions.IPermissions) OpenInventoryMessage(com.minecolonies.coremod.network.messages.server.colony.OpenInventoryMessage) Container(net.minecraft.inventory.container.Container) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) TickingTransition(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickingTransition) NameTagItem(net.minecraft.item.NameTagItem) ItemParticleEffectMessage(com.minecolonies.coremod.network.messages.client.ItemParticleEffectMessage) ISFOOD(com.minecolonies.api.util.ItemStackUtils.ISFOOD) Action(com.minecolonies.api.colony.permissions.Action) LazyOptional(net.minecraftforge.common.util.LazyOptional) AbstractEntityAIBasic(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIBasic) ItemStack(net.minecraft.item.ItemStack) LookAtGoal(net.minecraft.entity.ai.goal.LookAtGoal) EffectInstance(net.minecraft.potion.EffectInstance) Attributes(net.minecraft.entity.ai.attributes.Attributes) net.minecraft.entity(net.minecraft.entity) com.minecolonies.api.util(com.minecolonies.api.util) INCREMENT_AND_DECREMENT_OPERATORS_SHOULD_NOT_BE_USED_IN_A_METHOD_CALL_OR_MIXED_WITH_OTHER_OPERATORS_IN_AN_EXPRESSION(com.minecolonies.api.util.constant.Suppression.INCREMENT_AND_DECREMENT_OPERATORS_SHOULD_NOT_BE_USED_IN_A_METHOD_CALL_OR_MIXED_WITH_OTHER_OPERATORS_IN_AN_EXPRESSION) com.minecolonies.api.colony(com.minecolonies.api.colony) TickRateStateMachine(com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateStateMachine) Effects(net.minecraft.potion.Effects) PlayerInventory(net.minecraft.entity.player.PlayerInventory) AbstractBuildingGuards(com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards) AbstractEntityAIGuard(com.minecolonies.coremod.entity.ai.citizen.guard.AbstractEntityAIGuard) IWalkToProxy(com.minecolonies.api.entity.ai.pathfinding.IWalkToProxy) Month(java.time.Month) ILocation(com.minecolonies.api.colony.requestsystem.location.ILocation) World(net.minecraft.world.World) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) BlockPos(net.minecraft.util.math.BlockPos) Items(net.minecraft.item.Items) VanillaParticleMessage(com.minecolonies.coremod.network.messages.client.VanillaParticleMessage) MovementHandler(com.minecolonies.coremod.entity.pathfinding.MovementHandler) ParticleTypes(net.minecraft.particles.ParticleTypes) PathResult(com.minecolonies.api.entity.pathfinding.PathResult) TypeConstants(com.minecolonies.api.util.constant.TypeConstants) InventoryCitizen(com.minecolonies.api.inventory.InventoryCitizen) EquipmentSlotType(net.minecraft.inventory.EquipmentSlotType) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) NbtTagConstants(com.minecolonies.api.util.constant.NbtTagConstants) Clock(java.time.Clock) CitizenDiedEvent(com.minecolonies.coremod.colony.colonyEvents.citizenEvents.CitizenDiedEvent) ItemEntity(net.minecraft.entity.item.ItemEntity) IJob(com.minecolonies.api.colony.jobs.IJob) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) AbstractEntityAIGuard(com.minecolonies.coremod.entity.ai.citizen.guard.AbstractEntityAIGuard) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) ThreatTable(com.minecolonies.api.entity.combat.threat.ThreatTable) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen)

Aggregations

com.minecolonies.api.colony (com.minecolonies.api.colony)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 IGuardBuilding (com.minecolonies.api.colony.buildings.IGuardBuilding)2 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)2 IJob (com.minecolonies.api.colony.jobs.IJob)2 Action (com.minecolonies.api.colony.permissions.Action)2 IPermissions (com.minecolonies.api.colony.permissions.IPermissions)2 StandardFactoryController (com.minecolonies.api.colony.requestsystem.StandardFactoryController)2 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 Compatibility (com.minecolonies.api.compatibility.Compatibility)2 CustomGoalSelector (com.minecolonies.api.entity.CustomGoalSelector)2 DesiredActivity (com.minecolonies.api.entity.ai.DesiredActivity)2 Status (com.minecolonies.api.entity.ai.Status)2 IWalkToProxy (com.minecolonies.api.entity.ai.pathfinding.IWalkToProxy)2 IState (com.minecolonies.api.entity.ai.statemachine.states.IState)2 ITickRateStateMachine (com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.ITickRateStateMachine)2 TickRateStateMachine (com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickRateStateMachine)2 TickingTransition (com.minecolonies.api.entity.ai.statemachine.tickratestatemachine.TickingTransition)2 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)2 VisibleCitizenStatus (com.minecolonies.api.entity.citizen.VisibleCitizenStatus)2