Class DataComponentHelper

java.lang.Object
vazkii.botania.common.helper.DataComponentHelper

public final class DataComponentHelper extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static net.minecraft.world.item.ItemStack
    duplicateAndClearMana(net.minecraft.world.item.ItemStack stack)
     
    static int
    Returns the fullness of the mana item: 0 if empty, 1 if partially full, 2 if full.
    static boolean
    matchTagAndManaFullness(net.minecraft.world.item.ItemStack stack1, net.minecraft.world.item.ItemStack stack2)
    Checks if two items are the same and have the same NBT.
    static void
    setFlag(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<net.minecraft.util.Unit> component, boolean value)
    Ensures a Unit component is present on the ItemStack if the value is true, otherwise ensures that component is not present.
    static void
    setIntNonZero(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<Integer> component, int value)
    Sets an Integer component of the ItemStack to the specified value.
    static <C extends Collection<?>>
    void
    setNonEmpty(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<C> component, C collection)
    Sets a collection component of the ItemStack to the specified collection.
    static void
    setNonEmpty(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<net.minecraft.world.item.ItemStack> component, @Nullable net.minecraft.world.item.ItemStack value)
    Sets an ItemStack component of the stack to the specified value.
    static <T> void
    setOptional(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<? super T> component, T value)
    Sets a component of the ItemStack to a value.
    static <T> void
    setUnlessDefault(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<? super T> component, T value, T defaultValue)
    Sets a component of the ItemStack to a non-default value.

    Methods inherited from class java.lang.Object

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

    • DataComponentHelper

      public DataComponentHelper()
  • Method Details

    • setIntNonZero

      @Contract(mutates="param1") public static void setIntNonZero(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<Integer> component, int value)
      Sets an Integer component of the ItemStack to the specified value. If the value is zero, that component is removed instead.
    • setFlag

      @Contract(mutates="param1") public static void setFlag(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<net.minecraft.util.Unit> component, boolean value)
      Ensures a Unit component is present on the ItemStack if the value is true, otherwise ensures that component is not present.
    • setOptional

      @Contract(mutates="param1") public static <T> void setOptional(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<? super T> component, @Nullable T value)
      Sets a component of the ItemStack to a value. If that value is null, the component is removed instead.
    • setUnlessDefault

      @Contract(mutates="param1") public static <T> void setUnlessDefault(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<? super T> component, @Nullable T value, T defaultValue)
      Sets a component of the ItemStack to a non-default value. If the value is null or equal to the specified default value, the component is removed instead.
    • setNonEmpty

      @Contract(mutates="param1") public static <C extends Collection<?>> void setNonEmpty(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<C> component, @Nullable C collection)
      Sets a collection component of the ItemStack to the specified collection. If that collection is null or empty, the component is removed instead.
    • setNonEmpty

      @Contract(mutates="param1") public static void setNonEmpty(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<net.minecraft.world.item.ItemStack> component, @Nullable @Nullable net.minecraft.world.item.ItemStack value)
      Sets an ItemStack component of the stack to the specified value. If that value is null or an empty item stack, the component is removed instead.
    • getFullness

      public static int getFullness(ManaItem item)
      Returns the fullness of the mana item: 0 if empty, 1 if partially full, 2 if full.
    • duplicateAndClearMana

      public static net.minecraft.world.item.ItemStack duplicateAndClearMana(net.minecraft.world.item.ItemStack stack)
    • matchTagAndManaFullness

      public static boolean matchTagAndManaFullness(net.minecraft.world.item.ItemStack stack1, net.minecraft.world.item.ItemStack stack2)
      Checks if two items are the same and have the same NBT. If they are `IManaItems`, their mana property is matched on whether they are empty, partially full, or full.