Package me.hackware.api.util
Class InventoryUtil
java.lang.Object
me.hackware.api.util.InventoryUtil
Inventory search and manipulation utilities.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanWears a chestplate; true when chest armour is worn already or the swap was sent.static booleanWears a usable elytra; true when a glider is worn already or the swap was sent.static booleanWears 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).static InventoryUtil.FindItemResultFinds an item matching a predicate anywhere in the inventory.static InventoryUtil.FindItemResultfind(net.minecraft.world.item.Item item) Finds an item anywhere in the player's inventory (hotbar + main).static InventoryUtil.FindItemResultfindInHotbar(Predicate<net.minecraft.world.item.ItemStack> predicate) Finds an item matching a predicate only in the hotbar.static InventoryUtil.FindItemResultfindInHotbar(net.minecraft.world.item.Item item) Finds an item only in the hotbar (slots 0-8).static InventoryUtil.FindItemResultfindInHotbarWithOffhand(Predicate<net.minecraft.world.item.ItemStack> predicate) Finds an item matching a predicate, preferring the offhand, then the hotbar.static InventoryUtil.FindItemResultfindInHotbarWithOffhand(net.minecraft.world.item.Item item) Finds an item preferring the offhand, then the hotbar.static InventoryUtil.FindItemResultThe most durable elytra anywhere in the inventory that can still deploy (durability > 1).static InventoryUtil.FindItemResultfindWithOffhand(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.static InventoryUtil.FindItemResultfindWithOffhand(net.minecraft.world.item.Item item) Finds an item preferring the offhand, then the hotbar (held slot first), then the main inventory.static intfireworkRefireTicks(net.minecraft.world.item.ItemStack stack) Ticks until another firework rocket of this flight duration can meaningfully re-fire.static voidmoveBackFromHotbar(int invSlot, int hotbarSlot) Reverses a previous moveToHotbar by swapping the hotbar slot back with the original inventory slot.static intmoveToHotbar(int invSlot, int hotbarSlot) Silently moves an item from the main inventory (slot 9-35) into a hotbar slot using inventory container clicks.static booleanSilently 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 booleanSilently 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 intKeeps a usable elytra in the hotbar forequipHotbarElytra(): with none there, the main inventory's most durable one is moved up with one SWAP click.static booleanswap(int slot) Swaps the given hotbar slot to the player's selected slot.static inttoContainerSlot(int invSlot) Converts a player inventory slot index (0-35) to the corresponding container slot index in the player's inventory menu.static booleanTrue when the worn chest piece can glide.
-
Constructor Details
-
InventoryUtil
public InventoryUtil()
-
-
Method Details
-
find
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
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
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
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). UnlikesilentSwapEquipElytra()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 forequipHotbarElytra(): 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 slotSwapManagerdisplaces 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
-