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

import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.util.Mth;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.core.Vec3i;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.Level;
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.levelgen.feature.configurations.NoneFeatureConfiguration;

public class BasaltPillarFeature extends Feature<NoneFeatureConfiguration> {
    public BasaltPillarFeature(final Codec<NoneFeatureConfiguration> codec) {
        super(codec);
    }
    
    @Override
    public boolean place(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, final BlockPos fu, final NoneFeatureConfiguration coa) {
        if (!bqu.isEmptyBlock(fu) || bqu.isEmptyBlock(fu.above())) {
            return false;
        }
        final BlockPos.MutableBlockPos a8 = fu.mutable();
        final BlockPos.MutableBlockPos a9 = fu.mutable();
        boolean boolean10 = true;
        boolean boolean11 = true;
        boolean boolean12 = true;
        boolean boolean13 = true;
        while (bqu.isEmptyBlock(a8)) {
            if (Level.isOutsideBuildHeight(a8)) {
                return true;
            }
            bqu.setBlock(a8, Blocks.BASALT.defaultBlockState(), 2);
            boolean10 = (boolean10 && this.placeHangOff(bqu, random, a9.setWithOffset(a8, Direction.NORTH)));
            boolean11 = (boolean11 && this.placeHangOff(bqu, random, a9.setWithOffset(a8, Direction.SOUTH)));
            boolean12 = (boolean12 && this.placeHangOff(bqu, random, a9.setWithOffset(a8, Direction.WEST)));
            boolean13 = (boolean13 && this.placeHangOff(bqu, random, a9.setWithOffset(a8, Direction.EAST)));
            a8.move(Direction.DOWN);
        }
        a8.move(Direction.UP);
        this.placeBaseHangOff(bqu, random, a9.setWithOffset(a8, Direction.NORTH));
        this.placeBaseHangOff(bqu, random, a9.setWithOffset(a8, Direction.SOUTH));
        this.placeBaseHangOff(bqu, random, a9.setWithOffset(a8, Direction.WEST));
        this.placeBaseHangOff(bqu, random, a9.setWithOffset(a8, Direction.EAST));
        a8.move(Direction.DOWN);
        final BlockPos.MutableBlockPos a10 = new BlockPos.MutableBlockPos();
        for (int integer15 = -3; integer15 < 4; ++integer15) {
            for (int integer16 = -3; integer16 < 4; ++integer16) {
                final int integer17 = Mth.abs(integer15) * Mth.abs(integer16);
                if (random.nextInt(10) < 10 - integer17) {
                    a10.set(a8.offset(integer15, 0, integer16));
                    int integer18 = 3;
                    while (bqu.isEmptyBlock(a9.setWithOffset(a10, Direction.DOWN))) {
                        a10.move(Direction.DOWN);
                        if (--integer18 <= 0) {
                            break;
                        }
                    }
                    if (!bqu.isEmptyBlock(a9.setWithOffset(a10, Direction.DOWN))) {
                        bqu.setBlock(a10, Blocks.BASALT.defaultBlockState(), 2);
                    }
                }
            }
        }
        return true;
    }
    
    private void placeBaseHangOff(final LevelAccessor bqc, final Random random, final BlockPos fu) {
        if (random.nextBoolean()) {
            bqc.setBlock(fu, Blocks.BASALT.defaultBlockState(), 2);
        }
    }
    
    private boolean placeHangOff(final LevelAccessor bqc, final Random random, final BlockPos fu) {
        if (random.nextInt(10) != 0) {
            bqc.setBlock(fu, Blocks.BASALT.defaultBlockState(), 2);
            return true;
        }
        return false;
    }
}
