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
Nested ClassesModifier and TypeClassDescriptionstatic classClass holding functional interface instances which handle the logic of an individual inventory type.static interfacestatic interfacestatic interface -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddItem(BagSection section, net.minecraft.world.item.ItemStack stack, List<ItemData> items) Attempts to add anItemStackto the list ofItemDatas, if it is valid for the givenBagSection, and if it isn't appended to an existingItemDatavia theattemptUpdate(ItemStack, List)method.static voidRegister a new inventory scanner to look for battle items in.static booleanattemptUpdate(net.minecraft.world.item.ItemStack stack, List<ItemData> items) Attempts to combineItemStacks into oneItemDataentry if a matching entry is already present.static voidcheckInventory(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 ofItemStacks and checks for battle items of the givenBagSection, populating the given list ofItemDatawith any matches.static voidcheckInventory(net.minecraft.server.level.ServerPlayer player, BagSection section, List<net.minecraft.world.item.ItemStack> inventory, List<ItemData> items) Iterates over a given list ofItemStacks and checks for battle items of the givenBagSection, populating the given list ofItemDatawith any matches.static voidcheckInventory(net.minecraft.server.level.ServerPlayer player, BagSection section, net.minecraft.world.Container inventory, List<ItemData> items) Iterates over a givenContainerand checks for battle items of the givenBagSection, populating the given list ofItemDatawith any matches.static net.minecraft.world.item.ItemStackconsumeItem(net.minecraft.world.item.ItemStack toMatch, net.minecraft.server.level.ServerPlayer player) Attempts to consume anItemStackmatching a givenItemStackwithin a player's inventory, seeking through any sub-inventories within items known about.static net.minecraft.world.item.ItemStackconsumeItem(net.minecraft.world.item.ItemStack toMatch, net.minecraft.server.level.ServerPlayer player, net.minecraft.world.Container inventory) Attempts to consume anItemStackmatching a givenItemStackwithin a given inventory, seeking through any sub-inventories within items known about.static net.minecraft.world.item.ItemStackfindItemFromIterable(net.minecraft.world.item.ItemStack toMatch, int size, IntFunction<net.minecraft.world.item.ItemStack> getter) Attempts to find anItemStackmatching a givenItemStackfor an iterable collection of items represented by anIntFunctionof index toItemStack.static net.minecraft.world.item.ItemStackfindMatchingItem(net.minecraft.world.item.ItemStack toMatch, net.minecraft.server.level.ServerPlayer player) Attempts to find anItemStackmatching a givenItemStackwithin a player's inventory, seeking through any sub-inventories within items known about.static net.minecraft.world.item.ItemStackfindMatchingItem(net.minecraft.world.item.ItemStack toMatch, net.minecraft.server.level.ServerPlayer player, net.minecraft.world.Container inventory) Attempts to find anItemStackmatching a givenItemStackwithin 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 theItemDatalist 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 givenContainerand checks for battle items of the givenBagSection, populating the given list ofItemDatawith 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 ofItemStacks and checks for battle items of the givenBagSection, populating the given list ofItemDatawith 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 ofItemStacks and checks for battle items of the givenBagSection, populating the given list ofItemDatawith 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 anItemStackto the list ofItemDatas, if it is valid for the givenBagSection, and if it isn't appended to an existingItemDatavia 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 combineItemStacks into oneItemDataentry 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
ItemDataor 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 anItemStackmatching a givenItemStackwithin a player's inventory, seeking through any sub-inventories within items known about.- Parameters:
toMatch- TheItemStackto 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 anItemStackmatching a givenItemStackwithin a given inventory, seeking through any sub-inventories within items known about.- Parameters:
toMatch- TheItemStackto 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 anItemStackmatching a givenItemStackfor an iterable collection of items represented by anIntFunctionof index toItemStack.- Parameters:
toMatch- TheItemStackto match other items against.size- The size of the given iterable collection.getter- The function to map index toItemStacks 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 anItemStackmatching a givenItemStackwithin a player's inventory, seeking through any sub-inventories within items known about.- Parameters:
toMatch- TheItemStackto 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 anItemStackmatching a givenItemStackwithin a given inventory, seeking through any sub-inventories within items known about.- Parameters:
toMatch- TheItemStackto match other items against.player- The player being searched.- Returns:
- The item consumed, if any.
-