Interface PlayerInventoryStorage

All Superinterfaces:
InventoryStorage, Storage<ItemVariant>

@Experimental @Deprecated @NonExtendable public interface PlayerInventoryStorage extends InventoryStorage
Deprecated.
Experimental feature, we reserve the right to remove or change it without further notice. The transfer API is a complex addition, and we want to be able to correct possible design mistakes.
A Storage<ItemVariant> implementation for a PlayerInventory. This is a specialized version of InventoryStorage, with an additional transactional wrapper for PlayerInventory.offerOrDrop(net.minecraft.item.ItemStack).

Note that this is a wrapper around all the slots of the player inventory. This may cause direct insertion to insert arbitrary items into equipment slots or other unexpected behavior. To prevent this, offerOrDrop(net.fabricmc.fabric.api.transfer.v1.item.ItemVariant, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext) is recommended for simple insertions. InventoryStorage.getSlots() can also be used and combined with CombinedStorage to retrieve a wrapper around a specific range of slots.

  • Method Details

    • of

      static PlayerInventoryStorage of(net.minecraft.entity.player.PlayerEntity player)
      Deprecated.
      Return an instance for the passed player's inventory.
    • of

      static PlayerInventoryStorage of(net.minecraft.entity.player.PlayerInventory playerInventory)
      Deprecated.
      Return an instance for the passed player inventory.
    • getCursorStorage

      static SingleSlotStorage<ItemVariant> getCursorStorage(net.minecraft.screen.ScreenHandler screenHandler)
      Deprecated.
      Return a wrapper around the cursor slot of a screen handler, i.e. the stack that can be manipulated with ScreenHandler.getCursorStack() and ScreenHandler.setCursorStack(net.minecraft.item.ItemStack).
    • offerOrDrop

      void offerOrDrop(ItemVariant variant, long amount, TransactionContext transaction)
      Deprecated.
      Add items to the inventory if possible, and drop any leftover items in the world, similar to PlayerInventory.offerOrDrop(net.minecraft.item.ItemStack)

      Note: This function has full transaction support, and will not actually drop the items until the outermost transaction is committed.

      Parameters:
      variant - The variant to insert.
      amount - How many of the variant to insert.
      transaction - The transaction this operation is part of.