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.state.BlockState;
import net.minecraft.tags.FluidTags;
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.DiskConfiguration;

public class DiskReplaceFeature extends Feature<DiskConfiguration> {
    public DiskReplaceFeature(final Function<Dynamic<?>, ? extends DiskConfiguration> function) {
        super(function);
    }
    
    @Override
    public boolean place(final LevelAccessor bjx, final ChunkGenerator<? extends ChunkGeneratorSettings> caa, final Random random, final BlockPos fk, final DiskConfiguration cgl) {
        if (!bjx.getFluidState(fk).is(FluidTags.WATER)) {
            return false;
        }
        int integer7 = 0;
        for (int integer8 = random.nextInt(cgl.radius - 2) + 2, integer9 = fk.getX() - integer8; integer9 <= fk.getX() + integer8; ++integer9) {
            for (int integer10 = fk.getZ() - integer8; integer10 <= fk.getZ() + integer8; ++integer10) {
                final int integer11 = integer9 - fk.getX();
                final int integer12 = integer10 - fk.getZ();
                if (integer11 * integer11 + integer12 * integer12 <= integer8 * integer8) {
                    for (int integer13 = fk.getY() - cgl.ySize; integer13 <= fk.getY() + cgl.ySize; ++integer13) {
                        final BlockPos fk2 = new BlockPos(integer9, integer13, integer10);
                        final BlockState byj15 = bjx.getBlockState(fk2);
                        for (final BlockState byj16 : cgl.targets) {
                            if (byj16.getBlock() == byj15.getBlock()) {
                                bjx.setBlock(fk2, cgl.state, 2);
                                ++integer7;
                                break;
                            }
                        }
                    }
                }
            }
        }
        return integer7 > 0;
    }
}
