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

import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.block.Block;
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.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.NoneFeatureConfiguration;

public class BlueIceFeature extends Feature<NoneFeatureConfiguration> {
    public BlueIceFeature(final Function<Dynamic<?>, ? extends NoneFeatureConfiguration> function) {
        super(function);
    }
    
    @Override
    public boolean place(final LevelAccessor bjx, final ChunkGenerator<? extends ChunkGeneratorSettings> caa, final Random random, final BlockPos fk, final NoneFeatureConfiguration cgv) {
        if (fk.getY() > bjx.getSeaLevel() - 1) {
            return false;
        }
        if (bjx.getBlockState(fk).getBlock() != Blocks.WATER && bjx.getBlockState(fk.below()).getBlock() != Blocks.WATER) {
            return false;
        }
        boolean boolean7 = false;
        for (final Direction fp11 : Direction.values()) {
            if (fp11 != Direction.DOWN) {
                if (bjx.getBlockState(fk.relative(fp11)).getBlock() == Blocks.PACKED_ICE) {
                    boolean7 = true;
                    break;
                }
            }
        }
        if (!boolean7) {
            return false;
        }
        bjx.setBlock(fk, Blocks.BLUE_ICE.defaultBlockState(), 2);
        for (int integer8 = 0; integer8 < 200; ++integer8) {
            final int integer9 = random.nextInt(5) - random.nextInt(6);
            int integer10 = 3;
            if (integer9 < 2) {
                integer10 += integer9 / 2;
            }
            if (integer10 >= 1) {
                final BlockPos fk2 = fk.offset(random.nextInt(integer10) - random.nextInt(integer10), integer9, random.nextInt(integer10) - random.nextInt(integer10));
                final BlockState byj12 = bjx.getBlockState(fk2);
                final Block bph13 = byj12.getBlock();
                if (byj12.getMaterial() == Material.AIR || bph13 == Blocks.WATER || bph13 == Blocks.PACKED_ICE || bph13 == Blocks.ICE) {
                    for (final Direction fp12 : Direction.values()) {
                        final Block bph14 = bjx.getBlockState(fk2.relative(fp12)).getBlock();
                        if (bph14 == Blocks.BLUE_ICE) {
                            bjx.setBlock(fk2, Blocks.BLUE_ICE.defaultBlockState(), 2);
                            break;
                        }
                    }
                }
            }
        }
        return true;
    }
}
