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.block.state.properties.Property;
import net.minecraft.world.level.block.KelpBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Blocks;
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.NoneFeatureConfiguration;

public class KelpFeature extends Feature<NoneFeatureConfiguration> {
    public KelpFeature(final Codec<NoneFeatureConfiguration> codec) {
        super(codec);
    }
    
    @Override
    public boolean place(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, final BlockPos fu, final NoneFeatureConfiguration coa) {
        int integer8 = 0;
        final int integer9 = bqu.getHeight(Heightmap.Types.OCEAN_FLOOR, fu.getX(), fu.getZ());
        BlockPos fu2 = new BlockPos(fu.getX(), integer9, fu.getZ());
        if (bqu.getBlockState(fu2).is(Blocks.WATER)) {
            final BlockState cfj11 = Blocks.KELP.defaultBlockState();
            final BlockState cfj12 = Blocks.KELP_PLANT.defaultBlockState();
            for (int integer10 = 1 + random.nextInt(10), integer11 = 0; integer11 <= integer10; ++integer11) {
                if (bqu.getBlockState(fu2).is(Blocks.WATER) && bqu.getBlockState(fu2.above()).is(Blocks.WATER) && cfj12.canSurvive(bqu, fu2)) {
                    if (integer11 == integer10) {
                        bqu.setBlock(fu2, ((StateHolder<O, BlockState>)cfj11).<Comparable, Integer>setValue((Property<Comparable>)KelpBlock.AGE, random.nextInt(4) + 20), 2);
                        ++integer8;
                    }
                    else {
                        bqu.setBlock(fu2, cfj12, 2);
                    }
                }
                else if (integer11 > 0) {
                    final BlockPos fu3 = fu2.below();
                    if (cfj11.canSurvive(bqu, fu3) && !bqu.getBlockState(fu3.below()).is(Blocks.KELP)) {
                        bqu.setBlock(fu3, ((StateHolder<O, BlockState>)cfj11).<Comparable, Integer>setValue((Property<Comparable>)KelpBlock.AGE, random.nextInt(4) + 20), 2);
                        ++integer8;
                        break;
                    }
                    break;
                }
                fu2 = fu2.above();
            }
        }
        return integer8 > 0;
    }
}
