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 java.util.stream.Stream;
import net.minecraft.core.BlockPos;
import java.util.Random;
import net.minecraft.world.level.levelgen.ChunkGeneratorSettings;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.LevelAccessor;
import com.mojang.datafixers.Dynamic;
import java.util.function.Function;

public class CarvingMaskDecorator extends FeatureDecorator<CarvingMaskDecoratorConfiguration> {
    public CarvingMaskDecorator(final Function<Dynamic<?>, ? extends CarvingMaskDecoratorConfiguration> function) {
        super(function);
    }
    
    @Override
    public Stream<BlockPos> getPositions(final LevelAccessor bjx, final ChunkGenerator<? extends ChunkGeneratorSettings> caa, final Random random, final CarvingMaskDecoratorConfiguration cjc, final BlockPos fk) {
        final ChunkAccess bzy7 = bjx.getChunk(fk);
        final ChunkPos bjh8 = bzy7.getPos();
        final BitSet bitSet9 = bzy7.getCarvingMask(cjc.step);
        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() < cjc.probability).<BlockPos>mapToObj(integer -> {
            integer2 = (integer & 0xF);
            integer3 = (integer >> 4 & 0xF);
            integer4 = integer >> 8;
            return new BlockPos(chunkPos.getMinBlockX() + integer2, integer4, chunkPos.getMinBlockZ() + integer3);
        });
    }
}
