package net.minecraft.world.level.levelgen.structure.templatesystem;

import com.mojang.datafixers.kinds.Applicative;
import com.mojang.datafixers.kinds.App;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import java.util.Random;
import net.minecraft.core.BlockPos;
import java.util.Optional;
import javax.annotation.Nullable;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.state.BlockState;
import com.mojang.serialization.Codec;

public class ProcessorRule {
    public static final Codec<ProcessorRule> CODEC;
    private final RuleTest inputPredicate;
    private final RuleTest locPredicate;
    private final PosRuleTest posPredicate;
    private final BlockState outputState;
    @Nullable
    private final CompoundTag outputTag;
    
    public ProcessorRule(final RuleTest cuy1, final RuleTest cuy2, final BlockState cfj) {
        this(cuy1, cuy2, PosAlwaysTrueTest.INSTANCE, cfj, Optional.<CompoundTag>empty());
    }
    
    public ProcessorRule(final RuleTest cuy1, final RuleTest cuy2, final PosRuleTest cus, final BlockState cfj) {
        this(cuy1, cuy2, cus, cfj, Optional.<CompoundTag>empty());
    }
    
    public ProcessorRule(final RuleTest cuy1, final RuleTest cuy2, final PosRuleTest cus, final BlockState cfj, final Optional<CompoundTag> optional) {
        this.inputPredicate = cuy1;
        this.locPredicate = cuy2;
        this.posPredicate = cus;
        this.outputState = cfj;
        this.outputTag = optional.orElse(null);
    }
    
    public boolean test(final BlockState cfj1, final BlockState cfj2, final BlockPos fu3, final BlockPos fu4, final BlockPos fu5, final Random random) {
        return this.inputPredicate.test(cfj1, random) && this.locPredicate.test(cfj2, random) && this.posPredicate.test(fu3, fu4, fu5, random);
    }
    
    public BlockState getOutputState() {
        return this.outputState;
    }
    
    @Nullable
    public CompoundTag getOutputTag() {
        return this.outputTag;
    }
    
    static {
        CODEC = RecordCodecBuilder.create(instance -> ((RecordCodecBuilder.Instance)instance).group((App)RuleTest.CODEC.fieldOf("input_predicate").forGetter(cuu -> cuu.inputPredicate), (App)RuleTest.CODEC.fieldOf("location_predicate").forGetter(cuu -> cuu.locPredicate), (App)PosRuleTest.CODEC.fieldOf("position_predicate").forGetter(cuu -> cuu.posPredicate), (App)BlockState.CODEC.fieldOf("output_state").forGetter(cuu -> cuu.outputState), (App)CompoundTag.CODEC.optionalFieldOf("output_nbt").forGetter(cuu -> Optional.<CompoundTag>ofNullable(cuu.outputTag))).apply(instance, ProcessorRule::new));
    }
}
