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

import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
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 net.minecraft.world.level.block.Blocks;
import com.mojang.serialization.Codec;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureRadiusConfiguration;

public class IcePatchFeature extends Feature<FeatureRadiusConfiguration> {
    private final Block block;
    
    public IcePatchFeature(final Codec<FeatureRadiusConfiguration> codec) {
        super(codec);
        this.block = Blocks.PACKED_ICE;
    }
    
    @Override
    public boolean place(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, BlockPos fu, final FeatureRadiusConfiguration cns) {
        while (bqu.isEmptyBlock(fu) && fu.getY() > 2) {
            fu = fu.below();
        }
        if (!bqu.getBlockState(fu).is(Blocks.SNOW_BLOCK)) {
            return false;
        }
        final int integer8 = random.nextInt(cns.radius) + 2;
        final int integer9 = 1;
        for (int integer10 = fu.getX() - integer8; integer10 <= fu.getX() + integer8; ++integer10) {
            for (int integer11 = fu.getZ() - integer8; integer11 <= fu.getZ() + integer8; ++integer11) {
                final int integer12 = integer10 - fu.getX();
                final int integer13 = integer11 - fu.getZ();
                if (integer12 * integer12 + integer13 * integer13 <= integer8 * integer8) {
                    for (int integer14 = fu.getY() - 1; integer14 <= fu.getY() + 1; ++integer14) {
                        final BlockPos fu2 = new BlockPos(integer10, integer14, integer11);
                        final Block bvr16 = bqu.getBlockState(fu2).getBlock();
                        if (Feature.isDirt(bvr16) || bvr16 == Blocks.SNOW_BLOCK || bvr16 == Blocks.ICE) {
                            bqu.setBlock(fu2, this.block.defaultBlockState(), 2);
                        }
                    }
                }
            }
        }
        return true;
    }
}
