2025-11-24 22:52:51 +03:00

42 lines
2.7 KiB
Java

/*
* 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<T>(EnchantmentTarget enchanted, EnchantmentTarget affected, T effect, Optional<LootItemCondition> requirements) {
public static <S> Codec<TargetedConditionalEffect<S>> codec(Codec<S> 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 <S> Codec<TargetedConditionalEffect<S>> equipmentDropsCodec(Codec<S> 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<Object>((EnchantmentTarget)target, EnchantmentTarget.VICTIM, effect, (Optional<LootItemCondition>)requirements)));
}
public boolean matches(LootContext context) {
if (this.requirements.isEmpty()) {
return true;
}
return this.requirements.get().test(context);
}
}