Search in sources :

Example 1 with JobCook

use of com.minecolonies.coremod.colony.jobs.JobCook in project minecolonies by Minecolonies.

the class EntityAIWorkCook method checkForImportantJobs.

/**
 * Checks if the cook has anything important to do before going to the default furnace user jobs. First calculate the building range if not cached yet. Then check for citizens
 * around the building. If no citizen around switch to default jobs. If citizens around check if food in inventory, if not, switch to gather job. If food in inventory switch to
 * serve job.
 *
 * @return the next IAIState to transfer to.
 */
@Override
protected IAIState checkForImportantJobs() {
    // Clear the cache of current pending work
    this.reservedItemCache.clear();
    citizenToServe.clear();
    final List<AbstractEntityCitizen> citizenList = WorldUtil.getEntitiesWithinBuilding(world, AbstractEntityCitizen.class, building, null).stream().filter(cit -> !(cit.getCitizenJobHandler().getColonyJob() instanceof JobCook) && cit.shouldBeFed() && !InventoryUtils.hasItemInItemHandler(cit.getItemHandlerCitizen(), stack -> CAN_EAT.test(stack) && canEat(stack, cit))).sorted(Comparator.comparingInt(a -> (a.getCitizenJobHandler().getColonyJob() == null ? 1 : 0))).collect(Collectors.toList());
    final List<PlayerEntity> playerList = WorldUtil.getEntitiesWithinBuilding(world, PlayerEntity.class, building, player -> player != null && player.getFoodData().getFoodLevel() < LEVEL_TO_FEED_PLAYER && building.getColony().getPermissions().hasPermission(player, Action.MANAGE_HUTS));
    playerToServe.addAll(playerList);
    boolean hasFoodInBuilding = false;
    for (final AbstractEntityCitizen citizen : citizenList) {
        final Predicate<ItemStack> foodPredicate = stack -> ItemStackUtils.CAN_EAT.test(stack) && !isItemStackForAssistant(stack) && canEat(stack, citizen);
        if (InventoryUtils.hasItemInItemHandler(worker.getInventoryCitizen(), foodPredicate)) {
            citizenToServe.add(citizen);
        } else {
            if (InventoryUtils.hasItemInProvider(building, foodPredicate)) {
                hasFoodInBuilding = true;
                needsCurrently = new Tuple<>(foodPredicate, STACKSIZE);
            }
        }
    }
    if (!citizenToServe.isEmpty()) {
        return COOK_SERVE_FOOD_TO_CITIZEN;
    }
    if (hasFoodInBuilding) {
        return GATHERING_REQUIRED_MATERIALS;
    }
    return START_WORKING;
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) MESSAGE_INFO_CITIZEN_COOK_SERVE_PLAYER(com.minecolonies.api.util.constant.TranslationConstants.MESSAGE_INFO_CITIZEN_COOK_SERVE_PLAYER) java.util(java.util) BuildingCook(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingCook) JobCook(com.minecolonies.coremod.colony.jobs.JobCook) TypeToken(com.google.common.reflect.TypeToken) Action(com.minecolonies.api.colony.permissions.Action) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) FOOD_EXCLUSION_LIST(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingCook.FOOD_EXCLUSION_LIST) MinecoloniesAPIProxy(com.minecolonies.api.MinecoloniesAPIProxy) ItemStack(net.minecraft.item.ItemStack) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) IAIState(com.minecolonies.api.entity.ai.statemachine.states.IAIState) CAN_EAT(com.minecolonies.api.util.ItemStackUtils.CAN_EAT) AITarget(com.minecolonies.api.entity.ai.statemachine.AITarget) com.minecolonies.api.util(com.minecolonies.api.util) Constants(com.minecolonies.api.util.constant.Constants) ItemListModule(com.minecolonies.coremod.colony.buildings.modules.ItemListModule) TranslationConstants(com.minecolonies.api.util.constant.TranslationConstants) Entity(net.minecraft.entity.Entity) FURNACE_USER_NO_FOOD(com.minecolonies.api.util.constant.TranslationConstants.FURNACE_USER_NO_FOOD) Food(com.minecolonies.api.colony.requestsystem.requestable.Food) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Predicate(java.util.function.Predicate) IColonyManager(com.minecolonies.api.colony.IColonyManager) VisibleCitizenStatus(com.minecolonies.api.entity.citizen.VisibleCitizenStatus) ChatPriority(com.minecolonies.api.colony.interactionhandling.ChatPriority) StandardInteraction(com.minecolonies.coremod.colony.interactionhandling.StandardInteraction) BlockPos(net.minecraft.util.math.BlockPos) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) IRequestable(com.minecolonies.api.colony.requestsystem.requestable.IRequestable) AIWorkerState(com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState) Collectors(java.util.stream.Collectors) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStorage(com.minecolonies.api.crafting.ItemStorage) AbstractEntityAIUsesFurnace(com.minecolonies.coremod.entity.ai.basic.AbstractEntityAIUsesFurnace) NotNull(org.jetbrains.annotations.NotNull) AbstractEntityCitizen(com.minecolonies.api.entity.citizen.AbstractEntityCitizen) JobCook(com.minecolonies.coremod.colony.jobs.JobCook) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

TypeToken (com.google.common.reflect.TypeToken)1 MinecoloniesAPIProxy (com.minecolonies.api.MinecoloniesAPIProxy)1 IColonyManager (com.minecolonies.api.colony.IColonyManager)1 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)1 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)1 Action (com.minecolonies.api.colony.permissions.Action)1 Food (com.minecolonies.api.colony.requestsystem.requestable.Food)1 IRequestable (com.minecolonies.api.colony.requestsystem.requestable.IRequestable)1 ItemStorage (com.minecolonies.api.crafting.ItemStorage)1 AITarget (com.minecolonies.api.entity.ai.statemachine.AITarget)1 AIWorkerState (com.minecolonies.api.entity.ai.statemachine.states.AIWorkerState)1 IAIState (com.minecolonies.api.entity.ai.statemachine.states.IAIState)1 AbstractEntityCitizen (com.minecolonies.api.entity.citizen.AbstractEntityCitizen)1 VisibleCitizenStatus (com.minecolonies.api.entity.citizen.VisibleCitizenStatus)1 com.minecolonies.api.util (com.minecolonies.api.util)1 CAN_EAT (com.minecolonies.api.util.ItemStackUtils.CAN_EAT)1 Constants (com.minecolonies.api.util.constant.Constants)1 TranslationConstants (com.minecolonies.api.util.constant.TranslationConstants)1 FURNACE_USER_NO_FOOD (com.minecolonies.api.util.constant.TranslationConstants.FURNACE_USER_NO_FOOD)1 MESSAGE_INFO_CITIZEN_COOK_SERVE_PLAYER (com.minecolonies.api.util.constant.TranslationConstants.MESSAGE_INFO_CITIZEN_COOK_SERVE_PLAYER)1