Search in sources :

Example 1 with MESSAGE_INFO_CITIZEN_COOK_SERVE_PLAYER

use of com.minecolonies.api.util.constant.TranslationConstants.MESSAGE_INFO_CITIZEN_COOK_SERVE_PLAYER in project minecolonies by Minecolonies.

the class EntityAIWorkCook method serveFoodToCitizen.

/**
 * Serve food to customer
 * <p>
 * If no customer, transition to START_WORKING. If we need to walk to the customer, repeat this state with tiny delay. If the customer has a full inventory, report and remove
 * customer, delay and repeat this state. If we have food, then COOK_SERVE. If no food in the building, transition to START_WORKING. If we were able to get the stored food,
 * then COOK_SERVE. If food is no longer available, delay and transition to START_WORKING. Otherwise, give the customer some food, then delay and repeat this state.
 *
 * @return next IAIState
 */
private IAIState serveFoodToCitizen() {
    worker.getCitizenStatusHandler().setLatestStatus(new TranslationTextComponent(TranslationConstants.COM_MINECOLONIES_COREMOD_STATUS_SERVING));
    if (citizenToServe.isEmpty() && playerToServe.isEmpty()) {
        return START_WORKING;
    }
    worker.getCitizenData().setVisibleStatus(COOK);
    final Entity living = citizenToServe.isEmpty() ? playerToServe.get(0) : citizenToServe.get(0);
    if (!building.isInBuilding(living.blockPosition())) {
        worker.getNavigation().stop();
        removeFromQueue();
        return START_WORKING;
    }
    if (walkToBlock(new BlockPos(living.position()))) {
        return getState();
    }
    final IItemHandler handler = citizenToServe.isEmpty() ? new InvWrapper(playerToServe.get(0).inventory) : citizenToServe.get(0).getInventoryCitizen();
    if (InventoryUtils.isItemHandlerFull(handler)) {
        if (!citizenToServe.isEmpty()) {
            final int foodSlot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getInventoryCitizen(), stack -> ItemStackUtils.CAN_EAT.test(stack) && canEat(stack, citizenToServe.isEmpty() ? null : citizenToServe.get(0)));
            if (foodSlot != -1) {
                final ItemStack stack = worker.getInventoryCitizen().extractItem(foodSlot, 1, false);
                if (stack.getItem().isEdible()) {
                    citizenToServe.get(0).getCitizenData().increaseSaturation(stack.getItem().getFoodProperties().getNutrition() / 2.0);
                }
            }
        }
        removeFromQueue();
        return getState();
    } else if (InventoryUtils.hasItemInItemHandler(handler, stack -> CAN_EAT.test(stack) && canEat(stack, citizenToServe.isEmpty() ? null : citizenToServe.get(0)))) {
        removeFromQueue();
        return getState();
    }
    if (!InventoryUtils.transferFoodUpToSaturation(worker, handler, building.getBuildingLevel() * SATURATION_TO_SERVE, stack -> CAN_EAT.test(stack) && canEat(stack, citizenToServe.isEmpty() ? null : citizenToServe.get(0)))) {
        removeFromQueue();
        return getState();
    }
    if (!citizenToServe.isEmpty() && citizenToServe.get(0).getCitizenData() != null) {
        citizenToServe.get(0).getCitizenData().setJustAte(true);
    }
    if (citizenToServe.isEmpty() && living instanceof PlayerEntity) {
        MessageUtils.format(MESSAGE_INFO_CITIZEN_COOK_SERVE_PLAYER, worker.getName().getString()).sendTo((PlayerEntity) living);
    }
    removeFromQueue();
    worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
    this.incrementActionsDoneAndDecSaturation();
    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) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) FurnaceTileEntity(net.minecraft.tileentity.FurnaceTileEntity) IItemHandler(net.minecraftforge.items.IItemHandler) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) 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