Package alexiil.mc.lib.attributes.item
Class ItemInvUtil
java.lang.Object
alexiil.mc.lib.attributes.item.ItemInvUtil
public final class ItemInvUtil
extends java.lang.Object
Various hooks and methods for dealing with pairs of
FixedItemInv
, FixedItemInvView
,
ItemInsertable
, ItemExtractable
, and GroupedItemInvView
instances.-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ItemInvUtil.MultiMoveResult
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 Type Method Description static void
copyAll(FixedItemInvView inv, java.util.List<net.minecraft.item.ItemStack> dest)
Copies everyItemStack
held in the given inventory to the givenList
.static java.util.function.Consumer<net.minecraft.item.ItemStack>
createPlayerInsertable(net.minecraft.entity.player.PlayerEntity player)
Deprecated.static net.minecraft.item.ItemStack
extractSingle(FixedItemInv inv, int slot, ItemFilter filter, net.minecraft.item.ItemStack toAddWith, int maxAmount, Simulation simulation)
Deprecated.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.static net.minecraft.item.ItemStack
insertSingle(FixedItemInv inv, int slot, net.minecraft.item.ItemStack toInsert, Simulation simulation)
Deprecated.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.static Reference<net.minecraft.item.ItemStack>
referenceHand(net.minecraft.entity.player.PlayerEntity player, net.minecraft.util.Hand hand)
Deprecated.UsePlayerInvUtil.referenceHand(PlayerEntity,Hand)
instead
-
Method Details
-
createPlayerInsertable
@Deprecated public static java.util.function.Consumer<net.minecraft.item.ItemStack> createPlayerInsertable(net.minecraft.entity.player.PlayerEntity player)Deprecated.Returns aConsumer
that will callPlayerInvUtil.insertItemIntoPlayerInventory(PlayerEntity, ItemStack)
for everyItemStack
passed to it. -
referenceHand
@Deprecated public static Reference<net.minecraft.item.ItemStack> referenceHand(net.minecraft.entity.player.PlayerEntity player, net.minecraft.util.Hand hand)Deprecated.UsePlayerInvUtil.referenceHand(PlayerEntity,Hand)
insteadCreates aReference
to the what the player is currently holding in the givenHand
. -
referenceGuiCursor
@Deprecated public static Reference<net.minecraft.item.ItemStack> referenceGuiCursor(net.minecraft.server.network.ServerPlayerEntity player)Deprecated.Creates aReference
to the given player'scursor stack
, that updates the client whenever it is changed. -
insertItemIntoPlayerInventory
@Deprecated public static void insertItemIntoPlayerInventory(net.minecraft.entity.player.PlayerEntity player, net.minecraft.item.ItemStack stack)Deprecated.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
public static void copyAll(FixedItemInvView inv, java.util.List<net.minecraft.item.ItemStack> dest)Copies everyItemStack
held in the given inventory to the givenList
. -
insertSingle
@Deprecated public static net.minecraft.item.ItemStack insertSingle(FixedItemInv inv, int slot, net.minecraft.item.ItemStack toInsert, Simulation simulation)Deprecated.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 public static net.minecraft.item.ItemStack extractSingle(FixedItemInv inv, int slot, @Nullable ItemFilter filter, net.minecraft.item.ItemStack toAddWith, int maxAmount, Simulation simulation)Deprecated.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".
-