Interface PlayerInventoryStorage
- All Superinterfaces:
ContainerStorage, Iterable<StorageView<ItemVariant>>, SlottedStorage<ItemVariant>, Storage<ItemVariant>
Storage<ItemVariant> implementation for a Inventory.
This is a specialized version of ContainerStorage,
with an additional transactional wrapper for Inventory.placeItemBackInInventory(ItemStack).
Note that this is a wrapper around all the slots of the player inventory.
However, insert(ItemVariant, long, TransactionContext) is overridden to behave like offer(ItemVariant, long, TransactionContext).
For simple insertions, offer(ItemVariant, long, TransactionContext) or offerOrDrop(ItemVariant, long, TransactionContext) is recommended.
ContainerStorage.getSlots() can also be used and combined with CombinedStorage to retrieve a wrapper around a specific range of slots.
-
Method Summary
Modifier and TypeMethodDescriptionvoiddrop(ItemVariant variant, long amount, boolean throwRandomly, boolean retainOwnership, TransactionContext transaction) Throw items in the world from the player's location.default voiddrop(ItemVariant variant, long amount, boolean retainOwnership, TransactionContext transaction) Throw items in the world from the player's location.default voiddrop(ItemVariant variant, long amount, TransactionContext transaction) Throw items in the world from the player's location.static SingleSlotStorage<ItemVariant> getCursorStorage(net.minecraft.world.inventory.AbstractContainerMenu menu) Return a wrapper around the cursor slot of a menu, i.e.getHandSlot(net.minecraft.world.InteractionHand hand) Return a wrapper around the current slot of the passed hand.longinsert(ItemVariant resource, long maxAmount, TransactionContext transaction) Insert items into this player inventory.static PlayerInventoryStorageof(net.minecraft.world.entity.player.Inventory playerInventory) Return an instance for the passed player inventory.static PlayerInventoryStorageof(net.minecraft.world.entity.player.Player player) Return an instance for the passed player's inventory.longoffer(ItemVariant variant, long maxAmount, TransactionContext transaction) Try to add items to the inventory if possible, stacking likeInventory.placeItemBackInInventory(ItemStack).default voidofferOrDrop(ItemVariant variant, long amount, TransactionContext transaction) Add items to the inventory if possible, and drop any leftover items in the world, similar toInventory.placeItemBackInInventory(ItemStack).Methods inherited from interface ContainerStorage
getSlot, getSlotCount, getSlotsMethods inherited from interface Iterable
forEach, spliteratorMethods inherited from interface Storage
extract, getVersion, iterator, nonEmptyIterator, nonEmptyViews, supportsExtraction, supportsInsertion
-
Method Details
-
of
Return an instance for the passed player's inventory. -
of
Return an instance for the passed player inventory. -
getCursorStorage
static SingleSlotStorage<ItemVariant> getCursorStorage(net.minecraft.world.inventory.AbstractContainerMenu menu) Return a wrapper around the cursor slot of a menu, i.e. the stack that can be manipulated withAbstractContainerMenu.getCarried()andAbstractContainerMenu.setCarried(ItemStack). -
insert
Insert items into this player inventory. Behaves the same asoffer(ItemVariant, long, TransactionContext). More fine-tuned insertion, for example over a specific range of slots, is possible with the slot list.- Specified by:
insertin interfaceStorage<ItemVariant>- Parameters:
resource- The resource to insert. May not be blank.maxAmount- The maximum amount of resource to insert. May not be negative.transaction- The transaction this operation is part of.- Returns:
- A non-negative integer not greater than maxAmount: the amount that was inserted.
- See Also:
-
offerOrDrop
Add items to the inventory if possible, and drop any leftover items in the world, similar toInventory.placeItemBackInInventory(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.
-
offer
Try to add items to the inventory if possible, stacking likeInventory.placeItemBackInInventory(ItemStack). UnlikeofferOrDrop(ItemVariant, long, TransactionContext), this function will not drop excess items.The exact behavior is:
- Try to stack inserted items with existing items in the main hand, then the offhand.
- Try to stack remaining inserted items with existing items in the player main inventory.
- Try to insert the remainder into empty slots of the player main inventory.
- Parameters:
variant- The variant to insert.maxAmount- How many of the variant to insert, at most.transaction- The transaction this operation is part of.- Returns:
- How many items could be inserted.
-
drop
void drop(ItemVariant variant, long amount, boolean throwRandomly, boolean retainOwnership, TransactionContext transaction) Throw items in the world from the player's location.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 drop.amount- How many of the variant to drop.throwRandomly- If true, the variant will be thrown in a random direction from the entity regardless of which direction the entity is facing.retainOwnership- If true, set theThrowerNBT data to the player's UUID.transaction- The transaction this operation is part of.- See Also:
-
drop
default void drop(ItemVariant variant, long amount, boolean retainOwnership, TransactionContext transaction) Throw items in the world from the player's location.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 drop.amount- How many of the variant to drop.retainOwnership- If true, set theThrowerNBT data to the player's UUID.transaction- The transaction this operation is part of.- See Also:
-
drop
Throw items in the world from the player's location.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 drop.amount- How many of the variant to drop.transaction- The transaction this operation is part of.- See Also:
-
getHandSlot
Return a wrapper around the current slot of the passed hand.
-