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.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.tags.Tag;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.LevelAccessor;
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.BlockPileConfiguration;

public class NetherForestVegetationFeature extends Feature<BlockPileConfiguration> {
    public NetherForestVegetationFeature(final Codec<BlockPileConfiguration> codec) {
        super(codec);
    }
    
    @Override
    public boolean place(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, final BlockPos fu, final BlockPileConfiguration cnf) {
        return place(bqu, random, fu, cnf, 8, 4);
    }
    
    public static boolean place(final LevelAccessor bqc, final Random random, BlockPos fu, final BlockPileConfiguration cnf, final int integer5, final int integer6) {
        for (Block bvr7 = bqc.getBlockState(fu.below()).getBlock(); !bvr7.is(BlockTags.NYLIUM) && fu.getY() > 0; fu = fu.below(), bvr7 = bqc.getBlockState(fu).getBlock()) {}
        final int integer7 = fu.getY();
        if (integer7 < 1 || integer7 + 1 >= 256) {
            return false;
        }
        int integer8 = 0;
        for (int integer9 = 0; integer9 < integer5 * integer5; ++integer9) {
            final BlockPos fu2 = fu.offset(random.nextInt(integer5) - random.nextInt(integer5), random.nextInt(integer6) - random.nextInt(integer6), random.nextInt(integer5) - random.nextInt(integer5));
            final BlockState cfj12 = cnf.stateProvider.getState(random, fu2);
            if (bqc.isEmptyBlock(fu2) && fu2.getY() > 0 && cfj12.canSurvive(bqc, fu2)) {
                bqc.setBlock(fu2, cfj12, 2);
                ++integer8;
            }
        }
        return integer8 > 0;
    }
}
