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;
}
Aggregations