Package alexiil.mc.lib.attributes.item
Class ItemInvUtil
java.lang.Object
alexiil.mc.lib.attributes.item.ItemInvUtil
Various hooks and methods for dealing with pairs of
FixedItemInv
, FixedItemInvView
,
ItemInsertable
, ItemExtractable
, and GroupedItemInvView
instances.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A pair of ints, representing both the total number of stacks and the total number of items moved bymoveMultiple(ItemExtractable, ItemInsertable, ItemFilter, int, int)
. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
copyAll(FixedItemInvView inv, List<net.minecraft.item.ItemStack> dest)
Copies everyItemStack
held in the given inventory to the givenList
.static Consumer<net.minecraft.item.ItemStack>
createPlayerInsertable(net.minecraft.entity.player.PlayerEntity player)
Deprecated, for removal: This API element is subject to removal in a future version.static net.minecraft.item.ItemStack
extractSingle(FixedItemInv inv, int slot, ItemFilter filter, net.minecraft.item.ItemStack toAddWith, int maxAmount, Simulation simulation)
Deprecated, for removal: This API element is subject to removal in a future version.Because this has been moved toFixedItemInv.extractStack(int, ItemFilter, ItemStack, int, Simulation)
.static void
insertItemIntoPlayerInventory(net.minecraft.entity.player.PlayerEntity player, net.minecraft.item.ItemStack stack)
Deprecated, for removal: This API element is subject to removal in a future version.static net.minecraft.item.ItemStack
insertSingle(FixedItemInv inv, int slot, net.minecraft.item.ItemStack toInsert, Simulation simulation)
Deprecated, for removal: This API element is subject to removal in a future version.Because this has been moved toFixedItemInv.insertStack(int, ItemStack, Simulation)
.static int
move(ItemExtractable from, ItemInsertable to, int maximum)
Attempts to move up to the given maximum number of items from theItemExtractable
to theItemInsertable
.static int
move(ItemExtractable from, ItemInsertable to, ItemFilter filter, int maximum)
Attempts to move up to the given maximum number of items from theItemExtractable
to theItemInsertable
, provided they match the givenItemFilter
.static int
move(ItemExtractable from, ItemInsertable to, ItemFilter filter, int maximum, Simulation simulation)
Attempts to move up to the given maximum number of items from theItemExtractable
to theItemInsertable
, provided they match the givenItemFilter
.static ItemInvUtil.MultiMoveResult
moveMultiple(ItemExtractable from, ItemInsertable to)
Attempts to move as much as possible from theItemExtractable
to theItemInsertable
.static ItemInvUtil.MultiMoveResult
moveMultiple(ItemExtractable from, ItemInsertable to, int maxStacks, int maxTotal)
Attempts to move a given number of stacks from theItemExtractable
to theItemInsertable
.static ItemInvUtil.MultiMoveResult
moveMultiple(ItemExtractable from, ItemInsertable to, ItemFilter filter, int maxStacks, int maxTotal)
Attempts to move a given number of stacks from theItemExtractable
to theItemInsertable
.static Reference<net.minecraft.item.ItemStack>
referenceGuiCursor(net.minecraft.server.network.ServerPlayerEntity player)
Deprecated, for removal: This API element is subject to removal in a future version.static Reference<net.minecraft.item.ItemStack>
referenceHand(net.minecraft.entity.player.PlayerEntity player, net.minecraft.util.Hand hand)
Deprecated, for removal: This API element is subject to removal in a future version.UsePlayerInvUtil.referenceHand(PlayerEntity,Hand)
instead
-
Method Details
-
createPlayerInsertable
@Deprecated(since="0.6.4", forRemoval=true) public static Consumer<net.minecraft.item.ItemStack> createPlayerInsertable(net.minecraft.entity.player.PlayerEntity player)Deprecated, for removal: This API element is subject to removal in a future version.Returns aConsumer
that will callPlayerInvUtil.insertItemIntoPlayerInventory(PlayerEntity, ItemStack)
for everyItemStack
passed to it. -
referenceHand
@Deprecated(since="0.6.4", forRemoval=true) public static Reference<net.minecraft.item.ItemStack> referenceHand(net.minecraft.entity.player.PlayerEntity player, net.minecraft.util.Hand hand)Deprecated, for removal: This API element is subject to removal in a future version.UsePlayerInvUtil.referenceHand(PlayerEntity,Hand)
insteadCreates aReference
to the what the player is currently holding in the givenHand
. -
referenceGuiCursor
@Deprecated(since="0.6.4", forRemoval=true) public static Reference<net.minecraft.item.ItemStack> referenceGuiCursor(net.minecraft.server.network.ServerPlayerEntity player)Deprecated, for removal: This API element is subject to removal in a future version.Creates aReference
to the given player'scursor stack
, that updates the client whenever it is changed. -
insertItemIntoPlayerInventory
@Deprecated(since="0.6.4", forRemoval=true) public static void insertItemIntoPlayerInventory(net.minecraft.entity.player.PlayerEntity player, net.minecraft.item.ItemStack stack)Deprecated, for removal: This API element is subject to removal in a future version.Either inserts the given item into the player's inventory or drops it in front of them. Note that this will always keep a reference to the passed stack (and might modify it!) -
move
Attempts to move up to the given maximum number of items from theItemExtractable
to theItemInsertable
. Note that this only ever moves a single stack, unlikemoveMultiple(ItemExtractable, ItemInsertable, ItemFilter, int, int)
.- Returns:
- The number of items moved.
- See Also:
move(ItemExtractable, ItemInsertable, ItemFilter, int)
-
move
Attempts to move up to the given maximum number of items from theItemExtractable
to theItemInsertable
, provided they match the givenItemFilter
. Note that this only ever moves a single stack, unlikemoveMultiple(ItemExtractable, ItemInsertable, ItemFilter, int, int)
.- Returns:
- The number of items moved.
-
move
public static int move(ItemExtractable from, ItemInsertable to, ItemFilter filter, int maximum, Simulation simulation)Attempts to move up to the given maximum number of items from theItemExtractable
to theItemInsertable
, provided they match the givenItemFilter
. Note that this only ever moves a single stack, unlikemoveMultiple(ItemExtractable, ItemInsertable, ItemFilter, int, int)
.- Returns:
- The number of items moved.
-
moveMultiple
Attempts to move as much as possible from theItemExtractable
to theItemInsertable
. Internally this callsmoveMultiple(ItemExtractable, ItemInsertable, int, int)
withInteger.MAX_VALUE
as the maximum value for both arguments.- Returns:
- The
ItemInvUtil.MultiMoveResult
-
moveMultiple
public static ItemInvUtil.MultiMoveResult moveMultiple(ItemExtractable from, ItemInsertable to, int maxStacks, int maxTotal)Attempts to move a given number of stacks from theItemExtractable
to theItemInsertable
. Internally this callsmove(ItemExtractable, ItemInsertable, int)
in a loop from 1 to maxStacks.- Returns:
- The
ItemInvUtil.MultiMoveResult
-
moveMultiple
public static ItemInvUtil.MultiMoveResult moveMultiple(ItemExtractable from, ItemInsertable to, ItemFilter filter, int maxStacks, int maxTotal)Attempts to move a given number of stacks from theItemExtractable
to theItemInsertable
. Internally this callsmove(ItemExtractable, ItemInsertable, int)
in a loop from 1 to maxStacks.- Returns:
- The
ItemInvUtil.MultiMoveResult
-
copyAll
Copies everyItemStack
held in the given inventory to the givenList
. -
insertSingle
@Deprecated(since="0.8.0", forRemoval=true) public static net.minecraft.item.ItemStack insertSingle(FixedItemInv inv, int slot, net.minecraft.item.ItemStack toInsert, Simulation simulation)Deprecated, for removal: This API element is subject to removal in a future version.Because this has been moved toFixedItemInv.insertStack(int, ItemStack, Simulation)
.Inserts a single ItemStack into aFixedItemInv
, using onlyFixedItemInv.setInvStack(int, ItemStack, Simulation)
. As such this is useful for implementations ofItemInsertable
(or others) for the base implementation.- Parameters:
toInsert
- The stack to insert. This won't be modified.- Returns:
- The excess
ItemStack
that wasn't inserted.
-
extractSingle
@Deprecated(since="0.8.0", forRemoval=true) public static net.minecraft.item.ItemStack extractSingle(FixedItemInv inv, int slot, @Nullable ItemFilter filter, net.minecraft.item.ItemStack toAddWith, int maxAmount, Simulation simulation)Deprecated, for removal: This API element is subject to removal in a future version.Because this has been moved toFixedItemInv.extractStack(int, ItemFilter, ItemStack, int, Simulation)
.Extracts a single ItemStack from aFixedItemInv
, using onlyFixedItemInv.setInvStack(int, ItemStack, Simulation)
. As such this is useful for implementations ofItemInsertable
(or others) for the base implementation.- Parameters:
filter
- The filter to match on. If this is null then it will match anyItemStack
.toAddWith
- An optionalItemStack
that the extracted item will be added to.maxAmount
- The maximum number of items to extract. Note that the returnedItemStack
may have a higher amount than this if the givenItemStack
isn't empty.- Returns:
- The extracted ItemStack, plus the parameter "toAddWith".
-
PlayerInvUtil.createPlayerInsertable(PlayerEntity)
instead