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

import net.minecraft.world.level.LevelSimulatedReader;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import java.util.Set;
import net.minecraft.core.BlockPos;
import java.util.Random;
import net.minecraft.world.level.LevelSimulatedRW;
import com.mojang.datafixers.Dynamic;
import java.util.function.Function;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;

public class GroundBushFeature extends AbstractTreeFeature<TreeConfiguration> {
    public GroundBushFeature(final Function<Dynamic<?>, ? extends TreeConfiguration> function) {
        super(function);
    }
    
    public boolean doPlace(final LevelSimulatedRW bkb, final Random random, BlockPos fk, final Set<BlockPos> set4, final Set<BlockPos> set5, final BoundingBox clb, final TreeConfiguration chl) {
        fk = bkb.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, fk).below();
        if (AbstractTreeFeature.isGrassOrDirt(bkb, fk)) {
            fk = fk.above();
            this.placeLog(bkb, random, fk, set4, clb, chl);
            for (int integer9 = 0; integer9 <= 2; ++integer9) {
                for (int integer10 = 2 - integer9, integer11 = -integer10; integer11 <= integer10; ++integer11) {
                    for (int integer12 = -integer10; integer12 <= integer10; ++integer12) {
                        if (Math.abs(integer11) != integer10 || Math.abs(integer12) != integer10 || random.nextInt(2) != 0) {
                            this.placeLeaf(bkb, random, new BlockPos(integer11 + fk.getX(), integer9 + fk.getY(), integer12 + fk.getZ()), set5, clb, chl);
                        }
                    }
                }
            }
        }
        return true;
    }
}
