Class BattleItemScanner

java.lang.Object
com.pixelmonmod.pixelmon.api.battles.BattleItemScanner

public class BattleItemScanner extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static 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 Type
    Method
    Description
    static void
    addItem(BagSection section, net.minecraft.world.item.ItemStack stack, List<ItemData> items)
    Attempts to add an ItemStack to the list of ItemDatas, if it is valid for the given BagSection, and if it isn't appended to an existing ItemData via the attemptUpdate(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 combine ItemStacks into one ItemData 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 of ItemStacks and checks for battle items of the given BagSection, populating the given list of ItemData 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 of ItemStacks and checks for battle items of the given BagSection, populating the given list of ItemData 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 given Container and checks for battle items of the given BagSection, populating the given list of ItemData 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 an ItemStack matching a given ItemStack 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 an ItemStack matching a given ItemStack 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 an ItemStack matching a given ItemStack for an iterable collection of items represented by an IntFunction of index to ItemStack.
    static net.minecraft.world.item.ItemStack
    findMatchingItem(net.minecraft.world.item.ItemStack toMatch, net.minecraft.server.level.ServerPlayer player)
    Attempts to find an ItemStack matching a given ItemStack 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 an ItemStack matching a given ItemStack within a given inventory, seeking through any sub-inventories within items known about.
    static List<ItemData>
    scan(net.minecraft.server.level.ServerPlayer player, BagSection section)
    Performs an inventory scan for battle items.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • addScanner

      public static void addScanner(BattleItemScanner.InventoryScanner scanner)
      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 the ItemData 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 given Container and checks for battle items of the given BagSection, populating the given list of ItemData 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 of ItemStacks and checks for battle items of the given BagSection, populating the given list of ItemData 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 of ItemStacks and checks for battle items of the given BagSection, populating the given list of ItemData 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 an ItemStack to the list of ItemDatas, if it is valid for the given BagSection, and if it isn't appended to an existing ItemData via the attemptUpdate(ItemStack, List) method.
      Parameters:
      section - The type of item being scanned for.
      stack - The stack to test.
      items - The items already found.
    • attemptUpdate

      public static boolean attemptUpdate(net.minecraft.world.item.ItemStack stack, List<ItemData> items)
      Attempts to combine ItemStacks into one ItemData 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 an ItemStack matching a given ItemStack within a player's inventory, seeking through any sub-inventories within items known about.
      Parameters:
      toMatch - The ItemStack 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 an ItemStack matching a given ItemStack within a given inventory, seeking through any sub-inventories within items known about.
      Parameters:
      toMatch - The ItemStack 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 an ItemStack matching a given ItemStack for an iterable collection of items represented by an IntFunction of index to ItemStack.
      Parameters:
      toMatch - The ItemStack to match other items against.
      size - The size of the given iterable collection.
      getter - The function to map index to ItemStacks 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 an ItemStack matching a given ItemStack within a player's inventory, seeking through any sub-inventories within items known about.
      Parameters:
      toMatch - The ItemStack 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 an ItemStack matching a given ItemStack within a given inventory, seeking through any sub-inventories within items known about.
      Parameters:
      toMatch - The ItemStack to match other items against.
      player - The player being searched.
      Returns:
      The item consumed, if any.