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

import net.minecraft.util.Mth;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
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 MegaJungleTreeFeature extends MegaTreeFeature<MegaTreeConfiguration> {
    public MegaJungleTreeFeature(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.above(integer9), 2, set5, clb, cgr);
        for (int integer10 = fk.getY() + integer9 - 2 - random.nextInt(4); integer10 > fk.getY() + integer9 / 2; integer10 -= 2 + random.nextInt(4)) {
            final float float11 = random.nextFloat() * 6.2831855f;
            int integer11 = fk.getX() + (int)(0.5f + Mth.cos(float11) * 4.0f);
            int integer12 = fk.getZ() + (int)(0.5f + Mth.sin(float11) * 4.0f);
            for (int integer13 = 0; integer13 < 5; ++integer13) {
                integer11 = fk.getX() + (int)(1.5f + Mth.cos(float11) * integer13);
                integer12 = fk.getZ() + (int)(1.5f + Mth.sin(float11) * integer13);
                final BlockPos fk2 = new BlockPos(integer11, integer10 - 3 + integer13 / 2, integer12);
                this.placeLog(bkb, random, fk2, set4, clb, cgr);
            }
            int integer13 = 1 + random.nextInt(2);
            for (int integer14 = integer10, integer15 = integer14 - integer13; integer15 <= integer14; ++integer15) {
                final int integer16 = integer15 - integer14;
                this.placeSingleTrunkLeaves(bkb, random, new BlockPos(integer11, integer15, integer12), 1 - integer16, set5, clb, cgr);
            }
        }
        this.placeTrunk(bkb, random, fk, integer9, set4, clb, cgr);
        return true;
    }
    
    private void createCrown(final LevelSimulatedRW bkb, final Random random, final BlockPos fk, final int integer, final Set<BlockPos> set, final BoundingBox clb, final TreeConfiguration chl) {
        final int integer2 = 2;
        for (int integer3 = -2; integer3 <= 0; ++integer3) {
            this.placeDoubleTrunkLeaves(bkb, random, fk.above(integer3), integer + 1 - integer3, set, clb, chl);
        }
    }
}
