Class LivingEntityEquipmentWrapper.SlotWrapper

All Implemented Interfaces:
ValueIOSerializable, ResourceHandler<ItemResource>
Enclosing class:
LivingEntityEquipmentWrapper

private class LivingEntityEquipmentWrapper.SlotWrapper extends ItemStackResourceHandler
The wrapper for a single EquipmentSlot, used as a building block.
  • Field Details

  • Constructor Details

  • Method Details

    • getStack

      protected ItemStack getStack()
      Description copied from class: ItemStackResourceHandler
      Return the stack of this handler. It will be modified directly sometimes to avoid needless copies. However, any mutation of the stack will directly be followed by a call to ItemStackResourceHandler.setStack(net.minecraft.world.item.ItemStack). This means that either returning the backing stack directly or a copy is safe. If returning a copy, consider overriding ItemStackResourceHandler.getAmountAsLong(int) and ItemStackResourceHandler.getResource(int) to avoid unnecessary copies.
      Specified by:
      getStack in class ItemStackResourceHandler
      Returns:
      The current stack.
    • setStack

      protected void setStack(ItemStack stack)
      Description copied from class: ItemStackResourceHandler
      Set the stack of this handler.
      Specified by:
      setStack in class ItemStackResourceHandler
    • isValid

      protected boolean isValid(ItemResource resource)
      Description copied from class: ItemStackResourceHandler
      Return true if the passed non-empty item resource can fit in this handler, false otherwise.

      The result of this function is used in the provided implementations of:

      Overrides:
      isValid in class ItemStackResourceHandler
    • getCapacity

      protected int getCapacity(ItemResource resource)
      Description copied from class: ItemStackResourceHandler
      Return the maximum capacity of this handler for the passed item resource. If the passed item resource is empty, an estimate should be returned.

      If the capacity should be limited by the max stack size of the item, this function must take it into account. Additionally, the empty resource should be special-cased to return the intended maximum capacity of the handler, as it will otherwise report a max stack size of 1. For example, a handler with a maximum count of 4, or less for items that have a smaller max stack size, should override this to return resource.isEmpty() ? 4 : Math.min(resource.getMaxStackSize(), 4).

      Overrides:
      getCapacity in class ItemStackResourceHandler
      Returns:
      The maximum capacity of this handler for the passed item resource.
    • onRootCommit

      protected void onRootCommit(ItemStack originalState)
      Description copied from class: SnapshotJournal
      Called after the root transaction was successfully committed, to perform irreversible actions such as setChanged() or neighbor updates.

      When a root transaction is being closed, all journals for which onRootCommit will be called are stored in a global thread-local queue. The processing of this queue starts immediately after the root transaction is closed. As such, new root transactions can safely be opened from this method.

      When a root transaction is opened from onRootCommit, any journal might be modified, leading to more onRootCommit callbacks being enqueued:

      • A journal that is already enqueued for onRootCommit will not be enqueued a second time. It will thus be notified a single time for changes that spanned multiple transactions. The originalState will be the state at the beginning of the first of these transactions.
      • A journal whose onRootCommit was already processed will be enqueued again. The journal will be notified a second time, with originalState the state at the beginning of the second transaction.
      • In particular, a journal is removed from the queue immediately before onRootCommit is called. Should the journal be modified again from its own onRootCommit, it will be added to the queue, and onRootCommit will be called again later.

      Given the large amount of actions that can happen between the last modification and the call to onRootCommit, journals should not depend on onRootCommit being called immediately for correctness, and implementations of this method should be careful (e.g. in case the journal got removed from the level). For example, skipping block change notifications because the block was removed from the level is preferable than crashing or silently overwriting the block.

      Overrides:
      onRootCommit in class SnapshotJournal<ItemStack>
      Parameters:
      originalState - state of this journal before the transactional operations. This corresponds to the first snapshot that was created in the transactional operations.
    • toString

      public String toString()
      Overrides:
      toString in class ItemStackResourceHandler