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

import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
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 GlowstoneFeature extends Feature<NoneFeatureConfiguration> {
    public GlowstoneFeature(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 (!bjx.isEmptyBlock(fk)) {
            return false;
        }
        if (bjx.getBlockState(fk.above()).getBlock() != Blocks.NETHERRACK) {
            return false;
        }
        bjx.setBlock(fk, Blocks.GLOWSTONE.defaultBlockState(), 2);
        for (int integer7 = 0; integer7 < 1500; ++integer7) {
            final BlockPos fk2 = fk.offset(random.nextInt(8) - random.nextInt(8), -random.nextInt(12), random.nextInt(8) - random.nextInt(8));
            if (bjx.getBlockState(fk2).isAir()) {
                int integer8 = 0;
                for (final Direction fp13 : Direction.values()) {
                    if (bjx.getBlockState(fk2.relative(fp13)).getBlock() == Blocks.GLOWSTONE) {
                        ++integer8;
                    }
                    if (integer8 > 1) {
                        break;
                    }
                }
                if (integer8 == 1) {
                    bjx.setBlock(fk2, Blocks.GLOWSTONE.defaultBlockState(), 2);
                }
            }
        }
        return true;
    }
}
