Class RangedResourceHandler<T extends Resource>

java.lang.Object
net.neoforged.neoforge.transfer.DelegatingResourceHandler<T>
net.neoforged.neoforge.transfer.RangedResourceHandler<T>
All Implemented Interfaces:
ResourceHandler<T>

public class RangedResourceHandler<T extends Resource> extends DelegatingResourceHandler<T>
A resource handler that wraps a range of indices of another handler.
  • Field Details

    • start

      protected int start
    • end

      protected int end
  • Constructor Details

    • RangedResourceHandler

      protected RangedResourceHandler(ResourceHandler<T> delegate, int start, int end)
    • RangedResourceHandler

      protected RangedResourceHandler(Supplier<ResourceHandler<T>> delegate, int start, int end)
  • Method Details

    • of

      public static <T extends Resource> RangedResourceHandler<T> of(ResourceHandler<T> delegate, int start, int end)
      Creates a wrapper for a range of indices.
      Parameters:
      start - start of the range of indices, inclusive
      end - end of the range of indices, exclusive
    • of

      public static <T extends Resource> RangedResourceHandler<T> of(Supplier<ResourceHandler<T>> delegate, int start, int end)
      Creates a wrapper for a range of indices, with the passed supplier being queried every time the handler is accessed.
      Parameters:
      start - start of the range of indices, inclusive
      end - end of the range of indices, exclusive
    • ofSingleIndex

      public static <T extends Resource> RangedResourceHandler<T> ofSingleIndex(ResourceHandler<T> delegate, int index)
      Creates a wrapper for a single index.
    • ofSingleIndex

      public static <T extends Resource> RangedResourceHandler<T> ofSingleIndex(Supplier<ResourceHandler<T>> delegate, int index)
      Creates a wrapper for a single index, with the passed supplier being queried every time the handler is accessed.
    • size

      public int size()
      Description copied from interface: ResourceHandler
      Returns the current number of indices in this resource handler.

      This size provides a bound on the valid indices for this handler, see the documentation of ResourceHandler.

      Specified by:
      size in interface ResourceHandler<T extends Resource>
      Overrides:
      size in class DelegatingResourceHandler<T extends Resource>
      Returns:
      The size of the resource handler. Can be 0 if the handler currently has no indices.
    • convertIndex

      protected int convertIndex(int index)
      Description copied from class: DelegatingResourceHandler
      Converts the external index to the internal index to use for the delegated-to handler.
      Overrides:
      convertIndex in class DelegatingResourceHandler<T extends Resource>
    • extract

      public int extract(T resource, int amount, TransactionContext transaction)
      Description copied from interface: ResourceHandler
      Tries to extract up to the given amount of a resource from the handler.

      This function is preferred to the index-specific overload since it lets the handler decide how to find indices that contain the resource.

      This method is expected to be more efficient than callers trying to find indices that contain the resource themselves.

      Changes to the handler are made in the context of a transaction.

      Specified by:
      extract in interface ResourceHandler<T extends Resource>
      Overrides:
      extract in class DelegatingResourceHandler<T extends Resource>
      Parameters:
      resource - The resource to extract. Must be non-empty.
      amount - The maximum amount of the resource to extract. Must be non-negative.
      transaction - The transaction that this operation is part of.
      Returns:
      The amount that was extracted. Between 0 (inclusive, nothing was extracted) and amount (inclusive, everything was extracted).
      See Also:
    • insert

      public int insert(T resource, int amount, TransactionContext transaction)
      Description copied from interface: ResourceHandler
      Inserts up to the given amount of a resource into the handler.

      This function is preferred to the index-specific overload since it lets the handler decide how to distribute the resource.

      This method is expected to be more efficient than callers trying to find a suitable index for insertion themselves.

      Changes to the handler are made in the context of a transaction.

      Specified by:
      insert in interface ResourceHandler<T extends Resource>
      Overrides:
      insert in class DelegatingResourceHandler<T extends Resource>
      Parameters:
      resource - The resource to insert. Must be non-empty.
      amount - The maximum amount of the resource to insert. Must be non-negative.
      transaction - The transaction that this operation is part of.
      Returns:
      The amount that was inserted. Between 0 (inclusive, nothing was inserted) and amount (inclusive, everything was inserted).
      See Also: