Search in sources :

Example 1 with IJob

use of com.minecolonies.api.colony.jobs.IJob in project minecolonies by ldtteam.

the class CitizenJobHandler method onJobChanged.

/**
 * Defines job changes and state changes of the citizen.
 *
 * @param job the set job.
 */
@Override
public void onJobChanged(@Nullable final IJob<?> job) {
    // Model
    setModelDependingOnJob(job);
    // AI Tasks
    for (@NotNull final PrioritizedGoal task : new ArrayList<>(citizen.getTasks().availableGoals)) {
        if (task.getGoal() instanceof AbstractAISkeleton) {
            citizen.getTasks().removeGoal(task.getGoal());
        }
    }
    citizen.getCitizenData().setIdleAtJob(false);
    if (job != null) {
        job.addWorkerAIToTaskList(citizen.getTasks());
        if (citizen.getTicksExisted() > 0 && citizen.getCitizenColonyHandler().getWorkBuilding() != null && citizen.getDesiredActivity() == DesiredActivity.WORK) {
            BlockPosUtil.tryMoveBaseCitizenEntityToXYZ(citizen, citizen.getCitizenColonyHandler().getWorkBuilding().getPosition());
        }
        // Calculate the number of guards for some advancements
        if (job instanceof AbstractJobGuard) {
            IColony colony = citizen.getCitizenColonyHandler().getColony();
            int guards = ((int) colony.getCitizenManager().getCitizens().stream().filter(citizen -> citizen.getJob() instanceof AbstractJobGuard).count());
            AdvancementUtils.TriggerAdvancementPlayersForColony(citizen.getCitizenColonyHandler().getColony(), player -> AdvancementTriggers.ARMY_POPULATION.trigger(player, guards));
        }
        job.initEntityValues(citizen);
    }
}
Also used : ModModelTypes(com.minecolonies.api.client.render.modeltype.ModModelTypes) DesiredActivity(com.minecolonies.api.entity.ai.DesiredActivity) AdvancementUtils(com.minecolonies.coremod.util.AdvancementUtils) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) ArrayList(java.util.ArrayList) DATA_MODEL(com.minecolonies.api.entity.citizen.AbstractEntityCitizen.DATA_MODEL) Nullable(org.jetbrains.annotations.Nullable) AdvancementTriggers(com.minecolonies.api.advancements.AdvancementTriggers) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) AbstractAISkeleton(com.minecolonies.coremod.entity.ai.basic.AbstractAISkeleton) IColony(com.minecolonies.api.colony.IColony) ICitizenJobHandler(com.minecolonies.api.entity.citizen.citizenhandlers.ICitizenJobHandler) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) NotNull(org.jetbrains.annotations.NotNull) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) IJob(com.minecolonies.api.colony.jobs.IJob) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) AbstractAISkeleton(com.minecolonies.coremod.entity.ai.basic.AbstractAISkeleton) ArrayList(java.util.ArrayList) IColony(com.minecolonies.api.colony.IColony) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with IJob

use of com.minecolonies.api.colony.jobs.IJob in project minecolonies by Minecolonies.

the class CitizenJobHandler method onJobChanged.

/**
 * Defines job changes and state changes of the citizen.
 *
 * @param job the set job.
 */
@Override
public void onJobChanged(@Nullable final IJob<?> job) {
    // Model
    setModelDependingOnJob(job);
    // AI Tasks
    for (@NotNull final PrioritizedGoal task : new ArrayList<>(citizen.getTasks().availableGoals)) {
        if (task.getGoal() instanceof AbstractAISkeleton) {
            citizen.getTasks().removeGoal(task.getGoal());
        }
    }
    citizen.getCitizenData().setIdleAtJob(false);
    if (job != null) {
        job.addWorkerAIToTaskList(citizen.getTasks());
        if (citizen.getTicksExisted() > 0 && citizen.getCitizenColonyHandler().getWorkBuilding() != null && citizen.getDesiredActivity() == DesiredActivity.WORK) {
            BlockPosUtil.tryMoveBaseCitizenEntityToXYZ(citizen, citizen.getCitizenColonyHandler().getWorkBuilding().getPosition());
        }
        // Calculate the number of guards for some advancements
        if (job instanceof AbstractJobGuard) {
            IColony colony = citizen.getCitizenColonyHandler().getColony();
            int guards = ((int) colony.getCitizenManager().getCitizens().stream().filter(citizen -> citizen.getJob() instanceof AbstractJobGuard).count());
            AdvancementUtils.TriggerAdvancementPlayersForColony(citizen.getCitizenColonyHandler().getColony(), player -> AdvancementTriggers.ARMY_POPULATION.trigger(player, guards));
        }
        job.initEntityValues(citizen);
    }
}
Also used : ModModelTypes(com.minecolonies.api.client.render.modeltype.ModModelTypes) DesiredActivity(com.minecolonies.api.entity.ai.DesiredActivity) AdvancementUtils(com.minecolonies.coremod.util.AdvancementUtils) BlockPosUtil(com.minecolonies.api.util.BlockPosUtil) ArrayList(java.util.ArrayList) DATA_MODEL(com.minecolonies.api.entity.citizen.AbstractEntityCitizen.DATA_MODEL) Nullable(org.jetbrains.annotations.Nullable) AdvancementTriggers(com.minecolonies.api.advancements.AdvancementTriggers) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) AbstractAISkeleton(com.minecolonies.coremod.entity.ai.basic.AbstractAISkeleton) IColony(com.minecolonies.api.colony.IColony) ICitizenJobHandler(com.minecolonies.api.entity.citizen.citizenhandlers.ICitizenJobHandler) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) NotNull(org.jetbrains.annotations.NotNull) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) IJob(com.minecolonies.api.colony.jobs.IJob) AbstractJobGuard(com.minecolonies.coremod.colony.jobs.AbstractJobGuard) AbstractAISkeleton(com.minecolonies.coremod.entity.ai.basic.AbstractAISkeleton) ArrayList(java.util.ArrayList) IColony(com.minecolonies.api.colony.IColony) PrioritizedGoal(net.minecraft.entity.ai.goal.PrioritizedGoal) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

AdvancementTriggers (com.minecolonies.api.advancements.AdvancementTriggers)2 ModModelTypes (com.minecolonies.api.client.render.modeltype.ModModelTypes)2 IColony (com.minecolonies.api.colony.IColony)2 IJob (com.minecolonies.api.colony.jobs.IJob)2 DesiredActivity (com.minecolonies.api.entity.ai.DesiredActivity)2 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)2 DATA_MODEL (com.minecolonies.api.entity.citizen.AbstractEntityCitizen.DATA_MODEL)2 ICitizenJobHandler (com.minecolonies.api.entity.citizen.citizenhandlers.ICitizenJobHandler)2 BlockPosUtil (com.minecolonies.api.util.BlockPosUtil)2 AbstractJobGuard (com.minecolonies.coremod.colony.jobs.AbstractJobGuard)2 AbstractAISkeleton (com.minecolonies.coremod.entity.ai.basic.AbstractAISkeleton)2 AdvancementUtils (com.minecolonies.coremod.util.AdvancementUtils)2 ArrayList (java.util.ArrayList)2 PrioritizedGoal (net.minecraft.entity.ai.goal.PrioritizedGoal)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2