package net.minecraft.world.level.levelgen.placement;

import net.minecraft.world.level.levelgen.feature.configurations.DecoratorConfiguration;
import java.util.BitSet;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.ChunkAccess;
import java.util.stream.IntStream;
import net.minecraft.world.level.chunk.ProtoChunk;
import java.util.stream.Stream;
import net.minecraft.core.BlockPos;
import java.util.Random;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.LevelAccessor;
import com.mojang.serialization.Codec;

public class CarvingMaskDecorator extends FeatureDecorator<CarvingMaskDecoratorConfiguration> {
    public CarvingMaskDecorator(final Codec<CarvingMaskDecoratorConfiguration> codec) {
        super(codec);
    }
    
    @Override
    public Stream<BlockPos> getPositions(final LevelAccessor bqc, final ChunkGenerator cha, final Random random, final CarvingMaskDecoratorConfiguration cre, final BlockPos fu) {
        final ChunkAccess cgy7 = bqc.getChunk(fu);
        final ChunkPos bph8 = cgy7.getPos();
        final BitSet bitSet9 = ((ProtoChunk)cgy7).getCarvingMask(cre.step);
        if (bitSet9 == null) {
            return Stream.<BlockPos>empty();
        }
        final int integer2;
        final int integer3;
        final int integer4;
        final ChunkPos chunkPos;
        return IntStream.range(0, bitSet9.length()).filter(integer -> bitSet9.get(integer) && random.nextFloat() < cre.probability).<BlockPos>mapToObj(integer -> {
            integer2 = (integer & 0xF);
            integer3 = (integer >> 4 & 0xF);
            integer4 = integer >> 8;
            return new BlockPos(chunkPos.getMinBlockX() + integer2, integer4, chunkPos.getMinBlockZ() + integer3);
        });
    }
}
