Package vazkii.botania.common.helper
Class DataComponentHelper
java.lang.Object
vazkii.botania.common.helper.DataComponentHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic net.minecraft.world.item.ItemStackduplicateAndClearMana(net.minecraft.world.item.ItemStack stack) static intgetFullness(ManaItem item) Returns the fullness of the mana item: 0 if empty, 1 if partially full, 2 if full.static booleanmatchTagAndManaFullness(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 voidsetFlag(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<net.minecraft.util.Unit> component, boolean value) Ensures aUnitcomponent is present on the ItemStack if the value is true, otherwise ensures that component is not present.static voidsetIntNonZero(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<?>>
voidsetNonEmpty(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 voidsetNonEmpty(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> voidsetOptional(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> voidsetUnlessDefault(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.
-
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 aUnitcomponent 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
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.
-