package net.geforcemods.securitycraft.blocks.reinforced;

import java.util.Random;

import net.geforcemods.securitycraft.SCContent;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.data.worldgen.Features;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.BonemealableBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.NetherForestVegetationFeature;
import net.minecraft.world.level.levelgen.feature.TwistingVinesFeature;
import net.minecraft.world.level.lighting.LayerLightEngine;

public class ReinforcedNyliumBlock extends BaseReinforcedBlock implements BonemealableBlock {
	public ReinforcedNyliumBlock(Block.Properties properties, Block vB) {
		super(properties, vB);
	}

	@Override
	public void randomTick(BlockState state, ServerLevel level, BlockPos pos, Random random) {
		if (!hasLightAbove(state, level, pos))
			level.setBlockAndUpdate(pos, Blocks.NETHERRACK.defaultBlockState());
	}

	private static boolean hasLightAbove(BlockState state, LevelReader level, BlockPos pos) {
		BlockPos upperPos = pos.above();
		BlockState upperState = level.getBlockState(upperPos);
		int lightLevel = LayerLightEngine.getLightBlockInto(level, state, pos, upperState, upperPos, Direction.UP, upperState.getLightBlock(level, upperPos));
		return lightLevel < level.getMaxLightLevel();
	}

	@Override
	public boolean isValidBonemealTarget(BlockGetter level, BlockPos pos, BlockState state, boolean flag) {
		return level.getBlockState(pos.above()).isAir();
	}

	@Override
	public boolean isBonemealSuccess(Level level, Random random, BlockPos pos, BlockState state) {
		return true;
	}

	@Override
	public void performBonemeal(ServerLevel level, Random random, BlockPos pos, BlockState blockState) {
		BlockState state = level.getBlockState(pos);
		BlockPos upperPos = pos.above();

		if (state.is(SCContent.REINFORCED_CRIMSON_NYLIUM.get()))
			NetherForestVegetationFeature.place(level, random, upperPos, Features.Configs.CRIMSON_FOREST_CONFIG, 3, 1);
		else if (state.is(SCContent.REINFORCED_WARPED_NYLIUM.get())) {
			NetherForestVegetationFeature.place(level, random, upperPos, Features.Configs.WARPED_FOREST_CONFIG, 3, 1);
			NetherForestVegetationFeature.place(level, random, upperPos, Features.Configs.NETHER_SPROUTS_CONFIG, 3, 1);

			if (random.nextInt(8) == 0)
				TwistingVinesFeature.place(level, random, upperPos, 3, 1, 2);
		}
	}
}

@@ -171,46 +171,8 @@
 s;%0D%0A
-import net.minecraft.core.Direction;%0D%0A
 impo
@@ -386,114 +386,19 @@
 vel.
-LevelReader;%0D%0Aimport net.minecraft.world.level.block.Block;%0D%0Aimport net.minecraft.world.level.block.Blocks
+block.Block
 ;%0D%0Ai
@@ -671,69 +671,8 @@
 re;%0D
-%0Aimport net.minecraft.world.level.lighting.LayerLightEngine;%0D
 %0A%0D%0Ap
@@ -873,629 +873,8 @@
 %0D%0A%0D%0A
-%09@Override%0D%0A%09public void randomTick(BlockState state, ServerLevel level, BlockPos pos, Random random) %7B%0D%0A%09%09if (!hasLightAbove(state, level, pos))%0D%0A%09%09%09level.setBlockAndUpdate(pos, Blocks.NETHERRACK.defaultBlockState());%0D%0A%09%7D%0D%0A%0D%0A%09private static boolean hasLightAbove(BlockState state, LevelReader level, BlockPos pos) %7B%0D%0A%09%09BlockPos upperPos = pos.above();%0D%0A%09%09BlockState upperState = level.getBlockState(upperPos);%0D%0A%09%09int lightLevel = LayerLightEngine.getLightBlockInto(level, state, pos, upperState, upperPos, Direction.UP, upperState.getLightBlock(level, upperPos));%0D%0A%09%09return lightLevel %3C level.getMaxLightLevel();%0D%0A%09%7D%0D%0A%0D%0A
 %09@Ov

remove unused code from ReinforcedNyliumBlock