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

import java.util.function.BiFunction;
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.world.level.block.state.BlockState;
import com.mojang.serialization.Codec;

public class RandomBlockStateMatchTest extends RuleTest {
    public static final Codec<RandomBlockStateMatchTest> CODEC;
    private final BlockState blockState;
    private final float probability;
    
    public RandomBlockStateMatchTest(final BlockState cfj, final float float2) {
        this.blockState = cfj;
        this.probability = float2;
    }
    
    @Override
    public boolean test(final BlockState cfj, final Random random) {
        return cfj == this.blockState && random.nextFloat() < this.probability;
    }
    
    @Override
    protected RuleTestType<?> getType() {
        return RuleTestType.RANDOM_BLOCKSTATE_TEST;
    }
    
    static {
        CODEC = RecordCodecBuilder.create(instance -> ((RecordCodecBuilder.Instance)instance).group((App)BlockState.CODEC.fieldOf("block_state").forGetter(cuw -> cuw.blockState), (App)Codec.FLOAT.fieldOf("probability").forGetter(cuw -> cuw.probability)).apply(instance, (BiFunction)RandomBlockStateMatchTest::new));
    }
}
