Class AbstractCraftingRequestResolver
- All Implemented Interfaces:
IRequester,IRequestResolver<IDeliverable>,IBuildingBasedRequester
- Direct Known Subclasses:
PrivateWorkerCraftingRequestResolver,PublicWorkerCraftingRequestResolver
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal booleanVariable to check if requests can be requested externally. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractCraftingRequestResolver(@NotNull ILocation location, @NotNull IToken<?> token, @NotNull JobEntry entry, boolean isPublicCrafter) Constructor to initialize. -
Method Summary
Modifier and TypeMethodDescriptionattemptResolveForBuilding(@NotNull IRequestManager manager, @NotNull IRequest<? extends IDeliverable> request, @NotNull AbstractBuilding building) attemptResolveForBuildingAndStack(@NotNull IRequestManager manager, @NotNull AbstractBuilding building, @NotNull Predicate<net.minecraft.world.item.ItemStack> stackPrecicate, int count, int minCount) attemptResolveRequest(@NotNull IRequestManager manager, @NotNull IRequest<? extends IDeliverable> request) Method used to attempt a resolving operation.abstract booleancanBuildingCraftRecipe(@NotNull AbstractBuilding building, IRecipeStorage recipe) Check if a building can craft a certain recipe.booleancanResolveForBuilding(@NotNull IRequestManager manager, @NotNull IRequest<? extends IDeliverable> request, @NotNull AbstractBuilding building) Check if the request can be resolved for this building.booleancanResolveRequest(@NotNull IRequestManager manager, IRequest<? extends IDeliverable> requestToCheck) A PreCheck used to determine if this request resolver is able to resolve a given request.protected abstract IRequestablecreateNewRequestableForStack(net.minecraft.world.item.ItemStack stack, int count, int minCount, IToken<?> recipeId) Create a new requestable for a stack.createRequestsForRecipe(@NotNull IRequestManager manager, IRecipeStorage recipeRequest, int count, int minCount) Create the crafting request entries for the overall request Will produce multiple, if the ingredients don't all fit in the crafters inventory.protected booleancreatesCraftingCycle(@NotNull IRequestManager manager, @NotNull IRequest<?> request, @NotNull IDeliverable target, @Nullable IRequest<? extends IDeliverable> targetRequest) Method to check if a crafting cycle can be created.protected booleancreatesCraftingCycle(@NotNull IRequestManager manager, @NotNull IRequest<?> request, @NotNull IDeliverable target, @Nullable IRequest<? extends IDeliverable> targetRequest, int count) Method to check if a crafting loop is created.getBuilding(@NotNull IRequestManager manager, @NotNull IToken<?> token) Get the building.Getter of the job entry.com.google.common.reflect.TypeToken<? extends IDeliverable> Used to determine which type of requests can be resolved by this Resolver.intgetSuitabilityMetric(@NotNull IRequestManager manager, @NotNull IRequest<? extends IDeliverable> request) Check how suitable this resolver is for the request.booleanisValid()If this resolver has valid data in it.voidonRequestedRequestComplete(@NotNull IRequestManager manager, @NotNull IRequest<?> request) Method called by the request system to notify this requester that a request is complete.voidresolveForBuilding(@NotNull IRequestManager manager, @NotNull IRequest<? extends IDeliverable> request, @NotNull AbstractBuilding building) Resolve the request in a building.voidresolveRequest(@NotNull IRequestManager manager, @NotNull IRequest<? extends IDeliverable> request) Method used to resolve a given request.Methods inherited from class com.minecolonies.core.colony.requestsystem.resolvers.core.AbstractRequestResolver
getId, getLocation, getPriority, getRequesterDisplayNameMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.minecolonies.api.colony.requestsystem.requester.IRequester
getId, getLocation, getRequesterDisplayName, onRequestedRequestCancelledMethods inherited from interface com.minecolonies.api.colony.requestsystem.resolver.IRequestResolver
getFollowupRequestForCompletion, onAssignedRequestBeingCancelled, onAssignedRequestCancelled, onColonyUpdate, onRequestAssigned
-
Field Details
-
isPublicCrafter
public final boolean isPublicCrafterVariable to check if requests can be requested externally.
-
-
Constructor Details
-
AbstractCraftingRequestResolver
public AbstractCraftingRequestResolver(@NotNull @NotNull ILocation location, @NotNull @NotNull IToken<?> token, @NotNull @NotNull JobEntry entry, boolean isPublicCrafter) Constructor to initialize.- Parameters:
location- the location.token- the id.isPublicCrafter- if public crafter or not.
-
-
Method Details
-
getJobEntry
Getter of the job entry.- Returns:
- the entry.
-
getRequestType
Description copied from interface:IRequestResolverUsed to determine which type of requests can be resolved by this Resolver.- Specified by:
getRequestTypein interfaceIRequestResolver<IDeliverable>- Returns:
- The class that represents this Type of Request this resolver can resolve.
-
getBuilding
public Optional<IRequester> getBuilding(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IToken<?> token) Description copied from interface:IBuildingBasedRequesterGet the building.- Specified by:
getBuildingin interfaceIBuildingBasedRequester- Parameters:
manager- the manager.token- the token.- Returns:
- the IRequester or empty.
-
onRequestedRequestComplete
public void onRequestedRequestComplete(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<?> request) Description copied from interface:IRequesterMethod called by the request system to notify this requester that a request is complete.- Specified by:
onRequestedRequestCompletein interfaceIRequester- Parameters:
manager- the request manager.request- the request.
-
getSuitabilityMetric
public int getSuitabilityMetric(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends IDeliverable> request) Description copied from interface:IRequestResolverCheck how suitable this resolver is for the request.- Specified by:
getSuitabilityMetricin interfaceIRequestResolver<IDeliverable>- Overrides:
getSuitabilityMetricin classAbstractRequestResolver<IDeliverable>- Parameters:
manager- the req manager.request- the request to check.- Returns:
- the suitability metric (an int for easy comparison).
-
canResolveRequest
public boolean canResolveRequest(@NotNull @NotNull IRequestManager manager, IRequest<? extends IDeliverable> requestToCheck) Description copied from interface:IRequestResolverA PreCheck used to determine if this request resolver is able to resolve a given request. Should quickly and cheaply check if this resolver COULD resolve this request.- Specified by:
canResolveRequestin interfaceIRequestResolver<IDeliverable>- Parameters:
manager- The manager that is checking if this resolver could resolve that request.requestToCheck- The request to check.- Returns:
- True when this resolver COULD resolve the given request, false when not.
-
canResolveForBuilding
public boolean canResolveForBuilding(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends IDeliverable> request, @NotNull @NotNull AbstractBuilding building) Check if the request can be resolved for this building.- Parameters:
manager- the manager.request- the request to check.building- the building to check.- Returns:
- true if so.
-
createsCraftingCycle
protected boolean createsCraftingCycle(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<?> request, @NotNull @NotNull IDeliverable target, @Nullable @Nullable IRequest<? extends IDeliverable> targetRequest) Method to check if a crafting cycle can be created.- Parameters:
manager- the manager.request- the request.target- the target.- Returns:
- true if so.
-
createsCraftingCycle
protected boolean createsCraftingCycle(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<?> request, @NotNull @NotNull IDeliverable target, @Nullable @Nullable IRequest<? extends IDeliverable> targetRequest, int count) Method to check if a crafting loop is created.- Parameters:
manager- the manager.request- the request.target- the target to create.count- the itemCount.- Returns:
- true if a loop is detected to abort.
-
canBuildingCraftRecipe
public abstract boolean canBuildingCraftRecipe(@NotNull @NotNull AbstractBuilding building, IRecipeStorage recipe) Check if a building can craft a certain recipe.- Parameters:
building- the building to check in.recipe- the recipe to check.- Returns:
- true if so.
-
attemptResolveRequest
@Nullable public @Nullable List<IToken<?>> attemptResolveRequest(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends IDeliverable> request) Description copied from interface:IRequestResolverMethod used to attempt a resolving operation.When this attempt was successful a List with tokens of required requests is returned. This list maybe empty. The list should indicate all sub requests that should be fullfilled before the @code{resolve(IRequest request)} method is called.
When this attempt was not successful, eg. this resolver could not schedule a crafting operation, a Null object should be returned. In that case the next resolver will be tried by the manager.
IT IS VITAL THAT THE REQUEST RETURNED ARE NOT YET ASSIGNED. SIMULATION AND OTHER STRATEGIES WILL FAIL ELSE! THE MANAGER GIVEN WILL HANDLE ASSIGNING HIMSELF!
- Specified by:
attemptResolveRequestin interfaceIRequestResolver<IDeliverable>- Parameters:
manager- The manager that is attempting to resolve using this resolver.request- The request to resolve.- Returns:
- The tokens of required requests if the attempt was successful (an empty list is allowed to indicate no requirements), null if the attempt failed.
-
attemptResolveForBuilding
@Nullable public @Nullable List<IToken<?>> attemptResolveForBuilding(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends IDeliverable> request, @NotNull @NotNull AbstractBuilding building) -
attemptResolveForBuildingAndStack
@Nullable protected @Nullable List<IToken<?>> attemptResolveForBuildingAndStack(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull AbstractBuilding building, @NotNull @NotNull Predicate<net.minecraft.world.item.ItemStack> stackPrecicate, int count, int minCount) -
createRequestsForRecipe
@Nullable protected @Nullable List<IToken<?>> createRequestsForRecipe(@NotNull @NotNull IRequestManager manager, IRecipeStorage recipeRequest, int count, int minCount) Create the crafting request entries for the overall request Will produce multiple, if the ingredients don't all fit in the crafters inventory.- Parameters:
manager- request managerrecipeRequest- requested recipe instancecount- count of item requestedminCount- minimum count required- Returns:
- List of crafting requests necessary to fulfill the overall requests
-
createNewRequestableForStack
protected abstract IRequestable createNewRequestableForStack(net.minecraft.world.item.ItemStack stack, int count, int minCount, IToken<?> recipeId) Create a new requestable for a stack.- Parameters:
stack- the stack to request.count- the count needed.minCount- the min count to fulfill.- Returns:
- the requestable.
-
resolveRequest
public void resolveRequest(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends IDeliverable> request) Description copied from interface:IRequestResolverMethod used to resolve a given request. Is called the moment all Child requests are resolved.The resolver should update the state through the given manager.
When this method is called all requirements need be fullfilled for this resolver. If this is not the case it will throw a RunTimeException
- Specified by:
resolveRequestin interfaceIRequestResolver<IDeliverable>- Parameters:
manager- The manager that is resolving this request, under normal conditions this is the colony manager.request- The request to resolve.
-
resolveForBuilding
public void resolveForBuilding(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IRequest<? extends IDeliverable> request, @NotNull @NotNull AbstractBuilding building) Resolve the request in a building.- Parameters:
manager- the request manager.request- the request.building- the building.
-
isValid
public boolean isValid()Description copied from interface:IRequestResolverIf this resolver has valid data in it.- Specified by:
isValidin interfaceIRequestResolver<IDeliverable>- Returns:
- true if so.
-