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

import java.util.function.BiFunction;
import com.mojang.datafixers.kinds.Applicative;
import net.minecraft.core.Registry;
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 net.minecraft.world.level.block.Block;
import com.mojang.serialization.Codec;

public class RandomBlockMatchTest extends RuleTest {
    public static final Codec<RandomBlockMatchTest> CODEC;
    private final Block block;
    private final float probability;
    
    public RandomBlockMatchTest(final Block bvr, final float float2) {
        this.block = bvr;
        this.probability = float2;
    }
    
    @Override
    public boolean test(final BlockState cfj, final Random random) {
        return cfj.is(this.block) && random.nextFloat() < this.probability;
    }
    
    @Override
    protected RuleTestType<?> getType() {
        return RuleTestType.RANDOM_BLOCK_TEST;
    }
    
    static {
        CODEC = RecordCodecBuilder.create(instance -> ((RecordCodecBuilder.Instance)instance).group((App)Registry.BLOCK.fieldOf("block").forGetter(cuv -> cuv.block), (App)Codec.FLOAT.fieldOf("probability").forGetter(cuv -> cuv.probability)).apply(instance, (BiFunction)RandomBlockMatchTest::new));
    }
}
