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

import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.Blocks;
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.NoneFeatureConfiguration;

public class BlueIceFeature extends Feature<NoneFeatureConfiguration> {
    public BlueIceFeature(final Codec<NoneFeatureConfiguration> codec) {
        super(codec);
    }
    
    @Override
    public boolean place(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, final BlockPos fu, final NoneFeatureConfiguration coa) {
        if (fu.getY() > bqu.getSeaLevel() - 1) {
            return false;
        }
        if (!bqu.getBlockState(fu).is(Blocks.WATER) && !bqu.getBlockState(fu.below()).is(Blocks.WATER)) {
            return false;
        }
        boolean boolean8 = false;
        for (final Direction fz12 : Direction.values()) {
            if (fz12 != Direction.DOWN) {
                if (bqu.getBlockState(fu.relative(fz12)).is(Blocks.PACKED_ICE)) {
                    boolean8 = true;
                    break;
                }
            }
        }
        if (!boolean8) {
            return false;
        }
        bqu.setBlock(fu, Blocks.BLUE_ICE.defaultBlockState(), 2);
        for (int integer9 = 0; integer9 < 200; ++integer9) {
            final int integer10 = random.nextInt(5) - random.nextInt(6);
            int integer11 = 3;
            if (integer10 < 2) {
                integer11 += integer10 / 2;
            }
            if (integer11 >= 1) {
                final BlockPos fu2 = fu.offset(random.nextInt(integer11) - random.nextInt(integer11), integer10, random.nextInt(integer11) - random.nextInt(integer11));
                final BlockState cfj13 = bqu.getBlockState(fu2);
                if (cfj13.getMaterial() == Material.AIR || cfj13.is(Blocks.WATER) || cfj13.is(Blocks.PACKED_ICE) || cfj13.is(Blocks.ICE)) {
                    for (final Direction fz13 : Direction.values()) {
                        final BlockState cfj14 = bqu.getBlockState(fu2.relative(fz13));
                        if (cfj14.is(Blocks.BLUE_ICE)) {
                            bqu.setBlock(fu2, Blocks.BLUE_ICE.defaultBlockState(), 2);
                            break;
                        }
                    }
                }
            }
        }
        return true;
    }
}
