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

import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.block.state.properties.BambooLeaves;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.BambooBlock;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.core.Direction;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Blocks;
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.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.configurations.ProbabilityFeatureConfiguration;

public class BambooFeature extends Feature<ProbabilityFeatureConfiguration> {
    private static final BlockState BAMBOO_TRUNK;
    private static final BlockState BAMBOO_FINAL_LARGE;
    private static final BlockState BAMBOO_TOP_LARGE;
    private static final BlockState BAMBOO_TOP_SMALL;
    
    public BambooFeature(final Codec<ProbabilityFeatureConfiguration> codec) {
        super(codec);
    }
    
    @Override
    public boolean place(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, final BlockPos fu, final ProbabilityFeatureConfiguration cod) {
        int integer8 = 0;
        final BlockPos.MutableBlockPos a9 = fu.mutable();
        final BlockPos.MutableBlockPos a10 = fu.mutable();
        if (bqu.isEmptyBlock(a9)) {
            if (Blocks.BAMBOO.defaultBlockState().canSurvive(bqu, a9)) {
                final int integer9 = random.nextInt(12) + 5;
                if (random.nextFloat() < cod.probability) {
                    for (int integer10 = random.nextInt(4) + 1, integer11 = fu.getX() - integer10; integer11 <= fu.getX() + integer10; ++integer11) {
                        for (int integer12 = fu.getZ() - integer10; integer12 <= fu.getZ() + integer10; ++integer12) {
                            final int integer13 = integer11 - fu.getX();
                            final int integer14 = integer12 - fu.getZ();
                            if (integer13 * integer13 + integer14 * integer14 <= integer10 * integer10) {
                                a10.set(integer11, bqu.getHeight(Heightmap.Types.WORLD_SURFACE, integer11, integer12) - 1, integer12);
                                if (Feature.isDirt(bqu.getBlockState(a10).getBlock())) {
                                    bqu.setBlock(a10, Blocks.PODZOL.defaultBlockState(), 2);
                                }
                            }
                        }
                    }
                }
                for (int integer10 = 0; integer10 < integer9 && bqu.isEmptyBlock(a9); ++integer10) {
                    bqu.setBlock(a9, BambooFeature.BAMBOO_TRUNK, 2);
                    a9.move(Direction.UP, 1);
                }
                if (a9.getY() - fu.getY() >= 3) {
                    bqu.setBlock(a9, BambooFeature.BAMBOO_FINAL_LARGE, 2);
                    bqu.setBlock(a9.move(Direction.DOWN, 1), BambooFeature.BAMBOO_TOP_LARGE, 2);
                    bqu.setBlock(a9.move(Direction.DOWN, 1), BambooFeature.BAMBOO_TOP_SMALL, 2);
                }
            }
            ++integer8;
        }
        return integer8 > 0;
    }
    
    static {
        BAMBOO_TRUNK = ((((StateHolder<O, BlockState>)Blocks.BAMBOO.defaultBlockState()).setValue((Property<Comparable>)BambooBlock.AGE, 1)).setValue(BambooBlock.LEAVES, BambooLeaves.NONE)).<Comparable, Integer>setValue((Property<Comparable>)BambooBlock.STAGE, 0);
        BAMBOO_FINAL_LARGE = (((StateHolder<O, BlockState>)BambooFeature.BAMBOO_TRUNK).setValue(BambooBlock.LEAVES, BambooLeaves.LARGE)).<Comparable, Integer>setValue((Property<Comparable>)BambooBlock.STAGE, 1);
        BAMBOO_TOP_LARGE = ((StateHolder<O, BlockState>)BambooFeature.BAMBOO_TRUNK).<BambooLeaves, BambooLeaves>setValue(BambooBlock.LEAVES, BambooLeaves.LARGE);
        BAMBOO_TOP_SMALL = ((StateHolder<O, BlockState>)BambooFeature.BAMBOO_TRUNK).<BambooLeaves, BambooLeaves>setValue(BambooBlock.LEAVES, BambooLeaves.SMALL);
    }
}
