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

import java.util.function.Function;
import javax.annotation.Nullable;
import java.util.Random;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelReader;
import com.mojang.serialization.Codec;

public class BlockRotProcessor extends StructureProcessor {
    public static final Codec<BlockRotProcessor> CODEC;
    private final float integrity;
    
    public BlockRotProcessor(final float float1) {
        this.integrity = float1;
    }
    
    @Nullable
    @Override
    public StructureTemplate.StructureBlockInfo processBlock(final LevelReader bqd, final BlockPos fu2, final BlockPos fu3, final StructureTemplate.StructureBlockInfo c4, final StructureTemplate.StructureBlockInfo c5, final StructurePlaceSettings cvb) {
        final Random random8 = cvb.getRandom(c5.pos);
        if (this.integrity >= 1.0f || random8.nextFloat() <= this.integrity) {
            return c5;
        }
        return null;
    }
    
    @Override
    protected StructureProcessorType<?> getType() {
        return StructureProcessorType.BLOCK_ROT;
    }
    
    static {
        CODEC = Codec.FLOAT.fieldOf("integrity").withDefault(1.0f).xmap((Function)BlockRotProcessor::new, cuk -> cuk.integrity).codec();
    }
}
