Class AbstractCraftingRequestResolver

java.lang.Object
com.minecolonies.core.colony.requestsystem.resolvers.core.AbstractRequestResolver<IDeliverable>
com.minecolonies.core.colony.requestsystem.resolvers.core.AbstractCraftingRequestResolver
All Implemented Interfaces:
IRequester, IRequestResolver<IDeliverable>, IBuildingBasedRequester
Direct Known Subclasses:
PrivateWorkerCraftingRequestResolver, PublicWorkerCraftingRequestResolver

public abstract class AbstractCraftingRequestResolver extends AbstractRequestResolver<IDeliverable> implements IBuildingBasedRequester
Abstract crafting resolver for all crafting tasks.
  • Field Details

    • isPublicCrafter

      public final boolean isPublicCrafter
      Variable 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

      public JobEntry getJobEntry()
      Getter of the job entry.
      Returns:
      the entry.
    • getRequestType

      public com.google.common.reflect.TypeToken<? extends IDeliverable> getRequestType()
      Description copied from interface: IRequestResolver
      Used to determine which type of requests can be resolved by this Resolver.
      Specified by:
      getRequestType in interface IRequestResolver<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: IBuildingBasedRequester
      Get the building.
      Specified by:
      getBuilding in interface IBuildingBasedRequester
      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: IRequester
      Method called by the request system to notify this requester that a request is complete.
      Specified by:
      onRequestedRequestComplete in interface IRequester
      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: IRequestResolver
      Check how suitable this resolver is for the request.
      Specified by:
      getSuitabilityMetric in interface IRequestResolver<IDeliverable>
      Overrides:
      getSuitabilityMetric in class AbstractRequestResolver<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: IRequestResolver
      A 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:
      canResolveRequest in interface IRequestResolver<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: IRequestResolver
      Method 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:
      attemptResolveRequest in interface IRequestResolver<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 manager
      recipeRequest - requested recipe instance
      count - count of item requested
      minCount - 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: IRequestResolver
      Method 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:
      resolveRequest in interface IRequestResolver<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: IRequestResolver
      If this resolver has valid data in it.
      Specified by:
      isValid in interface IRequestResolver<IDeliverable>
      Returns:
      true if so.