package net.minecraft.world.level.block;

import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

/**
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
 */
public class BushBlock extends VegetationBlock implements BonemealableBlock {
	public static final int DEFAULT_SHAPE_HEIGHT = 13;
	private final VoxelShape shape;
	private final int shapeHeight;

	/**
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
	 */
	public BushBlock(final BlockBehaviour.Properties properties) {
		this(properties, 13);
	}

	/**
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
	 */
	public BushBlock(final BlockBehaviour.Properties properties, final int shapeHeight) {
		super(properties);
		this.shapeHeight = shapeHeight;
		this.shape = Block.column(16.0, 0.0, shapeHeight);
	}

	@Override
	protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
		return this.shape;
	}

	@Override
	public boolean isValidBonemealTarget(final LevelReader level, final BlockPos pos, final BlockState state, final BonemealSource source) {
		return BonemealableBlock.hasSpreadableNeighbourPos(level, pos, state);
	}

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

	@Override
	public void performBonemeal(final ServerLevel level, final RandomSource random, final BlockPos pos, final BlockState state, final BonemealSource source) {
		BonemealableBlock.findSpreadableNeighbourPos(level, pos, state).ifPresent(blockPos -> level.setBlockAndUpdate(blockPos, this.defaultBlockState()));
	}
}
