package net.minecraft.world.level.block;

import net.minecraft.world.level.levelgen.feature.TwistingVinesFeature;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.levelgen.feature.NetherForestVegetationFeature;
import net.minecraft.world.level.biome.BiomeDefaultFeatures;
import net.minecraft.world.level.Level;
import java.util.Random;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.lighting.LayerLightEngine;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour;

public class NyliumBlock extends Block implements BonemealableBlock {
    protected NyliumBlock(final Properties c) {
        super(c);
    }
    
    private static boolean canBeNylium(final BlockState cfj, final LevelReader bqd, final BlockPos fu) {
        final BlockPos fu2 = fu.above();
        final BlockState cfj2 = bqd.getBlockState(fu2);
        final int integer6 = LayerLightEngine.getLightBlockInto(bqd, cfj, fu, cfj2, fu2, Direction.UP, cfj2.getLightBlock(bqd, fu2));
        return integer6 < bqd.getMaxLightLevel();
    }
    
    @Override
    public void randomTick(final BlockState cfj, final ServerLevel zd, final BlockPos fu, final Random random) {
        if (!canBeNylium(cfj, zd, fu)) {
            zd.setBlockAndUpdate(fu, Blocks.NETHERRACK.defaultBlockState());
        }
    }
    
    @Override
    public boolean isValidBonemealTarget(final BlockGetter bpg, final BlockPos fu, final BlockState cfj, final boolean boolean4) {
        return bpg.getBlockState(fu.above()).isAir();
    }
    
    @Override
    public boolean isBonemealSuccess(final Level bqb, final Random random, final BlockPos fu, final BlockState cfj) {
        return true;
    }
    
    @Override
    public void performBonemeal(final ServerLevel zd, final Random random, final BlockPos fu, final BlockState cfj) {
        final BlockState cfj2 = zd.getBlockState(fu);
        final BlockPos fu2 = fu.above();
        if (cfj2.is(Blocks.CRIMSON_NYLIUM)) {
            NetherForestVegetationFeature.place(zd, random, fu2, BiomeDefaultFeatures.CRIMSON_FOREST_CONFIG, 3, 1);
        }
        else if (cfj2.is(Blocks.WARPED_NYLIUM)) {
            NetherForestVegetationFeature.place(zd, random, fu2, BiomeDefaultFeatures.WARPED_FOREST_CONFIG, 3, 1);
            NetherForestVegetationFeature.place(zd, random, fu2, BiomeDefaultFeatures.NETHER_SPROUTS_CONFIG, 3, 1);
            if (random.nextInt(8) == 0) {
                TwistingVinesFeature.place(zd, random, fu2, 3, 1, 2);
            }
        }
    }
}
