Class LodestoneEnchantmentDataHelper

java.lang.Object
team.lodestar.lodestone.modules.toolkit.enchanting.LodestoneEnchantmentDataHelper

public class LodestoneEnchantmentDataHelper extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static List<net.minecraft.world.item.enchantment.LevelBasedValue>
    findLevelBasedValues(Object effectOrComponent)
    Finds all LevelBasedValue instances stored on an object through the use of reflection
    findSpecialComponent(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<T> componentType)
     
    findSpecialComponent(net.minecraft.world.item.ItemStack stack, net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> filter, net.minecraft.core.component.DataComponentType<T> componentType)
     
    static int
    getEnchantmentLevel(net.minecraft.world.level.Level level, net.minecraft.resources.ResourceKey<net.minecraft.world.item.enchantment.Enchantment> key, net.minecraft.world.item.ItemStack stack)
    Retrieves the level of a specific enchantment on the given ItemStack.
    protected static <T> List<T>
    getMatchingEffects(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentMap map, Class<T> type, com.mojang.datafixers.util.Either<Predicate<net.minecraft.core.component.TypedDataComponent<?>>,Predicate<T>> condition)
    Sieves through a data map and finds all components, including nested ones, stored inside that match the given condition.
    protected static <T> List<T>
    getMatchingEffects(net.minecraft.world.item.ItemStack effectHolder, net.minecraft.world.item.ItemStack comparisonBroker, net.minecraft.core.component.DataComponentMap map, Class<T> type, com.mojang.datafixers.util.Either<Predicate<net.minecraft.core.component.TypedDataComponent<?>>,Predicate<T>> condition)
    Sieves through a data map and finds all components, including nested ones, stored inside that match the given condition.
    protected static boolean
    innerMatches(net.minecraft.world.item.ItemStack item, net.minecraft.world.level.storage.loot.predicates.LootItemCondition condition)
    Checks if an enchantment's item condition matches the given item.
    static boolean
    matches(net.minecraft.world.item.ItemStack item, net.minecraft.world.level.storage.loot.predicates.LootItemCondition condition)
    Checks if the given LootItemCondition matches the given context.
    static void
    runIterationOnItem(net.minecraft.world.item.ItemStack stack, net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> filter, net.minecraft.world.item.enchantment.EnchantmentHelper.EnchantmentVisitor visitor)
    A modified version of EnchantmentHelper.runIterationOnItem(ItemStack, EquipmentSlot, LivingEntity, EnchantmentHelper.EnchantmentInSlotVisitor)
    static void
    runIterationOnItem(net.minecraft.world.item.ItemStack stack, net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> filter, net.minecraft.world.item.enchantment.EnchantmentHelper.EnchantmentVisitor visitor, BooleanSupplier breakCondition)
    A modified version of EnchantmentHelper.runIterationOnItem(ItemStack, EquipmentSlot, LivingEntity, EnchantmentHelper.EnchantmentInSlotVisitor)

    Methods inherited from class java.lang.Object

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

    • LodestoneEnchantmentDataHelper

      public LodestoneEnchantmentDataHelper()
  • Method Details

    • runIterationOnItem

      public static void runIterationOnItem(net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> filter, net.minecraft.world.item.enchantment.EnchantmentHelper.EnchantmentVisitor visitor)
      A modified version of EnchantmentHelper.runIterationOnItem(ItemStack, EquipmentSlot, LivingEntity, EnchantmentHelper.EnchantmentInSlotVisitor)
      Parameters:
      stack - The enchanted stack to run enchantment logic on
      filter - The enchantment to limit the search to
      visitor - The enchantment consumer to run
    • runIterationOnItem

      public static void runIterationOnItem(net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> filter, net.minecraft.world.item.enchantment.EnchantmentHelper.EnchantmentVisitor visitor, BooleanSupplier breakCondition)
      A modified version of EnchantmentHelper.runIterationOnItem(ItemStack, EquipmentSlot, LivingEntity, EnchantmentHelper.EnchantmentInSlotVisitor)
      Parameters:
      stack - The enchanted stack to run enchantment logic on
      filter - The enchantment to limit the search to
      visitor - The enchantment consumer to run
      breakCondition - A condition which determines if we should keep iterating
    • findSpecialComponent

      public static <T> LocatedEnchantmentEffect<T> findSpecialComponent(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<T> componentType)
    • findSpecialComponent

      public static <T> LocatedEnchantmentEffect<T> findSpecialComponent(net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.Holder<net.minecraft.world.item.enchantment.Enchantment> filter, net.minecraft.core.component.DataComponentType<T> componentType)
    • findLevelBasedValues

      public static List<net.minecraft.world.item.enchantment.LevelBasedValue> findLevelBasedValues(Object effectOrComponent)
      Finds all LevelBasedValue instances stored on an object through the use of reflection
      Parameters:
      effectOrComponent - The enchantment effect or component to sieve through
      Returns:
      All LevelBasedValue instances stored on an object in order of definition
    • getMatchingEffects

      protected static <T> List<T> getMatchingEffects(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentMap map, Class<T> type, com.mojang.datafixers.util.Either<Predicate<net.minecraft.core.component.TypedDataComponent<?>>,Predicate<T>> condition)
      Sieves through a data map and finds all components, including nested ones, stored inside that match the given condition. We're basically going through a whole tree map of AllOf effects, lists, and other conditional effects and returning a raw list of pure effects. Order should be deterministic.
      Parameters:
      stack - The item to search through for effects.
      map - The enchantment data map to check.
      type - The class type of effect we are looking for
      condition - A condition for either the TypedDataComponent or the component object itself
      Returns:
      All matching enchantment entity effects stored in the data map.
    • getMatchingEffects

      protected static <T> List<T> getMatchingEffects(net.minecraft.world.item.ItemStack effectHolder, net.minecraft.world.item.ItemStack comparisonBroker, net.minecraft.core.component.DataComponentMap map, Class<T> type, com.mojang.datafixers.util.Either<Predicate<net.minecraft.core.component.TypedDataComponent<?>>,Predicate<T>> condition)
      Sieves through a data map and finds all components, including nested ones, stored inside that match the given condition. We're basically going through a whole tree map of AllOf effects, lists, and other conditional effects and returning a raw list of pure effects. Order should be deterministic.
      Parameters:
      effectHolder - The item to search through for effects.
      comparisonBroker - The item to pass into any conditional effect checks.
      map - The enchantment data map to check.
      type - The class type of effect we are looking for
      condition - A condition for either the TypedDataComponent or the component object itself
      Returns:
      All matching enchantment entity effects stored in the data map.
    • matches

      public static boolean matches(net.minecraft.world.item.ItemStack item, net.minecraft.world.level.storage.loot.predicates.LootItemCondition condition)
      Checks if the given LootItemCondition matches the given context. Only considers MatchTool conditions
      Parameters:
      item - The item to check against.
      condition - The condition of the ConditionalEffect or TargetedConditionalEffect to check
      Returns:
      If the effect's condition was passed
    • innerMatches

      protected static boolean innerMatches(net.minecraft.world.item.ItemStack item, net.minecraft.world.level.storage.loot.predicates.LootItemCondition condition)
      Checks if an enchantment's item condition matches the given item. Only considers conditions that are directly related to the item itself, rather than damage type or target.
      Parameters:
      item - The item to check against.
      condition - The condition to check.
      Returns:
      If the item passed any MatchTool conditions present
    • getEnchantmentLevel

      public static int getEnchantmentLevel(net.minecraft.world.level.Level level, net.minecraft.resources.ResourceKey<net.minecraft.world.item.enchantment.Enchantment> key, net.minecraft.world.item.ItemStack stack)
      Retrieves the level of a specific enchantment on the given ItemStack.
      Parameters:
      level - The current level
      key - The ResourceKey of the Enchantment
      stack - The ItemStack to check
      Returns:
      The enchantment level as an int