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

import net.minecraft.world.level.block.state.AbstractStateHolder;
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.LevelAccessor;
import com.mojang.datafixers.Dynamic;
import java.util.function.Function;
import net.minecraft.world.level.levelgen.feature.configurations.CountFeatureConfiguration;

public class SeaPickleFeature extends Feature<CountFeatureConfiguration> {
    public SeaPickleFeature(final Function<Dynamic<?>, ? extends CountFeatureConfiguration> function) {
        super(function);
    }
    
    @Override
    public boolean place(final LevelAccessor bjx, final ChunkGenerator<?> caa, final Random random, final BlockPos fk, final CountFeatureConfiguration cgh) {
        int integer7 = 0;
        for (int integer8 = 0; integer8 < cgh.count; ++integer8) {
            final int integer9 = random.nextInt(8) - random.nextInt(8);
            final int integer10 = random.nextInt(8) - random.nextInt(8);
            final int integer11 = bjx.getHeight(Heightmap.Types.OCEAN_FLOOR, fk.getX() + integer9, fk.getZ() + integer10);
            final BlockPos fk2 = new BlockPos(fk.getX() + integer9, integer11, fk.getZ() + integer10);
            final BlockState byj13 = ((AbstractStateHolder<O, BlockState>)Blocks.SEA_PICKLE.defaultBlockState()).<Comparable, Integer>setValue((Property<Comparable>)SeaPickleBlock.PICKLES, random.nextInt(4) + 1);
            if (bjx.getBlockState(fk2).getBlock() == Blocks.WATER && byj13.canSurvive(bjx, fk2)) {
                bjx.setBlock(fk2, byj13, 2);
                ++integer7;
            }
        }
        return integer7 > 0;
    }
}
