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

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

public class MegaPineTreeFeature extends MegaTreeFeature<MegaTreeConfiguration> {
    public MegaPineTreeFeature(final Function<Dynamic<?>, ? extends MegaTreeConfiguration> 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 MegaTreeConfiguration cgr) {
        final int integer9 = this.calcTreeHeigth(random, cgr);
        if (!this.prepareTree(bkb, fk, integer9)) {
            return false;
        }
        this.createCrown(bkb, random, fk.getX(), fk.getZ(), fk.getY() + integer9, 0, set5, clb, cgr);
        this.placeTrunk(bkb, random, fk, integer9, set4, clb, cgr);
        return true;
    }
    
    private void createCrown(final LevelSimulatedRW bkb, final Random random, final int integer3, final int integer4, final int integer5, final int integer6, final Set<BlockPos> set, final BoundingBox clb, final MegaTreeConfiguration cgr) {
        final int integer7 = random.nextInt(5) + cgr.crownHeight;
        int integer8 = 0;
        for (int integer9 = integer5 - integer7; integer9 <= integer5; ++integer9) {
            final int integer10 = integer5 - integer9;
            final int integer11 = integer6 + Mth.floor(integer10 / (float)integer7 * 3.5f);
            this.placeDoubleTrunkLeaves(bkb, random, new BlockPos(integer3, integer9, integer4), integer11 + ((integer10 > 0 && integer11 == integer8 && (integer9 & 0x1) == 0x0) ? 1 : 0), set, clb, cgr);
            integer8 = integer11;
        }
    }
}
