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

import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
import java.util.Optional;
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.SmallTreeConfiguration;

public class TreeFeature extends AbstractSmallTreeFeature<SmallTreeConfiguration> {
    public TreeFeature(final Function<Dynamic<?>, ? extends SmallTreeConfiguration> function) {
        super(function);
    }
    
    public boolean doPlace(final LevelSimulatedRW bkb, final Random random, final BlockPos fk, final Set<BlockPos> set4, final Set<BlockPos> set5, final BoundingBox clb, final SmallTreeConfiguration chi) {
        final int integer9 = chi.baseHeight + random.nextInt(chi.heightRandA + 1) + random.nextInt(chi.heightRandB + 1);
        final int integer10 = (chi.trunkHeight >= 0) ? (chi.trunkHeight + random.nextInt(chi.trunkHeightRandom + 1)) : (integer9 - (chi.foliageHeight + random.nextInt(chi.foliageHeightRandom + 1)));
        final int integer11 = chi.foliagePlacer.foliageRadius(random, integer10, integer9, chi);
        final Optional<BlockPos> optional12 = this.getProjectedOrigin(bkb, integer9, integer10, integer11, fk, chi);
        if (!optional12.isPresent()) {
            return false;
        }
        final BlockPos fk2 = optional12.get();
        this.setDirtAt(bkb, fk2.below());
        chi.foliagePlacer.createFoliage(bkb, random, chi, integer9, integer10, integer11, fk2, set5);
        this.placeTrunk(bkb, random, integer9, fk2, chi.trunkTopOffset + random.nextInt(chi.trunkTopOffsetRandom + 1), set4, clb, chi);
        return true;
    }
}
