Class EnchantmentHelpers

java.lang.Object
org.cyclops.cyclopscore.helper.EnchantmentHelpers

public class EnchantmentHelpers extends Object
This class contains helper methods to get and set certain enchants and enchantment levels on item stacks.
  • Nested Class Summary

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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    doesEnchantApply(net.minecraft.world.item.ItemStack itemStack, net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment)
    Checks if an itemStack has a certain enchantment.
    static net.minecraft.core.component.DataComponentType<net.minecraft.world.item.enchantment.ItemEnchantments>
    getComponentType(net.minecraft.world.item.ItemStack itemStack)
     
    static int
    getEnchantmentLevel(net.minecraft.world.item.ItemStack itemStack, net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment)
    Returns the level of an enchantment given an itemStack.
    static void
    runIterationOnItem(net.minecraft.world.item.ItemStack itemStack, EnchantmentHelpers.EnchantmentVisitor visitor)
     
    static void
    setEnchantmentLevel(net.minecraft.world.item.ItemStack itemStack, net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment, int level)
    Sets the level of an enchantment given an itemStack.

    Methods inherited from class java.lang.Object

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

    • EnchantmentHelpers

      public EnchantmentHelpers()
  • Method Details

    • doesEnchantApply

      public static boolean doesEnchantApply(net.minecraft.world.item.ItemStack itemStack, net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment)
      Checks if an itemStack has a certain enchantment.
      Parameters:
      itemStack - The itemStack to check.
      enchantment - The Enchantment to compare.
      Returns:
      If it applies.
    • getEnchantmentLevel

      public static int getEnchantmentLevel(net.minecraft.world.item.ItemStack itemStack, net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment)
      Returns the level of an enchantment given an itemStack.
      Parameters:
      itemStack - The itemStack which contains the enchanted item
      enchantment - The Enchantment to compare.
      Returns:
      The level of the enchantment on the given item
    • getComponentType

      public static net.minecraft.core.component.DataComponentType<net.minecraft.world.item.enchantment.ItemEnchantments> getComponentType(net.minecraft.world.item.ItemStack itemStack)
    • setEnchantmentLevel

      public static void setEnchantmentLevel(net.minecraft.world.item.ItemStack itemStack, net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> enchantment, int level)
      Sets the level of an enchantment given an itemStack. Will clear the enchantment if the new level <= 0
      Parameters:
      itemStack - The itemStack which contains the enchanted item
      enchantment - The Enchantment to compare.
      level - The new level of the enchantment on the given item
    • runIterationOnItem

      public static void runIterationOnItem(net.minecraft.world.item.ItemStack itemStack, EnchantmentHelpers.EnchantmentVisitor visitor)