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.levelgen.ChunkGeneratorSettings;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.LevelAccessor;
import com.mojang.datafixers.Dynamic;
import java.util.function.Function;
import net.minecraft.world.level.levelgen.feature.configurations.BlockBlobConfiguration;

public class BlockBlobFeature extends Feature<BlockBlobConfiguration> {
    public BlockBlobFeature(final Function<Dynamic<?>, ? extends BlockBlobConfiguration> function) {
        super(function);
    }
    
    @Override
    public boolean place(final LevelAccessor bjx, final ChunkGenerator<? extends ChunkGeneratorSettings> caa, final Random random, BlockPos fk, final BlockBlobConfiguration cgc) {
        while (fk.getY() > 3) {
            if (!bjx.isEmptyBlock(fk.below())) {
                final Block bph7 = bjx.getBlockState(fk.below()).getBlock();
                if (Feature.isDirt(bph7)) {
                    break;
                }
                if (Feature.isStone(bph7)) {
                    break;
                }
            }
            fk = fk.below();
        }
        if (fk.getY() <= 3) {
            return false;
        }
        for (int integer7 = cgc.startRadius, integer8 = 0; integer7 >= 0 && integer8 < 3; ++integer8) {
            final int integer9 = integer7 + random.nextInt(2);
            final int integer10 = integer7 + random.nextInt(2);
            final int integer11 = integer7 + random.nextInt(2);
            final float float12 = (integer9 + integer10 + integer11) * 0.333f + 0.5f;
            for (final BlockPos fk2 : BlockPos.betweenClosed(fk.offset(-integer9, -integer10, -integer11), fk.offset(integer9, integer10, integer11))) {
                if (fk2.distSqr(fk) <= float12 * float12) {
                    bjx.setBlock(fk2, cgc.state, 4);
                }
            }
            fk = fk.offset(-(integer7 + 1) + random.nextInt(2 + integer7 * 2), 0 - random.nextInt(2), -(integer7 + 1) + random.nextInt(2 + integer7 * 2));
        }
        return true;
    }
}
