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

import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.SeaPickleBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.core.BlockPos;
import java.util.Random;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.WorldGenLevel;
import com.mojang.serialization.Codec;
import net.minecraft.world.level.levelgen.feature.configurations.CountFeatureConfiguration;

public class SeaPickleFeature extends Feature<CountFeatureConfiguration> {
    public SeaPickleFeature(final Codec<CountFeatureConfiguration> codec) {
        super(codec);
    }
    
    @Override
    public boolean place(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, final BlockPos fu, final CountFeatureConfiguration cnk) {
        int integer8 = 0;
        for (int integer9 = 0; integer9 < cnk.count; ++integer9) {
            final int integer10 = random.nextInt(8) - random.nextInt(8);
            final int integer11 = random.nextInt(8) - random.nextInt(8);
            final int integer12 = bqu.getHeight(Heightmap.Types.OCEAN_FLOOR, fu.getX() + integer10, fu.getZ() + integer11);
            final BlockPos fu2 = new BlockPos(fu.getX() + integer10, integer12, fu.getZ() + integer11);
            final BlockState cfj14 = ((StateHolder<O, BlockState>)Blocks.SEA_PICKLE.defaultBlockState()).<Comparable, Integer>setValue((Property<Comparable>)SeaPickleBlock.PICKLES, random.nextInt(4) + 1);
            if (bqu.getBlockState(fu2).is(Blocks.WATER) && cfj14.canSurvive(bqu, fu2)) {
                bqu.setBlock(fu2, cfj14, 2);
                ++integer8;
            }
        }
        return integer8 > 0;
    }
}
