Class BattleItemScanner
java.lang.Object
com.pixelmonmod.pixelmon.api.battles.BattleItemScanner
Class for scanning and collecting battle items a player has available to use.
Methods are available for registering new inventory types to be scanned.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Class holding functional interface instances which handle the logic of an individual inventory type.static interface
static interface
static interface
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addItem
(BagSection section, net.minecraft.world.item.ItemStack stack, List<ItemData> items) Attempts to add anItemStack
to the list ofItemData
s, if it is valid for the givenBagSection
, and if it isn't appended to an existingItemData
via theattemptUpdate(ItemStack, List)
method.static void
Register a new inventory scanner to look for battle items in.static boolean
attemptUpdate
(net.minecraft.world.item.ItemStack stack, List<ItemData> items) Attempts to combineItemStack
s into oneItemData
entry if a matching entry is already present.static void
checkInventory
(net.minecraft.server.level.ServerPlayer player, BagSection section, List<net.minecraft.world.item.ItemStack> inventory, boolean checkSubInventories, List<ItemData> items) Iterates over a given list ofItemStack
s and checks for battle items of the givenBagSection
, populating the given list ofItemData
with any matches.static void
checkInventory
(net.minecraft.server.level.ServerPlayer player, BagSection section, List<net.minecraft.world.item.ItemStack> inventory, List<ItemData> items) Iterates over a given list ofItemStack
s and checks for battle items of the givenBagSection
, populating the given list ofItemData
with any matches.static void
checkInventory
(net.minecraft.server.level.ServerPlayer player, BagSection section, net.minecraft.world.Container inventory, List<ItemData> items) Iterates over a givenContainer
and checks for battle items of the givenBagSection
, populating the given list ofItemData
with any matches.static net.minecraft.world.item.ItemStack
consumeItem
(net.minecraft.world.item.ItemStack toMatch, net.minecraft.server.level.ServerPlayer player) Attempts to consume anItemStack
matching a givenItemStack
within a player's inventory, seeking through any sub-inventories within items known about.static net.minecraft.world.item.ItemStack
consumeItem
(net.minecraft.world.item.ItemStack toMatch, net.minecraft.server.level.ServerPlayer player, net.minecraft.world.Container inventory) Attempts to consume anItemStack
matching a givenItemStack
within a given inventory, seeking through any sub-inventories within items known about.static net.minecraft.world.item.ItemStack
findItemFromIterable
(net.minecraft.world.item.ItemStack toMatch, int size, IntFunction<net.minecraft.world.item.ItemStack> getter) Attempts to find anItemStack
matching a givenItemStack
for an iterable collection of items represented by anIntFunction
of index toItemStack
.static net.minecraft.world.item.ItemStack
findMatchingItem
(net.minecraft.world.item.ItemStack toMatch, net.minecraft.server.level.ServerPlayer player) Attempts to find anItemStack
matching a givenItemStack
within a player's inventory, seeking through any sub-inventories within items known about.static net.minecraft.world.item.ItemStack
findMatchingItem
(net.minecraft.world.item.ItemStack toMatch, net.minecraft.server.level.ServerPlayer player, net.minecraft.world.Container inventory) Attempts to find anItemStack
matching a givenItemStack
within a given inventory, seeking through any sub-inventories within items known about.scan
(net.minecraft.server.level.ServerPlayer player, BagSection section) Performs an inventory scan for battle items.
-
Method Details
-
addScanner
Register a new inventory scanner to look for battle items in. The predicate checks for whether the ItemStack is a valid inventory item, the first function is used to process the items within and add them to theItemData
list for delivery to the client, and the second function is used to find the item again once the client has chosen.- Parameters:
scanner
- The inventory scanner to register.
-
scan
public static List<ItemData> scan(net.minecraft.server.level.ServerPlayer player, BagSection section) Performs an inventory scan for battle items.- Parameters:
player
- The player to scan.section
- The type of item to scan for.- Returns:
- List of all valid items found.
-
checkInventory
public static void checkInventory(net.minecraft.server.level.ServerPlayer player, BagSection section, net.minecraft.world.Container inventory, List<ItemData> items) Iterates over a givenContainer
and checks for battle items of the givenBagSection
, populating the given list ofItemData
with any matches.- Parameters:
player
- The player to scan.section
- The type of item to scan for.inventory
- The inventory to scan.items
- Output for the items found during the scan.
-
checkInventory
public static void checkInventory(net.minecraft.server.level.ServerPlayer player, BagSection section, List<net.minecraft.world.item.ItemStack> inventory, List<ItemData> items) Iterates over a given list ofItemStack
s and checks for battle items of the givenBagSection
, populating the given list ofItemData
with any matches.- Parameters:
player
- The player to scan.section
- The type of item to scan for.inventory
- The items to scan.items
- Output for the items found during the scan.
-
checkInventory
public static void checkInventory(net.minecraft.server.level.ServerPlayer player, BagSection section, List<net.minecraft.world.item.ItemStack> inventory, boolean checkSubInventories, List<ItemData> items) Iterates over a given list ofItemStack
s and checks for battle items of the givenBagSection
, populating the given list ofItemData
with any matches.- Parameters:
player
- The player to scan.section
- The type of item to scan for.inventory
- The items to scan.checkSubInventories
- Whether to attempt to look inside sub-inventories or not.items
- Output for the items found during the scan.
-
addItem
public static void addItem(BagSection section, net.minecraft.world.item.ItemStack stack, List<ItemData> items) Attempts to add anItemStack
to the list ofItemData
s, if it is valid for the givenBagSection
, and if it isn't appended to an existingItemData
via theattemptUpdate(ItemStack, List)
method.- Parameters:
section
- The type of item being scanned for.stack
- The stack to test.items
- The items already found.
-
attemptUpdate
Attempts to combineItemStack
s into oneItemData
entry if a matching entry is already present.- Parameters:
stack
- The stack to check against already found items.items
- The items already found.- Returns:
- Whether this check updated an existing
ItemData
or not.
-
findMatchingItem
public static net.minecraft.world.item.ItemStack findMatchingItem(net.minecraft.world.item.ItemStack toMatch, net.minecraft.server.level.ServerPlayer player) Attempts to find anItemStack
matching a givenItemStack
within a player's inventory, seeking through any sub-inventories within items known about.- Parameters:
toMatch
- TheItemStack
to match other items against.player
- The player being searched.- Returns:
- The first found item, if any.
-
findMatchingItem
public static net.minecraft.world.item.ItemStack findMatchingItem(net.minecraft.world.item.ItemStack toMatch, net.minecraft.server.level.ServerPlayer player, net.minecraft.world.Container inventory) Attempts to find anItemStack
matching a givenItemStack
within a given inventory, seeking through any sub-inventories within items known about.- Parameters:
toMatch
- TheItemStack
to match other items against.player
- The player being searched.- Returns:
- The first found item, if any.
-
findItemFromIterable
public static net.minecraft.world.item.ItemStack findItemFromIterable(net.minecraft.world.item.ItemStack toMatch, int size, IntFunction<net.minecraft.world.item.ItemStack> getter) Attempts to find anItemStack
matching a givenItemStack
for an iterable collection of items represented by anIntFunction
of index toItemStack
.- Parameters:
toMatch
- TheItemStack
to match other items against.size
- The size of the given iterable collection.getter
- The function to map index toItemStack
s to compare to.- Returns:
- The first found item, if any.
-
consumeItem
public static net.minecraft.world.item.ItemStack consumeItem(net.minecraft.world.item.ItemStack toMatch, net.minecraft.server.level.ServerPlayer player) Attempts to consume anItemStack
matching a givenItemStack
within a player's inventory, seeking through any sub-inventories within items known about.- Parameters:
toMatch
- TheItemStack
to match other items against.player
- The player being searched.- Returns:
- The item consumed, if any.
-
consumeItem
public static net.minecraft.world.item.ItemStack consumeItem(net.minecraft.world.item.ItemStack toMatch, net.minecraft.server.level.ServerPlayer player, net.minecraft.world.Container inventory) Attempts to consume anItemStack
matching a givenItemStack
within a given inventory, seeking through any sub-inventories within items known about.- Parameters:
toMatch
- TheItemStack
to match other items against.player
- The player being searched.- Returns:
- The item consumed, if any.
-