Interface PlayerInventoryStorage
- All Superinterfaces:
InventoryStorage,Storage<ItemVariant>
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 Summary
Modifier and TypeMethodDescriptionvoiddrop(ItemVariant variant, long amount, TransactionContext transaction)Deprecated.Drop items in the world at the player's location.static SingleSlotStorage<ItemVariant>getCursorStorage(net.minecraft.screen.ScreenHandler screenHandler)Deprecated.Return a wrapper around the cursor slot of a screen handler, i.e.getHandSlot(net.minecraft.util.Hand hand)Deprecated.Return a wrapper around the current slot of the passed hand.static PlayerInventoryStorageof(net.minecraft.entity.player.PlayerEntity player)Deprecated.Return an instance for the passed player's inventory.static PlayerInventoryStorageof(net.minecraft.entity.player.PlayerInventory playerInventory)Deprecated.Return an instance for the passed player inventory.longoffer(ItemVariant variant, long maxAmount, TransactionContext transaction)Deprecated.Try to add items to the inventory if possible, stacking likePlayerInventory.offer(net.minecraft.item.ItemStack, boolean).default voidofferOrDrop(ItemVariant variant, long amount, TransactionContext transaction)Deprecated.Add items to the inventory if possible, and drop any leftover items in the world, similar toPlayerInventory.offerOrDrop(net.minecraft.item.ItemStack).Methods inherited from interface net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage
getSlot, getSlotsMethods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.Storage
exactView, extract, getVersion, insert, iterable, iterator, simulateExtract, simulateInsert, supportsExtraction, supportsInsertion
-
Method Details
-
of
Deprecated.Return an instance for the passed player's inventory. -
of
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 withScreenHandler.getCursorStack()andScreenHandler.setCursorStack(net.minecraft.item.ItemStack). -
offerOrDrop
Deprecated.Add items to the inventory if possible, and drop any leftover items in the world, similar toPlayerInventory.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.
-
offer
Deprecated.Try to add items to the inventory if possible, stacking likePlayerInventory.offer(net.minecraft.item.ItemStack, boolean). UnlikeofferOrDrop(net.fabricmc.fabric.api.transfer.v1.item.ItemVariant, long, net.fabricmc.fabric.api.transfer.v1.transaction.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
Deprecated.Drop items in the world at 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.
-
getHandSlot
Deprecated.Return a wrapper around the current slot of the passed hand.
-