Class InventoryUtil

java.lang.Object
me.hackware.api.util.InventoryUtil

public class InventoryUtil extends Object
Inventory search and manipulation utilities.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Wears a chestplate; true when chest armour is worn already or the swap was sent.
    static boolean
    Wears a usable elytra; true when a glider is worn already or the swap was sent.
    static boolean
    Wears the hotbar's elytra with a use of it (equipByUse(int)) or else one SWAP click, for the chestplate keepers that put it on for every glide start (AutoPitch's Infinite Durability, ElytraBounce's InfiniteDura).
    find(Predicate<net.minecraft.world.item.ItemStack> predicate)
    Finds an item matching a predicate anywhere in the inventory.
    find(net.minecraft.world.item.Item item)
    Finds an item anywhere in the player's inventory (hotbar + main).
    findInHotbar(Predicate<net.minecraft.world.item.ItemStack> predicate)
    Finds an item matching a predicate only in the hotbar.
    findInHotbar(net.minecraft.world.item.Item item)
    Finds an item only in the hotbar (slots 0-8).
    findInHotbarWithOffhand(Predicate<net.minecraft.world.item.ItemStack> predicate)
    Finds an item matching a predicate, preferring the offhand, then the hotbar.
    findInHotbarWithOffhand(net.minecraft.world.item.Item item)
    Finds an item preferring the offhand, then the hotbar.
    The most durable elytra anywhere in the inventory that can still deploy (durability > 1).
    findWithOffhand(Predicate<net.minecraft.world.item.ItemStack> predicate)
    Finds an item matching a predicate, preferring the offhand, then the hotbar (held slot first), then the main inventory.
    findWithOffhand(net.minecraft.world.item.Item item)
    Finds an item preferring the offhand, then the hotbar (held slot first), then the main inventory.
    static int
    fireworkRefireTicks(net.minecraft.world.item.ItemStack stack)
    Ticks until another firework rocket of this flight duration can meaningfully re-fire.
    static void
    moveBackFromHotbar(int invSlot, int hotbarSlot)
    Reverses a previous moveToHotbar by swapping the hotbar slot back with the original inventory slot.
    static int
    moveToHotbar(int invSlot, int hotbarSlot)
    Silently moves an item from the main inventory (slot 9-35) into a hotbar slot using inventory container clicks.
    static boolean
    Silently equips a chestplate: from the hotbar with a use of it (equipByUse(int)) or a SWAP click, from the main inventory with slot clicks.
    static boolean
    Silently equips an elytra: from the hotbar with a use of it (equipByUse(int)) or a SWAP click, from the main inventory with slot clicks.
    static int
    Keeps a usable elytra in the hotbar for equipHotbarElytra(): with none there, the main inventory's most durable one is moved up with one SWAP click.
    static boolean
    swap(int slot)
    Swaps the given hotbar slot to the player's selected slot.
    static int
    toContainerSlot(int invSlot)
    Converts a player inventory slot index (0-35) to the corresponding container slot index in the player's inventory menu.
    static boolean
    True when the worn chest piece can glide.

    Methods inherited from class java.lang.Object

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

    • InventoryUtil

      public InventoryUtil()
  • Method Details

    • find

      public static InventoryUtil.FindItemResult find(net.minecraft.world.item.Item item)
      Finds an item anywhere in the player's inventory (hotbar + main).
    • find

      public static InventoryUtil.FindItemResult find(Predicate<net.minecraft.world.item.ItemStack> predicate)
      Finds an item matching a predicate anywhere in the inventory.
    • findInHotbar

      public static InventoryUtil.FindItemResult findInHotbar(net.minecraft.world.item.Item item)
      Finds an item only in the hotbar (slots 0-8).
    • findInHotbar

      public static InventoryUtil.FindItemResult findInHotbar(Predicate<net.minecraft.world.item.ItemStack> predicate)
      Finds an item matching a predicate only in the hotbar.
    • findInHotbarWithOffhand

      public static InventoryUtil.FindItemResult findInHotbarWithOffhand(net.minecraft.world.item.Item item)
      Finds an item preferring the offhand, then the hotbar.
    • findInHotbarWithOffhand

      public static InventoryUtil.FindItemResult findInHotbarWithOffhand(Predicate<net.minecraft.world.item.ItemStack> predicate)
      Finds an item matching a predicate, preferring the offhand, then the hotbar.
    • findWithOffhand

      public static InventoryUtil.FindItemResult findWithOffhand(net.minecraft.world.item.Item item)
      Finds an item preferring the offhand, then the hotbar (held slot first), then the main inventory.
    • findWithOffhand

      public static InventoryUtil.FindItemResult findWithOffhand(Predicate<net.minecraft.world.item.ItemStack> predicate)
      Finds an item matching a predicate, preferring the offhand, then the hotbar (held slot first), then the main inventory.
    • fireworkRefireTicks

      public static int fireworkRefireTicks(net.minecraft.world.item.ItemStack stack)
      Ticks until another firework rocket of this flight duration can meaningfully re-fire.
    • swap

      public static boolean swap(int slot)
      Swaps the given hotbar slot to the player's selected slot. Returns true if the swap was performed.
    • moveToHotbar

      public static int moveToHotbar(int invSlot, int hotbarSlot)
      Silently moves an item from the main inventory (slot 9-35) into a hotbar slot using inventory container clicks. Returns the hotbar slot it was moved to, or -1 on failure. The item at the target hotbar slot is swapped into the original inventory slot.
    • moveBackFromHotbar

      public static void moveBackFromHotbar(int invSlot, int hotbarSlot)
      Reverses a previous moveToHotbar by swapping the hotbar slot back with the original inventory slot.
    • wearingGlider

      public static boolean wearingGlider()
      True when the worn chest piece can glide.
    • equipElytra

      public static boolean equipElytra()
      Wears a usable elytra; true when a glider is worn already or the swap was sent.
    • equipChestplate

      public static boolean equipChestplate()
      Wears a chestplate; true when chest armour is worn already or the swap was sent.
    • silentSwapEquipChestplate

      public static boolean silentSwapEquipChestplate()
      Silently equips a chestplate: from the hotbar with a use of it (equipByUse(int)) or a SWAP click, from the main inventory with slot clicks. Returns false if already wearing a chestplate or none found.
    • silentSwapEquipElytra

      public static boolean silentSwapEquipElytra()
      Silently equips an elytra: from the hotbar with a use of it (equipByUse(int)) or a SWAP click, from the main inventory with slot clicks. Returns false if already wearing an elytra or none found.
    • findUsableElytra

      public static InventoryUtil.FindItemResult findUsableElytra()
      The most durable elytra anywhere in the inventory that can still deploy (durability > 1).
    • equipHotbarElytra

      public static boolean equipHotbarElytra()
      Wears the hotbar's elytra with a use of it (equipByUse(int)) or else one SWAP click, for the chestplate keepers that put it on for every glide start (AutoPitch's Infinite Durability, ElytraBounce's InfiniteDura). Unlike silentSwapEquipElytra() it never shuttles one from the main inventory through a borrowed slot, which left the chestplate down there and cost three clicks each way on every swap: with no usable elytra in the hotbar, stockHotbarElytra() moves the best one up first. A used-up elytra worn is swapped off like any other chest piece.
      Returns:
      true when a glider is worn already or the swap was sent
    • stockHotbarElytra

      public static int stockHotbarElytra()
      Keeps a usable elytra in the hotbar for equipHotbarElytra(): with none there, the main inventory's most durable one is moved up with one SWAP click. It takes the slot of a used-up elytra in the hotbar, which goes down in its place, else the slot SwapManager displaces most cheaply, sparing the held slot and the diamond or netherite chestplate the elytra is swapped with. Nothing moves through an open container or under another module's container swap.
      Returns:
      the hotbar slot holding the most durable usable elytra there, or -1 for none
    • toContainerSlot

      public static int toContainerSlot(int invSlot)
      Converts a player inventory slot index (0-35) to the corresponding container slot index in the player's inventory menu. Hotbar slots 0-8 → container slots 36-44 Main slots 9-35 → container slots 9-35