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
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 Summary
Modifier and TypeMethodDescriptionbooleanAdd a recipe to the building.voidaddRecipeToList(IToken<?> token, boolean atTop) Add a recipe to the list of recipes.default booleancanLearn(CraftingType type) Check if the worker can learn a certain type of recipe.booleanCheck if the module should have a large limit for learnable recipes.booleancanRecipeBeAdded(IToken<?> token) Check if a recipe can be added.voidUpdates existing requests, if they match the recipes available at this workervoidClear the list of recipes.booleanfullFillRecipe(IRecipeStorage storage) Fulfill the recipe.default @NotNull List<net.minecraft.resources.ResourceKey<net.minecraft.world.level.storage.loot.LootTable>> Gets a list of loot tables that should be available for drop analysis (beyond any already used in recipes).@NotNull List<IGenericRecipe> getAdditionalRecipesForDisplayPurposesOnly(@NotNull net.minecraft.world.level.Level world) Generates any additional special recipes supported by this crafter.@Nullable IJob<?> Gets the crafting job associated with this building type.floatgetCraftingLuck(AbstractEntityCitizen worker) Get luck to use during fulFillRecipenet.minecraft.world.item.ItemStackgetCraftingTool(AbstractEntityCitizen worker) Get tool to use during fulFillRecipe@NotNull StringGets the unique key for recipes intended for this crafting module in the CustomRecipeManager.getFirstFulfillableRecipe(Predicate<net.minecraft.world.item.ItemStack> stackPredicate, int count, boolean considerReservation) Get a fullfillable recipe to execute.@Nullable IRecipeStoragegetFirstRecipe(Predicate<net.minecraft.world.item.ItemStack> stackPredicate) Check if is the worker has the knowledge to craft something.@Nullable IRecipeStoragegetFirstRecipe(net.minecraft.world.item.ItemStack stack) Get the first recipe where the output matches this stack.@NotNull StringgetId()Deprecated.@NotNull OptionalPredicate<net.minecraft.world.item.ItemStack> Gets a predicate for recipe ingredients that are explicitly allowed or banned at this building.Get a list of all recipes of this module.Get the supported crafting types.default @Nullable net.minecraft.resources.ResourceLocationgetUid()Deprecated.static @NotNull net.minecraft.resources.ResourceLocationFormats a crafting module unique identifier based on a job entry and disambiguation suffix.booleanholdsRecipe(IToken<?> token) Check if the recipe it part of this module.voidimproveRecipe(IRecipeStorage currentRecipeStorage, int craftCounter, ICitizenData citizenData) Randomly improve a certain recipe.booleanisDisabled(IToken<?> token) Check if a recipe is disabled.booleanisRecipeCompatible(@NotNull IGenericRecipe recipe) Checks if this particular recipe is *possible* to be learned by this building (or otherwise possible to be crafted there).booleanCheck if the module on the client side should be displayed.voidremoveRecipe(IToken<?> token) Remove a recipe of the building.voidreplaceRecipe(IToken<?> oldRecipe, IToken<?> newRecipe) Replace one current recipe with a new onevoidswitchOrder(int i, int j, boolean fullMove) Switch the order of two recipes.voidtoggle(int recipeLocation) Enable or disable a recipe at a location.voidUpdates existing requests, if they match the recipes available at this workerMethods inherited from interface com.minecolonies.api.colony.buildings.modules.IBuildingModule
getBuilding, getProducer, serializeToView, serializeToView, setBuilding, setProducerMethods inherited from interface com.minecolonies.api.util.IHasDirty
checkDirty, clearDirty, markDirty
-
Method Details
-
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 casegetId()must return different ids.- Returns:
- The crafting job, or null if there is no such job.
-
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
Gets the unique key for recipes intended for this crafting module in the CustomRecipeManager. Precondition: getCraftingJob() returns non-null.- Returns:
- The unique key.
-
canLearn
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
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
Gets a predicate for recipe ingredients that are explicitly allowed or banned at this building. Used to reduce false negatives fromisRecipeCompatible(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
Get a list of all recipes of this module.- Returns:
- the list of recipes.
-
getFirstRecipe
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
Fulfill the recipe.- Parameters:
storage- the recipe storage to fulfill.- Returns:
- true if successful.
-
getCraftingTool
Get tool to use during fulFillRecipe- Parameters:
worker- the worker to query for tool
-
getCraftingLuck
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
Replace one current recipe with a new one- Parameters:
oldRecipe- the recipe to replacenewRecipe- the new version
-
canRecipeBeAdded
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
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. viagetAdditionalRecipesForDisplayPurposesOnly(Level)).- Returns:
- The list of loot table ids
-
addRecipe
Add a recipe to the building.- Parameters:
token- the id of the recipe.- Returns:
- true if successful
-
removeRecipe
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
Randomly improve a certain recipe.- Parameters:
currentRecipeStorage- the recipe to improve.craftCounter- the craft counter.citizenData- the citizen running it.
-
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
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
Check if a recipe is disabled.- Parameters:
token- the recipe id to check for.- Returns:
- true if so.
-