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.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 GlowstoneFeature extends Feature<NoneFeatureConfiguration> {
    public GlowstoneFeature(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 (!bqu.isEmptyBlock(fu)) {
            return false;
        }
        final BlockState cfj8 = bqu.getBlockState(fu.above());
        if (!cfj8.is(Blocks.NETHERRACK) && !cfj8.is(Blocks.BASALT) && !cfj8.is(Blocks.BLACKSTONE)) {
            return false;
        }
        bqu.setBlock(fu, Blocks.GLOWSTONE.defaultBlockState(), 2);
        for (int integer9 = 0; integer9 < 1500; ++integer9) {
            final BlockPos fu2 = fu.offset(random.nextInt(8) - random.nextInt(8), -random.nextInt(12), random.nextInt(8) - random.nextInt(8));
            if (bqu.getBlockState(fu2).isAir()) {
                int integer10 = 0;
                for (final Direction fz15 : Direction.values()) {
                    if (bqu.getBlockState(fu2.relative(fz15)).is(Blocks.GLOWSTONE)) {
                        ++integer10;
                    }
                    if (integer10 > 1) {
                        break;
                    }
                }
                if (integer10 == 1) {
                    bqu.setBlock(fu2, Blocks.GLOWSTONE.defaultBlockState(), 2);
                }
            }
        }
        return true;
    }
}
