Class LodestoneEnchantmentDataHelper
java.lang.Object
team.lodestar.lodestone.modules.toolkit.enchanting.LodestoneEnchantmentDataHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<net.minecraft.world.item.enchantment.LevelBasedValue> findLevelBasedValues(Object effectOrComponent) Finds allLevelBasedValueinstances stored on an object through the use of reflectionstatic <T> LocatedEnchantmentEffect<T> findSpecialComponent(net.minecraft.world.item.ItemStack stack, net.minecraft.core.component.DataComponentType<T> componentType) static <T> LocatedEnchantmentEffect<T> 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 intgetEnchantmentLevel(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 booleaninnerMatches(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 booleanmatches(net.minecraft.world.item.ItemStack item, net.minecraft.world.level.storage.loot.predicates.LootItemCondition condition) Checks if the givenLootItemConditionmatches the given context.static voidrunIterationOnItem(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 ofEnchantmentHelper.runIterationOnItem(ItemStack, EquipmentSlot, LivingEntity, EnchantmentHelper.EnchantmentInSlotVisitor)static voidrunIterationOnItem(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 ofEnchantmentHelper.runIterationOnItem(ItemStack, EquipmentSlot, LivingEntity, EnchantmentHelper.EnchantmentInSlotVisitor)
-
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 ofEnchantmentHelper.runIterationOnItem(ItemStack, EquipmentSlot, LivingEntity, EnchantmentHelper.EnchantmentInSlotVisitor)- Parameters:
stack- The enchanted stack to run enchantment logic onfilter- The enchantment to limit the search tovisitor- 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 ofEnchantmentHelper.runIterationOnItem(ItemStack, EquipmentSlot, LivingEntity, EnchantmentHelper.EnchantmentInSlotVisitor)- Parameters:
stack- The enchanted stack to run enchantment logic onfilter- The enchantment to limit the search tovisitor- The enchantment consumer to runbreakCondition- 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 allLevelBasedValueinstances stored on an object through the use of reflection- Parameters:
effectOrComponent- The enchantment effect or component to sieve through- Returns:
- All
LevelBasedValueinstances 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 ofAllOfeffects, 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 forcondition- A condition for either theTypedDataComponentor 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 ofAllOfeffects, 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 forcondition- A condition for either theTypedDataComponentor 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 givenLootItemConditionmatches the given context. Only considersMatchToolconditions- Parameters:
item- The item to check against.condition- The condition of theConditionalEffectorTargetedConditionalEffectto 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 levelkey- The ResourceKey of the Enchantmentstack- The ItemStack to check- Returns:
- The enchantment level as an int
-