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.Smelting
public abstract class AbstractCraftingBuildingModule
extends AbstractBuildingModule
implements ICraftingBuildingModule, IPersistentModule, ICreatesResolversModule, IHasRequiredItemsModule, ITickingModule
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classthis module is for brewing-only usersstatic classThis module is for standard crafters (3x3 by default)static classthis module is for those who can't be taught recipes but can still use custom recipesstatic classthis module is for furnace-only users -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AbstractBuildingSpecific crafting building.The list of disabled recipes.protected final JobEntryThe job entry that works at this module.static final ISettingKey<CrafterRecipeSetting>The recipemode of the crafter (either priority based, or warehouse stock baseD).The list of recipes the worker knows, correspond to a subset of the recipes in the colony.Fields inherited from class com.minecolonies.api.colony.buildings.modules.AbstractBuildingModule
isDirty -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd a recipe to the building.voidaddRecipeToList(IToken<?> token, boolean atTop) Add a recipe to the list of recipes.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.List<IRequestResolver<?>>Get a list of resolvers for this building.voiddeserializeNBT(net.minecraft.nbt.CompoundTag compound) Deserialize the module.booleanfullFillRecipe(IRecipeStorage storage) Fulfill the recipe.@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.abstract @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.protected intGets the maximum number of recipes a building may have at the current time.Get a list of all recipes of this module.Override this method if you want to keep an amount of items in inventory.protected intgetWarehouseCount(ItemStorage item) Get the count of items in all the warehousesvoidhandleRecipeUpdate(IToken<?> token) Handle recipe update.booleanholdsRecipe(IToken<?> token) Check if the recipe it part of this module.voidimproveRecipe(IRecipeStorage recipe, int count, ICitizenData citizen) Randomly improve a certain recipe.booleanisDisabled(IToken<?> token) Check if a recipe is disabled.protected booleanisPreTaughtRecipe(IRecipeStorage storage, Map<net.minecraft.resources.ResourceLocation, CustomRecipe> crafterRecipes) Check if the recipe is a pre-taught recipe through datapack.protected booleanisRecipeCompatibleWithCraftingModule(IToken<?> token) booleanCheck if the module on the client side should be displayed.voidonColonyTick(@NotNull IColony colony) Colony tick hook.voidremoveRecipe(IToken<?> token) Remove a recipe of the building.voidreplaceRecipe(IToken<?> oldRecipe, IToken<?> newRecipe) Replace one current recipe with a new onereservedStacksExcluding(@Nullable IRequest<? extends IDeliverable> request) Calculate the number of reserved stacks the resolver can't touch.voidserializeNBT(@NotNull net.minecraft.nbt.CompoundTag compound) Serialize the module from a compound.voidserializeToView(@NotNull net.minecraft.network.FriendlyByteBuf buf, boolean fullSync) Serialization method to send the module data to the client side.setBuilding(IBuilding building) Set the building of the module.voidswitchOrder(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 class com.minecolonies.api.colony.buildings.modules.AbstractBuildingModule
checkDirty, clearDirty, getBuilding, getProducer, markDirty, setProducerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.minecolonies.api.colony.buildings.modules.IBuildingModule
getBuilding, getProducer, serializeToView, setProducerMethods inherited from interface com.minecolonies.api.colony.buildings.modules.ICraftingBuildingModule
canLearn, getAdditionalLootTables, getSupportedCraftingTypes, getUid, isRecipeCompatibleMethods inherited from interface com.minecolonies.api.util.IHasDirty
checkDirty, clearDirty, markDirtyMethods inherited from interface com.minecolonies.api.colony.buildings.modules.IHasRequiredItemsModule
reservedStacks
-
Field Details
-
RECIPE_MODE
The recipemode of the crafter (either priority based, or warehouse stock baseD). -
recipes
The list of recipes the worker knows, correspond to a subset of the recipes in the colony. -
disabledRecipes
The list of disabled recipes. -
jobEntry
The job entry that works at this module. -
building
Specific crafting building.
-
-
Constructor Details
-
AbstractCraftingBuildingModule
Create a new module.- Parameters:
jobEntry- the entry of the job.
-
-
Method Details
-
getRecipes
Description copied from interface:ICraftingBuildingModuleGet a list of all recipes of this module.- Specified by:
getRecipesin interfaceICraftingBuildingModule- Returns:
- the list of recipes.
-
setBuilding
Description copied from interface:IBuildingModuleSet the building of the module.- Specified by:
setBuildingin interfaceIBuildingModule- Overrides:
setBuildingin classAbstractBuildingModule- Parameters:
building- the building to set.- Returns:
- the module itself.
-
canRecipeBeAdded
Description copied from interface:ICraftingBuildingModuleCheck if a recipe can be added. This is only important for 3x3 crafting. Workers shall override this if necessary.- Specified by:
canRecipeBeAddedin interfaceICraftingBuildingModule- 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
- 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 @NotNull net.minecraft.nbt.CompoundTag compound) Description copied from interface:IPersistentModuleSerialize the module from a compound.- Specified by:
serializeNBTin interfaceIPersistentModule- Parameters:
compound- the compound.
-
deserializeNBT
public void deserializeNBT(net.minecraft.nbt.CompoundTag compound) Description copied from interface:IPersistentModuleDeserialize the module.- Specified by:
deserializeNBTin interfaceIPersistentModule- Parameters:
compound- the nbt compound.
-
serializeToView
public void serializeToView(@NotNull @NotNull net.minecraft.network.FriendlyByteBuf buf, boolean fullSync) Description copied from interface:IBuildingModuleSerialization method to send the module data to the client side.- Specified by:
serializeToViewin interfaceIBuildingModule- 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, getRequiredItemsAndAmount()Boolean>> Description copied from interface:IHasRequiredItemsModuleOverride 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:
getRequiredItemsAndAmountin interfaceIHasRequiredItemsModule- 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:IHasRequiredItemsModuleCalculate the number of reserved stacks the resolver can't touch.- Specified by:
reservedStacksExcludingin interfaceIHasRequiredItemsModule- Parameters:
request- ignore reservations that would exist for the current request.- Returns:
- a list of itemstorages.
-
isVisible
public boolean isVisible()Description copied from interface:ICraftingBuildingModuleCheck if the module on the client side should be displayed.- Specified by:
isVisiblein interfaceICraftingBuildingModule- Returns:
- true if so.
-
addRecipe
Description copied from interface:ICraftingBuildingModuleAdd a recipe to the building.- Specified by:
addRecipein interfaceICraftingBuildingModule- Parameters:
token- the id of the recipe.- Returns:
- true if successful
-
handleRecipeUpdate
Handle recipe update. Adjust request system to deal with recipe update.- Parameters:
token- the related recipe.
-
onColonyTick
Description copied from interface:ITickingModuleColony tick hook.- Specified by:
onColonyTickin interfaceITickingModule- Parameters:
colony- the colony the tick is invoked from.
-
checkForWorkerSpecificRecipes
public void checkForWorkerSpecificRecipes()Description copied from interface:ICraftingBuildingModuleUpdates existing requests, if they match the recipes available at this worker- Specified by:
checkForWorkerSpecificRecipesin interfaceICraftingBuildingModule
-
clearRecipes
public void clearRecipes()Description copied from interface:ICraftingBuildingModuleClear the list of recipes.- Specified by:
clearRecipesin interfaceICraftingBuildingModule
-
improveRecipe
Description copied from interface:ICraftingBuildingModuleRandomly improve a certain recipe.- Specified by:
improveRecipein interfaceICraftingBuildingModule- Parameters:
recipe- the recipe to improve.count- the craft counter.citizen- the citizen running it.
-
getFirstRecipe
Description copied from interface:ICraftingBuildingModuleGet the first recipe where the output matches this stack.- Specified by:
getFirstRecipein interfaceICraftingBuildingModule- 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:ICraftingBuildingModuleCheck if is the worker has the knowledge to craft something.- Specified by:
getFirstRecipein interfaceICraftingBuildingModule- Parameters:
stackPredicate- the predicate to check for fullfillment.- Returns:
- the recipe storage if so.
-
holdsRecipe
Description copied from interface:ICraftingBuildingModuleCheck if the recipe it part of this module.- Specified by:
holdsRecipein interfaceICraftingBuildingModule- Parameters:
token- the recipe token to check.- Returns:
- true if so.
-
getWarehouseCount
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:ICraftingBuildingModuleGet a fullfillable recipe to execute.- Specified by:
getFirstFulfillableRecipein interfaceICraftingBuildingModule- 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
Description copied from interface:ICraftingBuildingModuleFulfill the recipe.- Specified by:
fullFillRecipein interfaceICraftingBuildingModule- Parameters:
storage- the recipe storage to fulfill.- Returns:
- true if successful.
-
getCraftingTool
Description copied from interface:ICraftingBuildingModuleGet tool to use during fulFillRecipe- Specified by:
getCraftingToolin interfaceICraftingBuildingModule- Parameters:
worker- the worker to query for tool
-
getCraftingLuck
Description copied from interface:ICraftingBuildingModuleGet luck to use during fulFillRecipe- Specified by:
getCraftingLuckin interfaceICraftingBuildingModule- Parameters:
worker- the worker to calculate luck for
-
getCraftingJob
Description copied from interface:ICraftingBuildingModuleGets 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 caseICraftingBuildingModule.getId()must return different ids.- Specified by:
getCraftingJobin interfaceICraftingBuildingModule- Returns:
- The crafting job, or null if there is no such job.
-
updateWorkerAvailableForRecipes
public void updateWorkerAvailableForRecipes()Description copied from interface:ICraftingBuildingModuleUpdates existing requests, if they match the recipes available at this worker- Specified by:
updateWorkerAvailableForRecipesin interfaceICraftingBuildingModule
-
replaceRecipe
Description copied from interface:ICraftingBuildingModuleReplace one current recipe with a new one- Specified by:
replaceRecipein interfaceICraftingBuildingModule- Parameters:
oldRecipe- the recipe to replacenewRecipe- the new version
-
removeRecipe
Description copied from interface:ICraftingBuildingModuleRemove a recipe of the building.- Specified by:
removeRecipein interfaceICraftingBuildingModule- Parameters:
token- the id of the recipe.
-
addRecipeToList
Description copied from interface:ICraftingBuildingModuleAdd a recipe to the list of recipes.- Specified by:
addRecipeToListin interfaceICraftingBuildingModule- Parameters:
token- the token to add.
-
switchOrder
public void switchOrder(int i, int j, boolean fullMove) Description copied from interface:ICraftingBuildingModuleSwitch the order of two recipes.- Specified by:
switchOrderin interfaceICraftingBuildingModule- 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:ICraftingBuildingModuleEnable or disable a recipe at a location.- Specified by:
togglein interfaceICraftingBuildingModule- 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:ICraftingBuildingModuleGenerates 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:
getAdditionalRecipesForDisplayPurposesOnlyin interfaceICraftingBuildingModule- Returns:
- The list of additional recipes.
-
createResolvers
Description copied from interface:ICreatesResolversModuleGet a list of resolvers for this building.- Specified by:
createResolversin interfaceICreatesResolversModule- Returns:
- the list of resolvers.
-
getId
Deprecated.Description copied from interface:ICraftingBuildingModuleGets 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:
getIdin interfaceICraftingBuildingModule- Returns:
- The disambiguating id suffix.
-
getCustomRecipeKey
Description copied from interface:ICraftingBuildingModuleGets the unique key for recipes intended for this crafting module in the CustomRecipeManager. Precondition: getCraftingJob() returns non-null.- Specified by:
getCustomRecipeKeyin interfaceICraftingBuildingModule- Returns:
- The unique key.
-
getIngredientValidator
@NotNull public @NotNull OptionalPredicate<net.minecraft.world.item.ItemStack> getIngredientValidator()Description copied from interface:ICraftingBuildingModuleGets a predicate for recipe ingredients that are explicitly allowed or banned at this building. Used to reduce false negatives fromICraftingBuildingModule.isRecipeCompatible(com.minecolonies.api.crafting.IGenericRecipe)when alternatives are available.- Specified by:
getIngredientValidatorin interfaceICraftingBuildingModule- 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:ICraftingBuildingModuleCheck if the module should have a large limit for learnable recipes.- Specified by:
canLearnManyRecipesin interfaceICraftingBuildingModule- Returns:
- true if so.
-
isDisabled
Description copied from interface:ICraftingBuildingModuleCheck if a recipe is disabled.- Specified by:
isDisabledin interfaceICraftingBuildingModule- Parameters:
token- the recipe id to check for.- Returns:
- true if so.
-