/* * 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.ProblemReporter; import net.minecraft.util.context.ContextKeySet; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.ValidationContext; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; public record ConditionalEffect(T effect, Optional requirements) { public static Codec conditionCodec(ContextKeySet paramsSet) { return LootItemCondition.DIRECT_CODEC.validate(condition -> { ProblemReporter.Collector problemCollector = new ProblemReporter.Collector(); ValidationContext validationContext = new ValidationContext(problemCollector, paramsSet); condition.validate(validationContext); if (!problemCollector.isEmpty()) { return DataResult.error(() -> "Validation error in enchantment effect condition: " + problemCollector.getReport()); } return DataResult.success((Object)condition); }); } public static Codec> codec(Codec effectCodec, ContextKeySet paramsSet) { return RecordCodecBuilder.create(i -> i.group((App)effectCodec.fieldOf("effect").forGetter(ConditionalEffect::effect), (App)ConditionalEffect.conditionCodec(paramsSet).optionalFieldOf("requirements").forGetter(ConditionalEffect::requirements)).apply((Applicative)i, ConditionalEffect::new)); } public boolean matches(LootContext context) { if (this.requirements.isEmpty()) { return true; } return this.requirements.get().test(context); } }