/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.datafixers.kinds.App * com.mojang.datafixers.kinds.Applicative * com.mojang.serialization.Codec * com.mojang.serialization.DataResult * com.mojang.serialization.codecs.RecordCodecBuilder */ package net.minecraft.world.item.enchantment; import com.mojang.datafixers.kinds.App; import com.mojang.datafixers.kinds.Applicative; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import com.mojang.serialization.codecs.RecordCodecBuilder; import java.util.Optional; import net.minecraft.util.context.ContextKeySet; import net.minecraft.world.item.enchantment.ConditionalEffect; import net.minecraft.world.item.enchantment.EnchantmentTarget; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; public record TargetedConditionalEffect(EnchantmentTarget enchanted, EnchantmentTarget affected, T effect, Optional requirements) { public static Codec> codec(Codec effectCodec, ContextKeySet paramsSet) { return RecordCodecBuilder.create(i -> i.group((App)EnchantmentTarget.CODEC.fieldOf("enchanted").forGetter(TargetedConditionalEffect::enchanted), (App)EnchantmentTarget.CODEC.fieldOf("affected").forGetter(TargetedConditionalEffect::affected), (App)effectCodec.fieldOf("effect").forGetter(TargetedConditionalEffect::effect), (App)ConditionalEffect.conditionCodec(paramsSet).optionalFieldOf("requirements").forGetter(TargetedConditionalEffect::requirements)).apply((Applicative)i, TargetedConditionalEffect::new)); } public static Codec> equipmentDropsCodec(Codec effectCodec, ContextKeySet paramsSet) { return RecordCodecBuilder.create(i -> i.group((App)EnchantmentTarget.CODEC.validate(t -> t != EnchantmentTarget.DAMAGING_ENTITY ? DataResult.success((Object)t) : DataResult.error(() -> "enchanted must be attacker or victim")).fieldOf("enchanted").forGetter(TargetedConditionalEffect::enchanted), (App)effectCodec.fieldOf("effect").forGetter(TargetedConditionalEffect::effect), (App)ConditionalEffect.conditionCodec(paramsSet).optionalFieldOf("requirements").forGetter(TargetedConditionalEffect::requirements)).apply((Applicative)i, (target, effect, requirements) -> new TargetedConditionalEffect((EnchantmentTarget)target, EnchantmentTarget.VICTIM, effect, (Optional)requirements))); } public boolean matches(LootContext context) { if (this.requirements.isEmpty()) { return true; } return this.requirements.get().test(context); } }