Class HeldItemSwaps

java.lang.Object
net.ixdarklord.coolcatcore.api.client.item.HeldItemSwaps

public final class HeldItemSwaps extends Object
When the item in a player's hand is shown being put away and taken out again. Vanilla plays that swap whenever the held stack changes in any way but a few (durability, for one), so data a mod keeps on a held item (a mark, a charge, a page) makes the item dip out of view and back each time it changes. Here a mod says which changes are quiet: the stack shown simply becomes the new one, in place.

 HeldItemSwaps.quiet("mymod_charge");                            // changes to these NBT keys alone
 HeldItemSwaps.register((shown, next) -> shown.is(MyItems.WAND)    // or any test of the old and new stacks
         && next.is(MyItems.WAND));
 
Changes to a mod's attachments (net.ixdarklord.coolcatcore.api.attachment) are quiet already, unless the attachment was built with swapAnimation(). Client only; call it while the client sets up.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isQuiet(net.minecraft.world.item.ItemStack shown, net.minecraft.world.item.ItemStack next)
    Whether going from the stack shown to the one now held is quiet: the new one simply takes its place.
    static void
    quiet(String... keys)
    Changes to these keys of a stack's NBT alone don't play the swap.
    static void
    A test of the stack shown and the one now held: when it says they are the same item, no swap plays.
    static boolean
    sameIgnoring(net.minecraft.world.item.ItemStack shown, net.minecraft.world.item.ItemStack next, Predicate<String> ignored)
    The same item and count, and the same NBT but for the keys ignored.

    Methods inherited from class java.lang.Object

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

    • quiet

      public static void quiet(String... keys)
      Changes to these keys of a stack's NBT alone don't play the swap.
    • register

      public static void register(HeldItemSwaps.SwapFilter filter)
      A test of the stack shown and the one now held: when it says they are the same item, no swap plays.
    • isQuiet

      public static boolean isQuiet(net.minecraft.world.item.ItemStack shown, net.minecraft.world.item.ItemStack next)
      Whether going from the stack shown to the one now held is quiet: the new one simply takes its place.
    • sameIgnoring

      public static boolean sameIgnoring(net.minecraft.world.item.ItemStack shown, net.minecraft.world.item.ItemStack next, Predicate<String> ignored)
      The same item and count, and the same NBT but for the keys ignored.