Class StackItemAccess

java.lang.Object
net.neoforged.neoforge.transfer.access.StackItemAccess
All Implemented Interfaces:
ItemAccess

class StackItemAccess extends Object implements ItemAccess
Implementation of ItemAccess that will mutate a stack directly, possibly changing the components and the count, but never the underlying Item as it's final.

This can be used when it is known that the resource handler will not change the underlying Item.

  • Field Details

  • Constructor Details

    • StackItemAccess

      public StackItemAccess(ItemStack stack)
  • Method Details

    • getResource

      public ItemResource getResource()
      Description copied from interface: ItemAccess
      Returns the currently stored item resource.
      Specified by:
      getResource in interface ItemAccess
    • getAmount

      public int getAmount()
      Description copied from interface: ItemAccess
      Returns the currently stored amount of the current resource.

      The returned amount must be non-negative. If the stored resource is empty, the amount must be 0.

      Specified by:
      getAmount in interface ItemAccess
    • insert

      public int insert(ItemResource resource, int amount, TransactionContext transaction)
      Description copied from interface: ItemAccess
      Inserts up to the given amount of an item resource into the accessed location.

      If the inserted item is not stackable with the current item, it may be inserted in a place that is inaccessible by ItemAccess.extract(net.neoforged.neoforge.transfer.item.ItemResource, int, net.neoforged.neoforge.transfer.transaction.TransactionContext), such as the player inventory.

      Changes to the accessed location are made in the context of a transaction.

      Specified by:
      insert in interface ItemAccess
      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).
    • extract

      public int extract(ItemResource resource, int amount, TransactionContext transaction)
      Description copied from interface: ItemAccess
      Extracts up to the given amount of an item resource from the accessed location.

      Changes to the accessed location are made in the context of a transaction.

      Specified by:
      extract in interface ItemAccess
      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).