minecraft-src/net/minecraft/world/item/context/UseOnContext.java
2025-07-04 01:41:11 +03:00

81 lines
2 KiB
Java

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.jetbrains.annotations.Nullable;
public class UseOnContext {
@Nullable
private final Player player;
private final InteractionHand hand;
private final BlockHitResult hitResult;
private final Level level;
private final ItemStack itemStack;
public UseOnContext(Player player, InteractionHand hand, BlockHitResult hitResult) {
this(player.level(), player, hand, player.getItemInHand(hand), hitResult);
}
protected UseOnContext(Level level, @Nullable Player player, InteractionHand hand, ItemStack itemStack, 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;
}
@Nullable
public 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();
}
}