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.state.properties.DoubleBlockHalf;
import net.minecraft.world.level.block.TallSeagrass;
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.SeagrassFeatureConfiguration;

public class SeagrassFeature extends Feature<SeagrassFeatureConfiguration> {
    public SeagrassFeature(final Codec<SeagrassFeatureConfiguration> codec) {
        super(codec);
    }
    
    @Override
    public boolean place(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, final BlockPos fu, final SeagrassFeatureConfiguration col) {
        int integer8 = 0;
        for (int integer9 = 0; integer9 < col.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);
            if (bqu.getBlockState(fu2).is(Blocks.WATER)) {
                final boolean boolean14 = random.nextDouble() < col.tallSeagrassProbability;
                final BlockState cfj15 = boolean14 ? Blocks.TALL_SEAGRASS.defaultBlockState() : Blocks.SEAGRASS.defaultBlockState();
                if (cfj15.canSurvive(bqu, fu2)) {
                    if (boolean14) {
                        final BlockState cfj16 = ((StateHolder<O, BlockState>)cfj15).<DoubleBlockHalf, DoubleBlockHalf>setValue(TallSeagrass.HALF, DoubleBlockHalf.UPPER);
                        final BlockPos fu3 = fu2.above();
                        if (bqu.getBlockState(fu3).is(Blocks.WATER)) {
                            bqu.setBlock(fu2, cfj15, 2);
                            bqu.setBlock(fu3, cfj16, 2);
                        }
                    }
                    else {
                        bqu.setBlock(fu2, cfj15, 2);
                    }
                    ++integer8;
                }
            }
        }
        return integer8 > 0;
    }
}
