package net.minecraft.world.item.enchantment; import com.mojang.serialization.Codec; import java.util.List; import java.util.function.UnaryOperator; import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.core.component.DataComponentMap; import net.minecraft.core.component.DataComponentType; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.sounds.SoundEvent; import net.minecraft.util.Unit; import net.minecraft.world.item.CrossbowItem; import net.minecraft.world.item.enchantment.effects.DamageImmunity; import net.minecraft.world.item.enchantment.effects.EnchantmentAttributeEffect; import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect; import net.minecraft.world.item.enchantment.effects.EnchantmentLocationBasedEffect; import net.minecraft.world.item.enchantment.effects.EnchantmentValueEffect; import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; public interface EnchantmentEffectComponents { Codec> COMPONENT_CODEC = Codec.lazyInitialized(() -> BuiltInRegistries.ENCHANTMENT_EFFECT_COMPONENT_TYPE.byNameCodec()); Codec CODEC = DataComponentMap.makeCodec(COMPONENT_CODEC); DataComponentType>> DAMAGE_PROTECTION = register( "damage_protection", p_343083_ -> p_343083_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> DAMAGE_IMMUNITY = register( "damage_immunity", p_342369_ -> p_342369_.persistent(ConditionalEffect.codec(DamageImmunity.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> DAMAGE = register( "damage", p_343665_ -> p_343665_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> SMASH_DAMAGE_PER_FALLEN_BLOCK = register( "smash_damage_per_fallen_block", p_342204_ -> p_342204_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> KNOCKBACK = register( "knockback", p_342778_ -> p_342778_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> ARMOR_EFFECTIVENESS = register( "armor_effectiveness", p_342687_ -> p_342687_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> POST_ATTACK = register( "post_attack", p_344691_ -> p_344691_.persistent(TargetedConditionalEffect.codec(EnchantmentEntityEffect.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> HIT_BLOCK = register( "hit_block", p_343726_ -> p_343726_.persistent(ConditionalEffect.codec(EnchantmentEntityEffect.CODEC, LootContextParamSets.HIT_BLOCK).listOf()) ); DataComponentType>> ITEM_DAMAGE = register( "item_damage", p_344724_ -> p_344724_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ITEM).listOf()) ); DataComponentType> ATTRIBUTES = register( "attributes", p_342151_ -> p_342151_.persistent(EnchantmentAttributeEffect.CODEC.codec().listOf()) ); DataComponentType>> EQUIPMENT_DROPS = register( "equipment_drops", p_342441_ -> p_342441_.persistent(TargetedConditionalEffect.equipmentDropsCodec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> LOCATION_CHANGED = register( "location_changed", p_344782_ -> p_344782_.persistent(ConditionalEffect.codec(EnchantmentLocationBasedEffect.CODEC, LootContextParamSets.ENCHANTED_LOCATION).listOf()) ); DataComponentType>> TICK = register( "tick", p_345201_ -> p_345201_.persistent(ConditionalEffect.codec(EnchantmentEntityEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> AMMO_USE = register( "ammo_use", p_343745_ -> p_343745_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ITEM).listOf()) ); DataComponentType>> PROJECTILE_PIERCING = register( "projectile_piercing", p_344537_ -> p_344537_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ITEM).listOf()) ); DataComponentType>> PROJECTILE_SPAWNED = register( "projectile_spawned", p_345464_ -> p_345464_.persistent(ConditionalEffect.codec(EnchantmentEntityEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> PROJECTILE_SPREAD = register( "projectile_spread", p_342569_ -> p_342569_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> PROJECTILE_COUNT = register( "projectile_count", p_344670_ -> p_344670_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> TRIDENT_RETURN_ACCELERATION = register( "trident_return_acceleration", p_342620_ -> p_342620_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> FISHING_TIME_REDUCTION = register( "fishing_time_reduction", p_342994_ -> p_342994_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> FISHING_LUCK_BONUS = register( "fishing_luck_bonus", p_345348_ -> p_345348_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> BLOCK_EXPERIENCE = register( "block_experience", p_344214_ -> p_344214_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ITEM).listOf()) ); DataComponentType>> MOB_EXPERIENCE = register( "mob_experience", p_344594_ -> p_344594_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> REPAIR_WITH_XP = register( "repair_with_xp", p_344261_ -> p_344261_.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ITEM).listOf()) ); DataComponentType CROSSBOW_CHARGE_TIME = register("crossbow_charge_time", p_344938_ -> p_344938_.persistent(EnchantmentValueEffect.CODEC)); DataComponentType> CROSSBOW_CHARGING_SOUNDS = register( "crossbow_charging_sounds", p_344355_ -> p_344355_.persistent(CrossbowItem.ChargingSounds.CODEC.listOf()) ); DataComponentType>> TRIDENT_SOUND = register("trident_sound", p_345273_ -> p_345273_.persistent(SoundEvent.CODEC.listOf())); DataComponentType PREVENT_EQUIPMENT_DROP = register("prevent_equipment_drop", p_345068_ -> p_345068_.persistent(Unit.CODEC)); DataComponentType PREVENT_ARMOR_CHANGE = register("prevent_armor_change", p_344955_ -> p_344955_.persistent(Unit.CODEC)); DataComponentType TRIDENT_SPIN_ATTACK_STRENGTH = register( "trident_spin_attack_strength", p_343362_ -> p_343362_.persistent(EnchantmentValueEffect.CODEC) ); static DataComponentType bootstrap(Registry> p_342462_) { return DAMAGE_PROTECTION; } private static DataComponentType register(String p_342959_, UnaryOperator> p_345175_) { return Registry.register(BuiltInRegistries.ENCHANTMENT_EFFECT_COMPONENT_TYPE, p_342959_, p_345175_.apply(DataComponentType.builder()).build()); } }