Record Class OneByOneItemAccess

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

record OneByOneItemAccess(ItemAccess delegate) extends Record implements ItemAccess
  • Field Details

    • delegate

      private final ItemAccess delegate
      The field for the delegate record component.
  • Constructor Details

    • OneByOneItemAccess

      OneByOneItemAccess(ItemAccess delegate)
      Creates an instance of a OneByOneItemAccess record class.
      Parameters:
      delegate - the value for the delegate record component
  • 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).
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • delegate

      public ItemAccess delegate()
      Returns the value of the delegate record component.
      Returns:
      the value of the delegate record component