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.world.level.material.Fluid;
import net.minecraft.tags.Tag;
import net.minecraft.tags.FluidTags;
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.DiskConfiguration;

public class DiskReplaceFeature extends Feature<DiskConfiguration> {
    public DiskReplaceFeature(final Codec<DiskConfiguration> codec) {
        super(codec);
    }
    
    @Override
    public boolean place(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, final BlockPos fu, final DiskConfiguration cnp) {
        if (!bqu.getFluidState(fu).is(FluidTags.WATER)) {
            return false;
        }
        int integer8 = 0;
        for (int integer9 = random.nextInt(cnp.radius - 2) + 2, integer10 = fu.getX() - integer9; integer10 <= fu.getX() + integer9; ++integer10) {
            for (int integer11 = fu.getZ() - integer9; integer11 <= fu.getZ() + integer9; ++integer11) {
                final int integer12 = integer10 - fu.getX();
                final int integer13 = integer11 - fu.getZ();
                if (integer12 * integer12 + integer13 * integer13 <= integer9 * integer9) {
                    for (int integer14 = fu.getY() - cnp.ySize; integer14 <= fu.getY() + cnp.ySize; ++integer14) {
                        final BlockPos fu2 = new BlockPos(integer10, integer14, integer11);
                        final BlockState cfj16 = bqu.getBlockState(fu2);
                        for (final BlockState cfj17 : cnp.targets) {
                            if (cfj17.is(cfj16.getBlock())) {
                                bqu.setBlock(fu2, cnp.state, 2);
                                ++integer8;
                                break;
                            }
                        }
                    }
                }
            }
        }
        return integer8 > 0;
    }
}
