Class AbstractCraftingBuildingModule

java.lang.Object
com.minecolonies.api.colony.buildings.modules.AbstractBuildingModule
com.minecolonies.core.colony.buildings.modules.AbstractCraftingBuildingModule
All Implemented Interfaces:
IBuildingModule, ICraftingBuildingModule, ICreatesResolversModule, IHasRequiredItemsModule, IPersistentModule, ITickingModule, IHasDirty
Direct Known Subclasses:
AbstractCraftingBuildingModule.Brewing, AbstractCraftingBuildingModule.Crafting, AbstractCraftingBuildingModule.Custom, AbstractCraftingBuildingModule.Domum, AbstractCraftingBuildingModule.Smelting

Basic implementation of a crafting module. Typically you should not directly extend this module; instead you should extend one of the "policy classes" (inner classes) to specify the type of crafting supported. The policy classes don't provide any "real" implementation, they just configure this one.
  • Field Details

    • RECIPE_MODE

      public static final ISettingKey<CrafterRecipeSetting> RECIPE_MODE
      The recipemode of the crafter (either priority based, or warehouse stock baseD).
    • recipes

      protected final List<IToken<?>> recipes
      The list of recipes the worker knows, correspond to a subset of the recipes in the colony.
    • disabledRecipes

      protected final List<IToken<?>> disabledRecipes
      The list of disabled recipes.
    • jobEntry

      protected final JobEntry jobEntry
      The job entry that works at this module.
    • building

      protected AbstractBuilding building
      Specific crafting building.
  • Constructor Details

    • AbstractCraftingBuildingModule

      public AbstractCraftingBuildingModule(JobEntry jobEntry)
      Create a new module.
      Parameters:
      jobEntry - the entry of the job.
  • Method Details

    • getRecipes

      public List<IToken<?>> getRecipes()
      Description copied from interface: ICraftingBuildingModule
      Get a list of all recipes of this module.
      Specified by:
      getRecipes in interface ICraftingBuildingModule
      Returns:
      the list of recipes.
    • setBuilding

      public IBuildingModule setBuilding(IBuilding building)
      Description copied from interface: IBuildingModule
      Set the building of the module.
      Specified by:
      setBuilding in interface IBuildingModule
      Overrides:
      setBuilding in class AbstractBuildingModule
      Parameters:
      building - the building to set.
      Returns:
      the module itself.
    • canRecipeBeAdded

      public boolean canRecipeBeAdded(IToken<?> token)
      Description copied from interface: ICraftingBuildingModule
      Check if a recipe can be added. This is only important for 3x3 crafting. Workers shall override this if necessary.
      Specified by:
      canRecipeBeAdded in interface ICraftingBuildingModule
      Parameters:
      token - the token of the recipe.
      Returns:
      true if so.
    • getMaxRecipes

      protected int getMaxRecipes()
      Gets the maximum number of recipes a building may have at the current time.
    • isRecipeCompatibleWithCraftingModule

      protected boolean isRecipeCompatibleWithCraftingModule(IToken<?> token)
      Parameters:
      token - the recipe token
      Returns:
      whether the recipe can be added according to the crafting module (or false if there's no module)
    • isPreTaughtRecipe

      protected boolean isPreTaughtRecipe(IRecipeStorage storage, Map<net.minecraft.resources.ResourceLocation,CustomRecipe> crafterRecipes)
      Check if the recipe is a pre-taught recipe through datapack.
      Parameters:
      storage - the recipe to check.
      crafterRecipes - the list of custom recipes.
      Returns:
      true if so.
    • serializeNBT

      public void serializeNBT(@NotNull net.minecraft.core.HolderLookup.Provider provider, @NotNull @NotNull net.minecraft.nbt.CompoundTag compound)
      Description copied from interface: IPersistentModule
      Serialize the module from a compound.
      Specified by:
      serializeNBT in interface IPersistentModule
      Parameters:
      compound - the compound.
    • deserializeNBT

      public void deserializeNBT(@NotNull net.minecraft.core.HolderLookup.Provider provider, net.minecraft.nbt.CompoundTag compound)
      Description copied from interface: IPersistentModule
      Deserialize the module.
      Specified by:
      deserializeNBT in interface IPersistentModule
      Parameters:
      compound - the nbt compound.
    • serializeToView

      public void serializeToView(@NotNull @NotNull net.minecraft.network.RegistryFriendlyByteBuf buf, boolean fullSync)
      Description copied from interface: IBuildingModule
      Serialization method to send the module data to the client side.
      Specified by:
      serializeToView in interface IBuildingModule
      Parameters:
      buf - the buffer to write it to.
      fullSync - whether we need to sync the full data
    • getRequiredItemsAndAmount

      public Map<Predicate<net.minecraft.world.item.ItemStack>,net.minecraft.util.Tuple<Integer,Boolean>> getRequiredItemsAndAmount()
      Description copied from interface: IHasRequiredItemsModule
      Override this method if you want to keep an amount of items in inventory. When the inventory is full, everything get's dumped into the building chest. But you can use this method to hold some stacks back.
      Specified by:
      getRequiredItemsAndAmount in interface IHasRequiredItemsModule
      Returns:
      a list of objects which should be kept.
    • reservedStacksExcluding

      public Map<ItemStorage,Integer> reservedStacksExcluding(@Nullable @Nullable IRequest<? extends IDeliverable> request)
      Description copied from interface: IHasRequiredItemsModule
      Calculate the number of reserved stacks the resolver can't touch.
      Specified by:
      reservedStacksExcluding in interface IHasRequiredItemsModule
      Parameters:
      request - ignore reservations that would exist for the current request.
      Returns:
      a list of itemstorages.
    • isVisible

      public boolean isVisible()
      Description copied from interface: ICraftingBuildingModule
      Check if the module on the client side should be displayed.
      Specified by:
      isVisible in interface ICraftingBuildingModule
      Returns:
      true if so.
    • addRecipe

      public boolean addRecipe(IToken<?> token)
      Description copied from interface: ICraftingBuildingModule
      Add a recipe to the building.
      Specified by:
      addRecipe in interface ICraftingBuildingModule
      Parameters:
      token - the id of the recipe.
      Returns:
      true if successful
    • handleRecipeUpdate

      public void handleRecipeUpdate(IToken<?> token)
      Handle recipe update. Adjust request system to deal with recipe update.
      Parameters:
      token - the related recipe.
    • onColonyTick

      public void onColonyTick(@NotNull @NotNull IColony colony)
      Description copied from interface: ITickingModule
      Colony tick hook.
      Specified by:
      onColonyTick in interface ITickingModule
      Parameters:
      colony - the colony the tick is invoked from.
    • checkForWorkerSpecificRecipes

      public void checkForWorkerSpecificRecipes()
      Description copied from interface: ICraftingBuildingModule
      Updates existing requests, if they match the recipes available at this worker
      Specified by:
      checkForWorkerSpecificRecipes in interface ICraftingBuildingModule
    • clearRecipes

      public void clearRecipes()
      Description copied from interface: ICraftingBuildingModule
      Clear the list of recipes.
      Specified by:
      clearRecipes in interface ICraftingBuildingModule
    • improveRecipe

      public void improveRecipe(IRecipeStorage recipe, int count, ICitizenData citizen)
      Description copied from interface: ICraftingBuildingModule
      Randomly improve a certain recipe.
      Specified by:
      improveRecipe in interface ICraftingBuildingModule
      Parameters:
      recipe - the recipe to improve.
      count - the craft counter.
      citizen - the citizen running it.
    • getFirstRecipe

      @Nullable public @Nullable IRecipeStorage getFirstRecipe(net.minecraft.world.item.ItemStack stack)
      Description copied from interface: ICraftingBuildingModule
      Get the first recipe where the output matches this stack.
      Specified by:
      getFirstRecipe in interface ICraftingBuildingModule
      Parameters:
      stack - the output stack to match.
      Returns:
      the recipe or null.
    • getFirstRecipe

      @Nullable public @Nullable IRecipeStorage getFirstRecipe(Predicate<net.minecraft.world.item.ItemStack> stackPredicate)
      Description copied from interface: ICraftingBuildingModule
      Check if is the worker has the knowledge to craft something.
      Specified by:
      getFirstRecipe in interface ICraftingBuildingModule
      Parameters:
      stackPredicate - the predicate to check for fullfillment.
      Returns:
      the recipe storage if so.
    • holdsRecipe

      public boolean holdsRecipe(IToken<?> token)
      Description copied from interface: ICraftingBuildingModule
      Check if the recipe it part of this module.
      Specified by:
      holdsRecipe in interface ICraftingBuildingModule
      Parameters:
      token - the recipe token to check.
      Returns:
      true if so.
    • getWarehouseCount

      protected int getWarehouseCount(ItemStorage item)
      Get the count of items in all the warehouses
    • getFirstFulfillableRecipe

      public IRecipeStorage getFirstFulfillableRecipe(Predicate<net.minecraft.world.item.ItemStack> stackPredicate, int count, boolean considerReservation)
      Description copied from interface: ICraftingBuildingModule
      Get a fullfillable recipe to execute.
      Specified by:
      getFirstFulfillableRecipe in interface ICraftingBuildingModule
      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

      public boolean fullFillRecipe(IRecipeStorage storage)
      Description copied from interface: ICraftingBuildingModule
      Fulfill the recipe.
      Specified by:
      fullFillRecipe in interface ICraftingBuildingModule
      Parameters:
      storage - the recipe storage to fulfill.
      Returns:
      true if successful.
    • getCraftingTool

      public net.minecraft.world.item.ItemStack getCraftingTool(AbstractEntityCitizen worker)
      Description copied from interface: ICraftingBuildingModule
      Get tool to use during fulFillRecipe
      Specified by:
      getCraftingTool in interface ICraftingBuildingModule
      Parameters:
      worker - the worker to query for tool
    • getCraftingLuck

      public float getCraftingLuck(AbstractEntityCitizen worker)
      Description copied from interface: ICraftingBuildingModule
      Get luck to use during fulFillRecipe
      Specified by:
      getCraftingLuck in interface ICraftingBuildingModule
      Parameters:
      worker - the worker to calculate luck for
    • getCraftingJob

      @Nullable public @Nullable IJob<?> getCraftingJob()
      Description copied from interface: ICraftingBuildingModule
      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 ICraftingBuildingModule.getId() must return different ids.
      Specified by:
      getCraftingJob in interface ICraftingBuildingModule
      Returns:
      The crafting job, or null if there is no such job.
    • updateWorkerAvailableForRecipes

      public void updateWorkerAvailableForRecipes()
      Description copied from interface: ICraftingBuildingModule
      Updates existing requests, if they match the recipes available at this worker
      Specified by:
      updateWorkerAvailableForRecipes in interface ICraftingBuildingModule
    • replaceRecipe

      public void replaceRecipe(IToken<?> oldRecipe, IToken<?> newRecipe)
      Description copied from interface: ICraftingBuildingModule
      Replace one current recipe with a new one
      Specified by:
      replaceRecipe in interface ICraftingBuildingModule
      Parameters:
      oldRecipe - the recipe to replace
      newRecipe - the new version
    • removeRecipe

      public void removeRecipe(IToken<?> token)
      Description copied from interface: ICraftingBuildingModule
      Remove a recipe of the building.
      Specified by:
      removeRecipe in interface ICraftingBuildingModule
      Parameters:
      token - the id of the recipe.
    • addRecipeToList

      public void addRecipeToList(IToken<?> token, boolean atTop)
      Description copied from interface: ICraftingBuildingModule
      Add a recipe to the list of recipes.
      Specified by:
      addRecipeToList in interface ICraftingBuildingModule
      Parameters:
      token - the token to add.
    • switchOrder

      public void switchOrder(int i, int j, boolean fullMove)
      Description copied from interface: ICraftingBuildingModule
      Switch the order of two recipes.
      Specified by:
      switchOrder in interface ICraftingBuildingModule
      Parameters:
      i - the first recipe.
      j - the second recipe.
      fullMove - move it fully up/down.
    • toggle

      public void toggle(int recipeLocation)
      Description copied from interface: ICraftingBuildingModule
      Enable or disable a recipe at a location.
      Specified by:
      toggle in interface ICraftingBuildingModule
      Parameters:
      recipeLocation - the location of the recipe.
    • getAdditionalRecipesForDisplayPurposesOnly

      @NotNull public @NotNull List<IGenericRecipe> getAdditionalRecipesForDisplayPurposesOnly(@NotNull @NotNull net.minecraft.world.level.Level world)
      Description copied from interface: ICraftingBuildingModule
      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).
      Specified by:
      getAdditionalRecipesForDisplayPurposesOnly in interface ICraftingBuildingModule
      Returns:
      The list of additional recipes.
    • createResolvers

      public List<IRequestResolver<?>> createResolvers()
      Description copied from interface: ICreatesResolversModule
      Get a list of resolvers for this building.
      Specified by:
      createResolvers in interface ICreatesResolversModule
      Returns:
      the list of resolvers.
    • getId

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

      @NotNull public @NotNull String getCustomRecipeKey()
      Description copied from interface: ICraftingBuildingModule
      Gets the unique key for recipes intended for this crafting module in the CustomRecipeManager. Precondition: getCraftingJob() returns non-null.
      Specified by:
      getCustomRecipeKey in interface ICraftingBuildingModule
      Returns:
      The unique key.
    • getIngredientValidator

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

      public boolean canLearnManyRecipes()
      Description copied from interface: ICraftingBuildingModule
      Check if the module should have a large limit for learnable recipes.
      Specified by:
      canLearnManyRecipes in interface ICraftingBuildingModule
      Returns:
      true if so.
    • isDisabled

      public boolean isDisabled(IToken<?> token)
      Description copied from interface: ICraftingBuildingModule
      Check if a recipe is disabled.
      Specified by:
      isDisabled in interface ICraftingBuildingModule
      Parameters:
      token - the recipe id to check for.
      Returns:
      true if so.