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 classItemInvUtil.MultiMoveResultA 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 voidcopyAll(FixedItemInvView inv, java.util.List<net.minecraft.item.ItemStack> dest)Copies everyItemStackheld 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.ItemStackextractSingle(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 voidinsertItemIntoPlayerInventory(net.minecraft.entity.player.PlayerEntity player, net.minecraft.item.ItemStack stack)Deprecated.static net.minecraft.item.ItemStackinsertSingle(FixedItemInv inv, int slot, net.minecraft.item.ItemStack toInsert, Simulation simulation)Deprecated.Because this has been moved toFixedItemInv.insertStack(int, ItemStack, Simulation).static intmove(ItemExtractable from, ItemInsertable to, int maximum)Attempts to move up to the given maximum number of items from theItemExtractableto theItemInsertable.static intmove(ItemExtractable from, ItemInsertable to, ItemFilter filter, int maximum)Attempts to move up to the given maximum number of items from theItemExtractableto theItemInsertable, provided they match the givenItemFilter.static intmove(ItemExtractable from, ItemInsertable to, ItemFilter filter, int maximum, Simulation simulation)Attempts to move up to the given maximum number of items from theItemExtractableto theItemInsertable, provided they match the givenItemFilter.static ItemInvUtil.MultiMoveResultmoveMultiple(ItemExtractable from, ItemInsertable to)Attempts to move as much as possible from theItemExtractableto theItemInsertable.static ItemInvUtil.MultiMoveResultmoveMultiple(ItemExtractable from, ItemInsertable to, int maxStacks, int maxTotal)Attempts to move a given number of stacks from theItemExtractableto theItemInsertable.static ItemInvUtil.MultiMoveResultmoveMultiple(ItemExtractable from, ItemInsertable to, ItemFilter filter, int maxStacks, int maxTotal)Attempts to move a given number of stacks from theItemExtractableto 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 aConsumerthat will callPlayerInvUtil.insertItemIntoPlayerInventory(PlayerEntity, ItemStack)for everyItemStackpassed 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 aReferenceto 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 aReferenceto 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 theItemExtractableto 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 theItemExtractableto 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 theItemExtractableto 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 theItemExtractableto theItemInsertable. Internally this callsmoveMultiple(ItemExtractable, ItemInsertable, int, int)withInteger.MAX_VALUEas 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 theItemExtractableto 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 theItemExtractableto 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 everyItemStackheld 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
ItemStackthat 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 optionalItemStackthat the extracted item will be added to.maxAmount- The maximum number of items to extract. Note that the returnedItemStackmay have a higher amount than this if the givenItemStackisn't empty.- Returns:
- The extracted ItemStack, plus the parameter "toAddWith".
-