Interface ICraftingBuildingModule

All Superinterfaces:
IBuildingModule, IHasDirty
All Known Implementing Classes:
AbstractCraftingBuildingModule, AbstractCraftingBuildingModule.Brewing, AbstractCraftingBuildingModule.Crafting, AbstractCraftingBuildingModule.Custom, AbstractCraftingBuildingModule.Domum, AbstractCraftingBuildingModule.Smelting, BuildingAlchemist.BrewingModule, BuildingAlchemist.CraftingModule, BuildingBaker.CraftingModule, BuildingBaker.SmeltingModule, BuildingBlacksmith.CraftingModule, BuildingConcreteMixer.CraftingModule, BuildingCrusher.CraftingModule, BuildingDyer.CraftingModule, BuildingDyer.SmeltingModule, BuildingEnchanter.CraftingModule, BuildingFarmer.CraftingModule, BuildingFletcher.CraftingModule, BuildingFletcher.DOCraftingModule, BuildingGlassblower.CraftingModule, BuildingGlassblower.DOCraftingModule, BuildingGlassblower.SmeltingModule, BuildingKitchen.CraftingModule, BuildingKitchen.SmeltingModule, BuildingLumberjack.CraftingModule, BuildingMechanic.CraftingModule, BuildingMechanic.DOCraftingModule, BuildingNetherWorker.CraftingModule, BuildingPlantation.CraftingModule, BuildingSawmill.CraftingModule, BuildingSawmill.DOCraftingModule, BuildingSifter.CraftingModule, BuildingSmeltery.OreBreakingModule, BuildingSmeltery.SmeltingModule, BuildingStonemason.CraftingModule, BuildingStonemason.DOCraftingModule, BuildingStoneSmeltery.SmeltingModule, SimpleCraftingModule

public interface ICraftingBuildingModule extends IBuildingModule
This module represents the ability for a building to generate items via some form of crafting, whether vanilla, smelter, or some entirely custom process. It also supports (within some restrictions) automatic JEI integration to let the player look up which items can be produced at each building. A single building may have more than one of these, but in that case they must be linked to different jobs (or to no job) and you have to more carefully manage the learned recipe list. Note that (somewhat uniquely among modules) while there is a "real" one of these attached to the building on the server side that can hold state, additional instances can also be created (with a null building) on the client side in order to answer abstract (but building-type-specific) questions for JEI. When called this way, it must be able to provide answers completely stateless with no expectation that the building (or any colony, for that matter) actually exists.
  • Method Details

    • getCraftingJob

      @Nullable @Nullable IJob<?> getCraftingJob()
      Gets the crafting job associated with this building type. This might not be the primary job of the building. Note that this must either always return null or always return a valid job, even if this module is not currently associated with a specific colony or building. (Note that if it returns null, there will be no JEI integration.) It may either return the actual job associated with a citizen working at the current building, or an abstract job not yet associated with any particular citizen. It is permitted for two crafting module types to return the same job but in that case getId() must return different ids.
      Returns:
      The crafting job, or null if there is no such job.
    • getId

      @NotNull @Deprecated @NotNull String getId()
      Deprecated.
      Gets an id *suffix* for this particular crafting module, to disambiguate between multiple modules with the same job. This is not unique by itself.
      Returns:
      The disambiguating id suffix.
    • getCustomRecipeKey

      @NotNull @NotNull String getCustomRecipeKey()
      Gets the unique key for recipes intended for this crafting module in the CustomRecipeManager. Precondition: getCraftingJob() returns non-null.
      Returns:
      The unique key.
    • canLearn

      default boolean canLearn(CraftingType type)
      Check if the worker can learn a certain type of recipe.
      Parameters:
      type - the type to check for.
      Returns:
      true if so.
    • getSupportedCraftingTypes

      Set<CraftingType> getSupportedCraftingTypes()
      Get the supported crafting types.
      Returns:
      a set of types.
    • isRecipeCompatible

      boolean isRecipeCompatible(@NotNull @NotNull IGenericRecipe recipe)
      Checks if this particular recipe is *possible* to be learned by this building (or otherwise possible to be crafted there). This is checked without regard to specific colony or level of building, or whether there are spare recipe slots or not.
      Parameters:
      recipe - The recipe to check.
      Returns:
      True if this recipe could be produced/taught.
    • getIngredientValidator

      @NotNull @NotNull OptionalPredicate<net.minecraft.world.item.ItemStack> getIngredientValidator()
      Gets a predicate for recipe ingredients that are explicitly allowed or banned at this building. Used to reduce false negatives from isRecipeCompatible(com.minecolonies.api.crafting.IGenericRecipe) when alternatives are available.
      Returns:
      A predicate that returns true when the ingredient is definitely allowed, false when definitely banned, or empty when undecided.
    • canLearnManyRecipes

      boolean canLearnManyRecipes()
      Check if the module should have a large limit for learnable recipes.
      Returns:
      true if so.
    • isVisible

      boolean isVisible()
      Check if the module on the client side should be displayed.
      Returns:
      true if so.
    • getRecipes

      List<IToken<?>> getRecipes()
      Get a list of all recipes of this module.
      Returns:
      the list of recipes.
    • getFirstRecipe

      @Nullable @Nullable IRecipeStorage getFirstRecipe(net.minecraft.world.item.ItemStack stack)
      Get the first recipe where the output matches this stack.
      Parameters:
      stack - the output stack to match.
      Returns:
      the recipe or null.
    • getFirstRecipe

      @Nullable @Nullable IRecipeStorage getFirstRecipe(Predicate<net.minecraft.world.item.ItemStack> stackPredicate)
      Check if is the worker has the knowledge to craft something.
      Parameters:
      stackPredicate - the predicate to check for fullfillment.
      Returns:
      the recipe storage if so.
    • getFirstFulfillableRecipe

      IRecipeStorage getFirstFulfillableRecipe(Predicate<net.minecraft.world.item.ItemStack> stackPredicate, int count, boolean considerReservation)
      Get a fullfillable recipe to execute.
      Parameters:
      stackPredicate - the predicate to check for fullfillment.
      count - the count to produce.
      considerReservation - if reservations should be considered.
      Returns:
      the recipe or null.
    • fullFillRecipe

      boolean fullFillRecipe(IRecipeStorage storage)
      Fulfill the recipe.
      Parameters:
      storage - the recipe storage to fulfill.
      Returns:
      true if successful.
    • getCraftingTool

      net.minecraft.world.item.ItemStack getCraftingTool(AbstractEntityCitizen worker)
      Get tool to use during fulFillRecipe
      Parameters:
      worker - the worker to query for tool
    • getCraftingLuck

      float getCraftingLuck(AbstractEntityCitizen worker)
      Get luck to use during fulFillRecipe
      Parameters:
      worker - the worker to calculate luck for
    • updateWorkerAvailableForRecipes

      void updateWorkerAvailableForRecipes()
      Updates existing requests, if they match the recipes available at this worker
    • replaceRecipe

      void replaceRecipe(IToken<?> oldRecipe, IToken<?> newRecipe)
      Replace one current recipe with a new one
      Parameters:
      oldRecipe - the recipe to replace
      newRecipe - the new version
    • canRecipeBeAdded

      boolean canRecipeBeAdded(IToken<?> token)
      Check if a recipe can be added. This is only important for 3x3 crafting. Workers shall override this if necessary.
      Parameters:
      token - the token of the recipe.
      Returns:
      true if so.
    • addRecipeToList

      void addRecipeToList(IToken<?> token, boolean atTop)
      Add a recipe to the list of recipes.
      Parameters:
      token - the token to add.
    • switchOrder

      void switchOrder(int i, int j, boolean fullMove)
      Switch the order of two recipes.
      Parameters:
      i - the first recipe.
      j - the second recipe.
      fullMove - move it fully up/down.
    • getAdditionalRecipesForDisplayPurposesOnly

      @NotNull @NotNull List<IGenericRecipe> getAdditionalRecipesForDisplayPurposesOnly(@NotNull @NotNull net.minecraft.world.level.Level world)
      Generates any additional special recipes supported by this crafter. Unlike the above, these are not added to the building's learned recipe list; they are only used for display purposes such as the JEI lookup. This is intended for things that the worker AI can do by itself without any explicit recipe (neither taught nor loaded).
      Returns:
      The list of additional recipes.
    • getAdditionalLootTables

      @NotNull default @NotNull List<net.minecraft.resources.ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> getAdditionalLootTables()
      Gets a list of loot tables that should be available for drop analysis (beyond any already used in recipes). This is not intended for actually generating loot, just for display purposes such as in JEI (e.g. via getAdditionalRecipesForDisplayPurposesOnly(Level)).
      Returns:
      The list of loot table ids
    • addRecipe

      boolean addRecipe(IToken<?> token)
      Add a recipe to the building.
      Parameters:
      token - the id of the recipe.
      Returns:
      true if successful
    • removeRecipe

      void removeRecipe(IToken<?> token)
      Remove a recipe of the building.
      Parameters:
      token - the id of the recipe.
    • checkForWorkerSpecificRecipes

      void checkForWorkerSpecificRecipes()
      Updates existing requests, if they match the recipes available at this worker
    • clearRecipes

      void clearRecipes()
      Clear the list of recipes.
    • improveRecipe

      void improveRecipe(IRecipeStorage currentRecipeStorage, int craftCounter, ICitizenData citizenData)
      Randomly improve a certain recipe.
      Parameters:
      currentRecipeStorage - the recipe to improve.
      craftCounter - the craft counter.
      citizenData - the citizen running it.
    • getUid

      @Nullable @Deprecated default @Nullable net.minecraft.resources.ResourceLocation getUid()
      Deprecated.
      Gets a unique identifier for this crafting module, based on the job and disambiguation suffix. May be null where there was no job.
      Returns:
      The unique id or null.
    • getUid

      @NotNull static @NotNull net.minecraft.resources.ResourceLocation getUid(@NotNull @NotNull JobEntry job, @NotNull @NotNull String id)
      Formats a crafting module unique identifier based on a job entry and disambiguation suffix.
      Returns:
      The unique id.
    • holdsRecipe

      boolean holdsRecipe(IToken<?> token)
      Check if the recipe it part of this module.
      Parameters:
      token - the recipe token to check.
      Returns:
      true if so.
    • toggle

      void toggle(int recipeLocation)
      Enable or disable a recipe at a location.
      Parameters:
      recipeLocation - the location of the recipe.
    • isDisabled

      boolean isDisabled(IToken<?> token)
      Check if a recipe is disabled.
      Parameters:
      token - the recipe id to check for.
      Returns:
      true if so.