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

import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import java.util.Iterator;
import net.minecraft.world.level.block.Block;
import net.minecraft.core.Vec3i;
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.BlockBlobConfiguration;

public class BlockBlobFeature extends Feature<BlockBlobConfiguration> {
    public BlockBlobFeature(final Codec<BlockBlobConfiguration> codec) {
        super(codec);
    }
    
    @Override
    public boolean place(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, BlockPos fu, final BlockBlobConfiguration cne) {
        while (fu.getY() > 3) {
            if (!bqu.isEmptyBlock(fu.below())) {
                final Block bvr8 = bqu.getBlockState(fu.below()).getBlock();
                if (Feature.isDirt(bvr8)) {
                    break;
                }
                if (Feature.isStone(bvr8)) {
                    break;
                }
            }
            fu = fu.below();
        }
        if (fu.getY() <= 3) {
            return false;
        }
        for (int integer8 = cne.startRadius, integer9 = 0; integer8 >= 0 && integer9 < 3; ++integer9) {
            final int integer10 = integer8 + random.nextInt(2);
            final int integer11 = integer8 + random.nextInt(2);
            final int integer12 = integer8 + random.nextInt(2);
            final float float13 = (integer10 + integer11 + integer12) * 0.333f + 0.5f;
            for (final BlockPos fu2 : BlockPos.betweenClosed(fu.offset(-integer10, -integer11, -integer12), fu.offset(integer10, integer11, integer12))) {
                if (fu2.distSqr(fu) <= float13 * float13) {
                    bqu.setBlock(fu2, cne.state, 4);
                }
            }
            fu = fu.offset(-(integer8 + 1) + random.nextInt(2 + integer8 * 2), 0 - random.nextInt(2), -(integer8 + 1) + random.nextInt(2 + integer8 * 2));
        }
        return true;
    }
}
