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.levelgen.ChunkGeneratorSettings;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Blocks;
import com.mojang.datafixers.Dynamic;
import java.util.function.Function;
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 Function<Dynamic<?>, ? extends FeatureRadiusConfiguration> function) {
        super(function);
        this.block = Blocks.PACKED_ICE;
    }
    
    @Override
    public boolean place(final LevelAccessor bjx, final ChunkGenerator<? extends ChunkGeneratorSettings> caa, final Random random, BlockPos fk, final FeatureRadiusConfiguration cgo) {
        while (bjx.isEmptyBlock(fk) && fk.getY() > 2) {
            fk = fk.below();
        }
        if (bjx.getBlockState(fk).getBlock() != Blocks.SNOW_BLOCK) {
            return false;
        }
        final int integer7 = random.nextInt(cgo.radius) + 2;
        final int integer8 = 1;
        for (int integer9 = fk.getX() - integer7; integer9 <= fk.getX() + integer7; ++integer9) {
            for (int integer10 = fk.getZ() - integer7; integer10 <= fk.getZ() + integer7; ++integer10) {
                final int integer11 = integer9 - fk.getX();
                final int integer12 = integer10 - fk.getZ();
                if (integer11 * integer11 + integer12 * integer12 <= integer7 * integer7) {
                    for (int integer13 = fk.getY() - 1; integer13 <= fk.getY() + 1; ++integer13) {
                        final BlockPos fk2 = new BlockPos(integer9, integer13, integer10);
                        final Block bph15 = bjx.getBlockState(fk2).getBlock();
                        if (Feature.isDirt(bph15) || bph15 == Blocks.SNOW_BLOCK || bph15 == Blocks.ICE) {
                            bjx.setBlock(fk2, this.block.defaultBlockState(), 2);
                        }
                    }
                }
            }
        }
        return true;
    }
}
