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.component.DataComponentType.Builder; 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", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> DAMAGE_IMMUNITY = register( "damage_immunity", builder -> builder.persistent(ConditionalEffect.codec(DamageImmunity.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> DAMAGE = register( "damage", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> SMASH_DAMAGE_PER_FALLEN_BLOCK = register( "smash_damage_per_fallen_block", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> KNOCKBACK = register( "knockback", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> ARMOR_EFFECTIVENESS = register( "armor_effectiveness", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> POST_ATTACK = register( "post_attack", builder -> builder.persistent(TargetedConditionalEffect.codec(EnchantmentEntityEffect.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> HIT_BLOCK = register( "hit_block", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentEntityEffect.CODEC, LootContextParamSets.HIT_BLOCK).listOf()) ); DataComponentType>> ITEM_DAMAGE = register( "item_damage", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ITEM).listOf()) ); DataComponentType> ATTRIBUTES = register( "attributes", builder -> builder.persistent(EnchantmentAttributeEffect.CODEC.codec().listOf()) ); DataComponentType>> EQUIPMENT_DROPS = register( "equipment_drops", builder -> builder.persistent(TargetedConditionalEffect.equipmentDropsCodec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_DAMAGE).listOf()) ); DataComponentType>> LOCATION_CHANGED = register( "location_changed", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentLocationBasedEffect.CODEC, LootContextParamSets.ENCHANTED_LOCATION).listOf()) ); DataComponentType>> TICK = register( "tick", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentEntityEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> AMMO_USE = register( "ammo_use", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ITEM).listOf()) ); DataComponentType>> PROJECTILE_PIERCING = register( "projectile_piercing", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ITEM).listOf()) ); DataComponentType>> PROJECTILE_SPAWNED = register( "projectile_spawned", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentEntityEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> PROJECTILE_SPREAD = register( "projectile_spread", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> PROJECTILE_COUNT = register( "projectile_count", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> TRIDENT_RETURN_ACCELERATION = register( "trident_return_acceleration", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> FISHING_TIME_REDUCTION = register( "fishing_time_reduction", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> FISHING_LUCK_BONUS = register( "fishing_luck_bonus", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> BLOCK_EXPERIENCE = register( "block_experience", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ITEM).listOf()) ); DataComponentType>> MOB_EXPERIENCE = register( "mob_experience", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ENTITY).listOf()) ); DataComponentType>> REPAIR_WITH_XP = register( "repair_with_xp", builder -> builder.persistent(ConditionalEffect.codec(EnchantmentValueEffect.CODEC, LootContextParamSets.ENCHANTED_ITEM).listOf()) ); DataComponentType CROSSBOW_CHARGE_TIME = register("crossbow_charge_time", builder -> builder.persistent(EnchantmentValueEffect.CODEC)); DataComponentType> CROSSBOW_CHARGING_SOUNDS = register( "crossbow_charging_sounds", builder -> builder.persistent(CrossbowItem.ChargingSounds.CODEC.listOf()) ); DataComponentType>> TRIDENT_SOUND = register("trident_sound", builder -> builder.persistent(SoundEvent.CODEC.listOf())); DataComponentType PREVENT_EQUIPMENT_DROP = register("prevent_equipment_drop", builder -> builder.persistent(Unit.CODEC)); DataComponentType PREVENT_ARMOR_CHANGE = register("prevent_armor_change", builder -> builder.persistent(Unit.CODEC)); DataComponentType TRIDENT_SPIN_ATTACK_STRENGTH = register( "trident_spin_attack_strength", builder -> builder.persistent(EnchantmentValueEffect.CODEC) ); static DataComponentType bootstrap(Registry> registry) { return DAMAGE_PROTECTION; } private static DataComponentType register(String name, UnaryOperator> operator) { return Registry.register(BuiltInRegistries.ENCHANTMENT_EFFECT_COMPONENT_TYPE, name, ((Builder)operator.apply(DataComponentType.builder())).build()); } }