Class AbstractRequest<R extends IRequestable>

java.lang.Object
com.minecolonies.core.colony.requestsystem.requests.AbstractRequest<R>
Type Parameters:
R - The type of request this is.
All Implemented Interfaces:
IRequest<R>
Direct Known Subclasses:
StandardRequests.AbstractCraftingRequest, StandardRequests.BurnableRequest, StandardRequests.DeliveryRequest, StandardRequests.FoodRequest, StandardRequests.ItemStackListRequest, StandardRequests.ItemStackRequest, StandardRequests.ItemTagRequest, StandardRequests.MinStackRequest, StandardRequests.PickupRequest, StandardRequests.SmeltAbleOreRequest, StandardRequests.ToolRequest

public abstract class AbstractRequest<R extends IRequestable> extends Object implements IRequest<R>
Abstract skeleton implementation of a request.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final net.minecraft.resources.ResourceLocation
    Default display icon (none).
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractRequest(@NotNull IRequester requester, @NotNull IToken<?> token, @NotNull RequestState state, R requested)
     
    protected
    AbstractRequest(@NotNull IRequester requester, @NotNull IToken<?> token, R requested)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <T extends IToken<?>>
    void
    addChild(T child)
    Method used to add a single Child.
    <T extends IToken<?>>
    void
    addChildren(@NotNull Collection<T> children)
    Method to add multiple children in a single call.
    <T extends IToken<?>>
    void
    addChildren(T... children)
    Method to add multiple children in a single call.
    void
    addDelivery(@NotNull List<net.minecraft.world.item.ItemStack> list)
    Adds a list of stacks as a delivery to this request.
    void
    addDelivery(@NotNull net.minecraft.world.item.ItemStack stack)
    Adds a single stack as a delivery to this request.
    boolean
    Method used to indicate that the result of this request can be delivered.
    void
    childStateUpdated(@NotNull IRequestManager manager, @NotNull IToken<?> child)
    Method called by a child state to indicate that its state has been updated.
    boolean
     
    @NotNull com.google.common.collect.ImmutableCollection<IToken<?>>
    Method to get the children of this request.
    @NotNull com.google.common.collect.ImmutableList<net.minecraft.world.item.ItemStack>
    Method to get the ItemStacks used for the delivery.
    @NotNull net.minecraft.resources.ResourceLocation
    Method used to get a ResourceLocation that is displayed instead of the IRequest.getDisplayStacks(), when IRequest.getDisplayStacks() returns an empty list.
    List<net.minecraft.world.item.ItemStack>
    Method used to get a List of ItemStacks that represents the stack.
    <T extends IToken<?>>
    T
    The unique token representing the request outside of the management system.
    @NotNull net.minecraft.network.chat.Component
    Method used to get a Component that can be displayed to the Player and describes so that the player can complete it.
    <T extends IToken<?>>
    T
    Returns the parent of this request.
    Return the object that is actually requested.
    @NotNull IRequester
    The location of the requester.
    <T> @NotNull Optional<T>
    Get a request of a specific type.
    List<net.minecraft.network.chat.MutableComponent>
    Get the resolver tooltip for a request.
    Returns the result of this request.
    @NotNull RequestState
    Returns the current state of the request.
    Set<com.google.common.reflect.TypeToken<?>>
    Get all super classes of this type (cached value).
    @NotNull com.google.common.reflect.TypeToken<? extends R>
    Used to determine which type of request this is.
    boolean
    Method to check if this request has children.
    int
     
    boolean
    Returns true if this request has a parent, false if not.
    boolean
    Method used to check if the result has been set.
    void
    overrideCurrentDeliveries(@NotNull com.google.common.collect.ImmutableList<net.minecraft.world.item.ItemStack> stacks)
    Sets the deliveries of this request to the given stacks
    <T extends IToken<?>>
    void
    removeChild(T child)
    Method used to remove a single Child.
    <T extends IToken<?>>
    void
    removeChildren(@NotNull Collection<T> children)
    Method to remove multiple children in a single call.
    <T extends IToken<?>>
    void
    removeChildren(T... children)
    Method to remove multiple children in a single call.
    void
    Reset the deliveries of the request.
    <T extends IToken<?>>
    void
    setParent(T parent)
    Method used to set the parent of a request.
    void
    setResult(R result)
    Setter for the result of the request.
    void
    setState(@NotNull IRequestManager manager, @NotNull RequestState state)
    Setter for the current state of this request.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.minecolonies.api.colony.requestsystem.request.IRequest

    getShortDisplayString, getStrategy
  • Field Details

    • MISSING

      public static final net.minecraft.resources.ResourceLocation MISSING
      Default display icon (none).
  • Constructor Details

    • AbstractRequest

      protected AbstractRequest(@NotNull @NotNull IRequester requester, @NotNull @NotNull IToken<?> token, @NotNull R requested)
    • AbstractRequest

      protected AbstractRequest(@NotNull @NotNull IRequester requester, @NotNull @NotNull IToken<?> token, @NotNull @NotNull RequestState state, @NotNull R requested)
  • Method Details

    • getType

      @NotNull public @NotNull com.google.common.reflect.TypeToken<? extends R> getType()
      Used to determine which type of request this is. Only RequestResolvers for this Type are then used to resolve the this.
      Specified by:
      getType in interface IRequest<R extends IRequestable>
      Returns:
      The class that represents this Type of Request.
    • getRequester

      @NotNull public @NotNull IRequester getRequester()
      The location of the requester. Is generally used in getDelivery requests to produce a getDelivery for a result from this request.
      Specified by:
      getRequester in interface IRequest<R extends IRequestable>
      Returns:
      The location of requester of this request.
    • getId

      public <T extends IToken<?>> T getId()
      The unique token representing the request outside of the management system.
      Specified by:
      getId in interface IRequest<R extends IRequestable>
      Type Parameters:
      T - generic token.
      Returns:
      the token representing the request outside of the management system.
    • getState

      @NotNull public @NotNull RequestState getState()
      Returns the current state of the request.
      Specified by:
      getState in interface IRequest<R extends IRequestable>
      Returns:
      The current state.
    • setState

      public void setState(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull RequestState state)
      Setter for the current state of this request.

      The implementing class is responsible for propagating the state change to its parent, if needed.

      Specified by:
      setState in interface IRequest<R extends IRequestable>
      Parameters:
      manager - The request manager that updated the state.
      state - The new state of this request.
    • getRequest

      @NotNull public R getRequest()
      Return the object that is actually requested. A RequestResolver can compare this object however way it sees fit.

      During the resolving process this object is called multiple times. But at least twice. A cached implementation is preferred.

      Specified by:
      getRequest in interface IRequest<R extends IRequestable>
      Returns:
      The object that is actually requested.
    • getResult

      @Nullable public R getResult()
      Returns the result of this request.
      Specified by:
      getResult in interface IRequest<R extends IRequestable>
      Returns:
      The result of this request, or null if it is not available.
    • setResult

      public void setResult(@NotNull R result)
      Setter for the result of the request.
      Specified by:
      setResult in interface IRequest<R extends IRequestable>
      Parameters:
      result - The new result of this request.
    • hasResult

      public boolean hasResult()
      Method used to check if the result has been set.
      Specified by:
      hasResult in interface IRequest<R extends IRequestable>
      Returns:
      True when the result has been set, false when not.
    • getParent

      @Nullable public <T extends IToken<?>> T getParent()
      Returns the parent of this request. If this is set it means that this request is part of request chain.
      Specified by:
      getParent in interface IRequest<R extends IRequestable>
      Type Parameters:
      T - generic token.
      Returns:
      The parent of this request, or null if it has no parent.
    • setParent

      public <T extends IToken<?>> void setParent(@Nullable T parent)
      Method used to set the parent of a request.
      Specified by:
      setParent in interface IRequest<R extends IRequestable>
      Type Parameters:
      T - generic token.
      Parameters:
      parent - The new parent, or null to clear the existing one.
    • hasParent

      public boolean hasParent()
      Returns true if this request has a parent, false if not.
      Specified by:
      hasParent in interface IRequest<R extends IRequestable>
      Returns:
      true if this request has a parent, false if not.
    • addChild

      public <T extends IToken<?>> void addChild(@NotNull T child)
      Method used to add a single Child.
      Specified by:
      addChild in interface IRequest<R extends IRequestable>
      Type Parameters:
      T - generic token.
      Parameters:
      child - The new child request to add.
    • addChildren

      public <T extends IToken<?>> void addChildren(@NotNull T... children)
      Method to add multiple children in a single call.
      Specified by:
      addChildren in interface IRequest<R extends IRequestable>
      Type Parameters:
      T - generic token.
      Parameters:
      children - An array of children to add.
    • addChildren

      public <T extends IToken<?>> void addChildren(@NotNull @NotNull Collection<T> children)
      Method to add multiple children in a single call.
      Specified by:
      addChildren in interface IRequest<R extends IRequestable>
      Type Parameters:
      T - generic token.
      Parameters:
      children - A collection of children to add.
    • removeChild

      public <T extends IToken<?>> void removeChild(@NotNull T child)
      Method used to remove a single Child.
      Specified by:
      removeChild in interface IRequest<R extends IRequestable>
      Type Parameters:
      T - generic token.
      Parameters:
      child - The new child request to remove.
    • removeChildren

      public <T extends IToken<?>> void removeChildren(@NotNull T... children)
      Method to remove multiple children in a single call.
      Specified by:
      removeChildren in interface IRequest<R extends IRequestable>
      Type Parameters:
      T - generic token.
      Parameters:
      children - An array of children to remove.
    • removeChildren

      public <T extends IToken<?>> void removeChildren(@NotNull @NotNull Collection<T> children)
      Method to remove multiple children in a single call.
      Specified by:
      removeChildren in interface IRequest<R extends IRequestable>
      Type Parameters:
      T - generic token.
      Parameters:
      children - A collection of children to remove.
    • hasChildren

      public boolean hasChildren()
      Method to check if this request has children.
      Specified by:
      hasChildren in interface IRequest<R extends IRequestable>
      Returns:
      true if it has children.
    • getChildren

      @NotNull public @NotNull com.google.common.collect.ImmutableCollection<IToken<?>> getChildren()
      Method to get the children of this request. Immutable.
      Specified by:
      getChildren in interface IRequest<R extends IRequestable>
      Returns:
      An immutable collection of the children of this request.
    • childStateUpdated

      public void childStateUpdated(@NotNull @NotNull IRequestManager manager, @NotNull @NotNull IToken<?> child)
      Method called by a child state to indicate that its state has been updated.
      Specified by:
      childStateUpdated in interface IRequest<R extends IRequestable>
      Parameters:
      manager - The manager that caused the update on the child.
      child - The child that was updated.
    • canBeDelivered

      public boolean canBeDelivered()
      Method used to indicate that the result of this request can be delivered.
      Specified by:
      canBeDelivered in interface IRequest<R extends IRequestable>
      Returns:
      True for requests that can be delivered, false when not.
    • getDeliveries

      @NotNull public @NotNull com.google.common.collect.ImmutableList<net.minecraft.world.item.ItemStack> getDeliveries()
      Description copied from interface: IRequest
      Method to get the ItemStacks used for the delivery.
      Specified by:
      getDeliveries in interface IRequest<R extends IRequestable>
      Returns:
      The ItemStacks that the Deliveryman transports around. AbstractCollection.isEmpty() means no delivery possible.
    • overrideCurrentDeliveries

      public void overrideCurrentDeliveries(@NotNull @NotNull com.google.common.collect.ImmutableList<net.minecraft.world.item.ItemStack> stacks)
      Description copied from interface: IRequest
      Sets the deliveries of this request to the given stacks
      Specified by:
      overrideCurrentDeliveries in interface IRequest<R extends IRequestable>
      Parameters:
      stacks - The stacks that will be the deliveries.
    • addDelivery

      public void addDelivery(@NotNull @NotNull net.minecraft.world.item.ItemStack stack)
      Description copied from interface: IRequest
      Adds a single stack as a delivery to this request.
      Specified by:
      addDelivery in interface IRequest<R extends IRequestable>
      Parameters:
      stack - The stack that should be treated as a new delivery.
    • addDelivery

      public void addDelivery(@NotNull @NotNull List<net.minecraft.world.item.ItemStack> list)
      Description copied from interface: IRequest
      Adds a list of stacks as a delivery to this request.
      Specified by:
      addDelivery in interface IRequest<R extends IRequestable>
      Parameters:
      list - The list of stacks that should be treated as a new delivery.
    • resetDeliveries

      public void resetDeliveries()
      Description copied from interface: IRequest
      Reset the deliveries of the request.
      Specified by:
      resetDeliveries in interface IRequest<R extends IRequestable>
    • getLongDisplayString

      @NotNull public @NotNull net.minecraft.network.chat.Component getLongDisplayString()
      Description copied from interface: IRequest
      Method used to get a Component that can be displayed to the Player and describes so that the player can complete it. Should represent the request, in case the player needs to fulfill it, or information about this request is required.
      Specified by:
      getLongDisplayString in interface IRequest<R extends IRequestable>
      Returns:
      The text that describes this Request.
    • getDisplayIcon

      @NotNull public @NotNull net.minecraft.resources.ResourceLocation getDisplayIcon()
      Description copied from interface: IRequest
      Method used to get a ResourceLocation that is displayed instead of the IRequest.getDisplayStacks(), when IRequest.getDisplayStacks() returns an empty list.
      Specified by:
      getDisplayIcon in interface IRequest<R extends IRequestable>
      Returns:
      The ResourceLocation of the Image dat is displayed when their are no DisplayStacks.
    • getResolverToolTip

      public List<net.minecraft.network.chat.MutableComponent> getResolverToolTip(IColonyView colony)
      Description copied from interface: IRequest
      Get the resolver tooltip for a request.
      Specified by:
      getResolverToolTip in interface IRequest<R extends IRequestable>
      Parameters:
      colony - the colony view to obtain information if necessary.
      Returns:
      a list of strings or empty.
    • getDisplayStacks

      public List<net.minecraft.world.item.ItemStack> getDisplayStacks()
      Description copied from interface: IRequest
      Method used to get a List of ItemStacks that represents the stack. This list is used in GUI to show what the request is. If an empty list is returned then no stack is shown. If a list with multiple stacks is returned it will switch between the stacks once every second unless the player holds the shift key.
      Specified by:
      getDisplayStacks in interface IRequest<R extends IRequestable>
      Returns:
      A List of ItemStacks that represents this request.
    • getRequestOfType

      @NotNull public <T> @NotNull Optional<T> getRequestOfType(Class<T> tClass)
      Description copied from interface: IRequest
      Get a request of a specific type.
      Specified by:
      getRequestOfType in interface IRequest<R extends IRequestable>
      Type Parameters:
      T - the type.
      Parameters:
      tClass - the class of it.
      Returns:
      the request of this particular type.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getSuperClasses

      public Set<com.google.common.reflect.TypeToken<?>> getSuperClasses()
      Description copied from interface: IRequest
      Get all super classes of this type (cached value).
      Specified by:
      getSuperClasses in interface IRequest<R extends IRequestable>
      Returns:
      an immutable copy of the set.