Class ItemUtil

java.lang.Object
net.neoforged.neoforge.transfer.item.ItemUtil

public final class ItemUtil extends Object
Helper functions to work with ResourceHandlers of ItemResources.
  • Constructor Details

    • ItemUtil

      private ItemUtil()
  • Method Details

    • getStack

      public static ItemStack getStack(ResourceHandler<ItemResource> handler, int index)
      Returns a new item stack with the contents of the handler at the given index.

      The result's stack size may be greater than the max stack size.

    • insertItemReturnRemaining

      public static ItemStack insertItemReturnRemaining(ResourceHandler<ItemResource> handler, ItemStack stack, boolean simulate, @Nullable @Nullable TransactionContext transaction)
      Attempts to insert an item stack into a handler, leaving distribution to the handler, and returning any leftover.
      Parameters:
      handler - handler to insert into
      stack - the stack to insert, will not be modified by this function
      simulate - true to simulate the result of the insert but leave the handler unmodified, false to modify the handler
      transaction - The transaction that this operation is part of. This method will always use a nested transaction that will be rolled back. null can be passed to conveniently have this method open its own root transaction.
      Returns:
      the leftover: the stack of items that could not be inserted
    • insertItemReturnRemaining

      public static ItemStack insertItemReturnRemaining(ResourceHandler<ItemResource> handler, int index, ItemStack stack, boolean simulate, @Nullable @Nullable TransactionContext transaction)
      Attempts to insert an item stack into the index of a handler, returning any leftover.
      Parameters:
      handler - handler to insert into
      index - index to insert into
      stack - the stack to insert, will not be modified by this function
      simulate - true to simulate the result of the insert but leave the handler unmodified, false to modify the handler
      transaction - The transaction that this operation is part of. This method will always use a nested transaction that will be rolled back. null can be passed to conveniently have this method open its own root transaction.
      Returns:
      the leftover: the stack of items that could not be inserted