package net.minecraft.world.item.context;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import org.jspecify.annotations.Nullable;

/**
 * Access widened by fabric-transitive-access-wideners-v1 to accessible
 */
public class UseOnContext {
	private final @Nullable Player player;
	private final InteractionHand hand;
	private final BlockHitResult hitResult;
	private final Level level;
	private final ItemStack itemStack;

	public UseOnContext(final Player player, final InteractionHand hand, final BlockHitResult hitResult) {
		this(player.level(), player, hand, player.getItemInHand(hand), hitResult);
	}

	/**
	 * Access widened by fabric-transitive-access-wideners-v1 to accessible
	 */
	public UseOnContext(final Level level, final @Nullable Player player, final InteractionHand hand, final ItemStack itemStack, final BlockHitResult hitResult) {
		this.player = player;
		this.hand = hand;
		this.hitResult = hitResult;
		this.itemStack = itemStack;
		this.level = level;
	}

	protected final BlockHitResult getHitResult() {
		return this.hitResult;
	}

	public BlockPos getClickedPos() {
		return this.hitResult.getBlockPos();
	}

	public Direction getClickedFace() {
		return this.hitResult.getDirection();
	}

	public Vec3 getClickLocation() {
		return this.hitResult.getLocation();
	}

	public boolean isInside() {
		return this.hitResult.isInside();
	}

	public ItemStack getItemInHand() {
		return this.itemStack;
	}

	public @Nullable Player getPlayer() {
		return this.player;
	}

	public InteractionHand getHand() {
		return this.hand;
	}

	public Level getLevel() {
		return this.level;
	}

	public Direction getHorizontalDirection() {
		return this.player == null ? Direction.NORTH : this.player.getDirection();
	}

	public boolean isSecondaryUseActive() {
		return this.player != null && this.player.isSecondaryUseActive();
	}

	public float getRotation() {
		return this.player == null ? 0.0F : this.player.getYRot();
	}
}
