use of com.minecolonies.api.colony.requestsystem.requestable.Food in project minecolonies by ldtteam.
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 (!getOwnBuilding().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, getOwnBuilding().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) {
LanguageHandler.sendPlayerMessage((PlayerEntity) living, "com.minecolonies.coremod.cook.serve.player", worker.getName().getString());
}
removeFromQueue();
worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN);
this.incrementActionsDoneAndDecSaturation();
return START_WORKING;
}
use of com.minecolonies.api.colony.requestsystem.requestable.Food 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;
}
use of com.minecolonies.api.colony.requestsystem.requestable.Food 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;
}
use of com.minecolonies.api.colony.requestsystem.requestable.Food in project minecolonies by Minecolonies.
the class EntityAIWorkCook method getSmeltAbleClass.
@Override
protected IRequestable getSmeltAbleClass() {
final List<ItemStorage> blockedItems = new ArrayList<>(building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(FOOD_EXCLUSION_LIST)).getList());
for (final Map.Entry<ItemStorage, Integer> content : building.getTileEntity().getAllContent().entrySet()) {
if (content.getValue() > content.getKey().getItemStack().getMaxStackSize() * 6 && ItemStackUtils.CAN_EAT.test(content.getKey().getItemStack())) {
blockedItems.add(content.getKey());
}
}
blockedItems.removeIf(item -> item.getItem().getFoodProperties() == null || item.getItem().getFoodProperties().getNutrition() < building.getBuildingLevel() - 1);
if (!blockedItems.isEmpty()) {
if (IColonyManager.getInstance().getCompatibilityManager().getEdibles(building.getBuildingLevel() - 1).size() <= blockedItems.size()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(FURNACE_USER_NO_FOOD), ChatPriority.BLOCKING));
return null;
}
}
return new Food(STACKSIZE, blockedItems, building.getBuildingLevel() - 1);
}
return new Food(STACKSIZE, building.getBuildingLevel() - 1);
}
use of com.minecolonies.api.colony.requestsystem.requestable.Food in project minecolonies by ldtteam.
the class EntityAIWorkCook method getSmeltAbleClass.
@Override
protected IRequestable getSmeltAbleClass() {
final List<ItemStorage> blockedItems = new ArrayList<>(getOwnBuilding().getModuleMatching(ItemListModule.class, m -> m.getId().equals(FOOD_EXCLUSION_LIST)).getList());
for (final Map.Entry<ItemStorage, Integer> content : getOwnBuilding().getTileEntity().getAllContent().entrySet()) {
if (content.getValue() > content.getKey().getItem().getMaxStackSize() * 6 && ItemStackUtils.CAN_EAT.test(content.getKey().getItemStack())) {
blockedItems.add(content.getKey());
}
}
blockedItems.removeIf(item -> item.getItem().getFoodProperties() == null || item.getItem().getFoodProperties().getNutrition() < getOwnBuilding().getBuildingLevel() - 1);
if (!blockedItems.isEmpty()) {
if (IColonyManager.getInstance().getCompatibilityManager().getEdibles(getOwnBuilding().getBuildingLevel() - 1).size() <= blockedItems.size()) {
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(FURNACE_USER_NO_FOOD), ChatPriority.BLOCKING));
return null;
}
}
return new Food(STACKSIZE, blockedItems, getOwnBuilding().getBuildingLevel() - 1);
}
return new Food(STACKSIZE, getOwnBuilding().getBuildingLevel() - 1);
}
Aggregations