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.world.World, net.minecraft.item.ItemStack)
.
Note that this is a wrapper around all the slots of the player inventory.
However, insert(net.fabricmc.fabric.api.transfer.v1.item.ItemVariant, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)
is overriden to behave like offer(net.fabricmc.fabric.api.transfer.v1.item.ItemVariant, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)
.
For simple insertions, offer(net.fabricmc.fabric.api.transfer.v1.item.ItemVariant, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)
or offerOrDrop(net.fabricmc.fabric.api.transfer.v1.item.ItemVariant, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)
is recommended.
InventoryStorage.getSlots()
can also be used and combined with CombinedStorage
to retrieve a wrapper around a specific range of slots.
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.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
drop(ItemVariant variant, long amount, TransactionContext transaction)
Drop items in the world at the player's location.static SingleSlotStorage<ItemVariant>
getCursorStorage(net.minecraft.entity.player.PlayerEntity player)
Return a wrapper around the cursor slot of a player, i.e.static SingleSlotStorage<ItemVariant>
getCursorStorage(net.minecraft.entity.player.PlayerInventory playerInventory)
Return a wrapper around the cursor slot of a player inventory, i.e.getHandSlot(net.minecraft.util.Hand hand)
Return a wrapper around the current slot of the passed hand.long
insert(ItemVariant resource, long maxAmount, TransactionContext transaction)
Insert items into this player inventory.static PlayerInventoryStorage
of(net.minecraft.entity.player.PlayerEntity player)
Return an instance for the passed player's inventory.static PlayerInventoryStorage
of(net.minecraft.entity.player.PlayerInventory playerInventory)
Return an instance for the passed player inventory.long
offer(ItemVariant variant, long maxAmount, TransactionContext transaction)
Try to add items to the inventory if possible, stacking likePlayerInventory#offer
.default void
offerOrDrop(ItemVariant variant, long amount, TransactionContext transaction)
Add items to the inventory if possible, and drop any leftover items in the world, similar toPlayerInventory.offerOrDrop(net.minecraft.world.World, net.minecraft.item.ItemStack)
.Methods inherited from interface net.fabricmc.fabric.api.transfer.v1.item.InventoryStorage
getSlot, getSlots
Methods inherited from interface net.fabricmc.fabric.api.transfer.v1.storage.Storage
exactView, extract, getVersion, iterable, iterator, simulateExtract, simulateInsert, 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.entity.player.PlayerEntity player)Return a wrapper around the cursor slot of a player, i.e. the stack that can be manipulated withPlayerInventory.getCursorStack()
andPlayerInventory.setCursorStack(net.minecraft.item.ItemStack)
. -
getCursorStorage
static SingleSlotStorage<ItemVariant> getCursorStorage(net.minecraft.entity.player.PlayerInventory playerInventory)Return a wrapper around the cursor slot of a player inventory, i.e. the stack that can be manipulated withPlayerInventory.getCursorStack()
andPlayerInventory.setCursorStack(net.minecraft.item.ItemStack)
. -
insert
Insert items into this player inventory. Behaves the same asoffer(net.fabricmc.fabric.api.transfer.v1.item.ItemVariant, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)
. More fine-tuned insertion, for example over a specific range of slots, is possible with the slot list.- Specified by:
insert
in 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 nonnegative integer not greater than maxAmount: the amount that was inserted.
- See Also:
offer(net.fabricmc.fabric.api.transfer.v1.item.ItemVariant, long, net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext)
-
offerOrDrop
Add items to the inventory if possible, and drop any leftover items in the world, similar toPlayerInventory.offerOrDrop(net.minecraft.world.World, 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
Try to add items to the inventory if possible, stacking likePlayerInventory#offer
. 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
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
Return a wrapper around the current slot of the passed hand.
-