Class FoodUtils

java.lang.Object
com.minecolonies.api.util.FoodUtils

public class FoodUtils extends Object
Food specific util functions.
  • Field Details

    • EDIBLE

      public static final Predicate<net.minecraft.world.item.ItemStack> EDIBLE
      Predicate describing food which can be eaten (is not raw).
  • Constructor Details

    • FoodUtils

      public FoodUtils()
  • Method Details

    • canEat

      public static boolean canEat(net.minecraft.world.item.ItemStack stack, IBuilding homeBuilding, IBuilding workBuilding)
      Parameters:
      stack -
      workBuilding -
      Returns:
    • canEatLevel

      public static boolean canEatLevel(net.minecraft.world.item.ItemStack stack, int buildingLevel)
      Check if that food can be eaten at a given building level.
      Parameters:
      stack - the stack to check.
      buildingLevel - the respective building level.
      Returns:
      true if so.
    • getBuildingLevelForFood

      public static int getBuildingLevelForFood(net.minecraft.world.item.ItemStack resource)
      Calculate the given max building level for a given food.
      Parameters:
      resource - the stack to check.
      Returns:
      the building level.
    • getFoodValue

      public static double getFoodValue(net.minecraft.world.item.ItemStack foodStack, @Nullable net.minecraft.world.food.FoodProperties itemFood, double researchBonus)
      Calculate the actual food value for a citizen consuming a given food.
      Parameters:
      foodStack - the food to consume.
      itemFood - the food properties of that food.
      researchBonus - the bonus from research (0 for no bonus).
      Returns:
      the saturation adjustment to apply when consuming this food.
    • getFoodValue

      public static double getFoodValue(net.minecraft.world.item.ItemStack foodStack, AbstractEntityCitizen citizen)
      Calculate the actual food value for a citizen consuming a given food.
      Parameters:
      foodStack - the food to consume.
      citizen - the citizen consuming the food.
      Returns:
      the saturation adjustment to apply when consuming this food.
    • getFoodTier

      public static int getFoodTier(net.minecraft.world.item.ItemStack food)
      Calculate the food tier from the food item.
      Parameters:
      food - the food item.
      Returns:
      the tier.
    • getBestFoodForCitizen

      public static int getBestFoodForCitizen(InventoryCitizen inventoryCitizen, ICitizenData citizenData, @Nullable Set<ItemStorage> menu)
      Get the best food for a given citizen from a given inventory and return the index where it is.
      Parameters:
      inventoryCitizen - the inventory to check.
      citizenData - the citizen data the food is for.
      menu - the menu that has to be matched. or null
      Returns:
      the matching inv slot, or -1.
    • checkForFoodInBuilding

      public static ItemStorage checkForFoodInBuilding(ICitizenData citizenData, @Nullable Set<ItemStorage> menu, IBuilding building)
      Get the best food for a given citizen from a given inventory and return the index where it is.
      Parameters:
      citizenData - the citizen data the food is for.
      menu - the menu that has to be matched or null.
      Returns:
      the matching inv slot, or -1.
    • hasBestOptionInInv

      public static boolean hasBestOptionInInv(InventoryCitizen inventoryCitizen, ICitizenData citizenData, @Nullable Set<ItemStorage> menu, IBuilding building)
      Get the best food for a given citizen from a given inventory and return the index where it is.
      Parameters:
      citizenData - the citizen data the food is for.
      menu - the menu that has to be matched or null.
      Returns:
      the matching inv slot, or -1.
    • getMinFoodQualityRequirement

      public static int getMinFoodQualityRequirement(int buildingLevel)
      Get the min food quality requirement.
      Parameters:
      buildingLevel - the building level to take into account.
      Returns:
      the food quality requirement in number of items.
    • getMinFoodDiversityRequirement

      public static int getMinFoodDiversityRequirement(int buildingLevel)
      Get the min food diversity requirement.
      Parameters:
      buildingLevel - the building level to take into account.
      Returns:
      the food diversity requirement in number of items.
    • consumeFoodStack

      public static net.minecraft.world.item.ItemStack consumeFoodStack(net.minecraft.world.item.ItemStack foodStack, AbstractEntityCitizen citizen)
      Update stacks for consuming a food (does not apply the actual nutrition).
      Parameters:
      foodStack - the food stack being eaten (will be modified!).
      citizen - the citizen doing the eating.
      Returns:
      the leftover item (e.g. bottle, bowl), or an empty stack.
    • computeSaturationConsumptionFactor

      public static double computeSaturationConsumptionFactor(int buildingLevel)
      Compute the saturation consumption factor.
      Parameters:
      buildingLevel - the housing level it's based on.
      Returns:
      the value.