| 1 | package net.minecraft.world.item.context;
|
| 2 |
|
| 3 | import net.minecraft.core.BlockPos;
|
| 4 | import net.minecraft.core.Direction;
|
| 5 | import net.minecraft.world.InteractionHand;
|
| 6 | import net.minecraft.world.entity.player.Player;
|
| 7 | import net.minecraft.world.item.ItemStack;
|
| 8 | import net.minecraft.world.level.Level;
|
| 9 | import net.minecraft.world.phys.BlockHitResult;
|
| 10 | import net.minecraft.world.phys.Vec3;
|
| 11 | import org.jspecify.annotations.Nullable;
|
| 12 |
|
| 13 | /**
|
| 14 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 15 | */
|
| 16 | public class UseOnContext {
|
| 17 | private final @Nullable Player player;
|
| 18 | private final InteractionHand hand;
|
| 19 | private final BlockHitResult hitResult;
|
| 20 | private final Level level;
|
| 21 | private final ItemStack itemStack;
|
| 22 |
|
| 23 | public UseOnContext(final Player player, final InteractionHand hand, final BlockHitResult hitResult) {
|
| 24 | this(player.level(), player, hand, player.getItemInHand(hand), hitResult);
|
| 25 | }
|
| 26 |
|
| 27 | /**
|
| 28 | * Access widened by fabric-transitive-access-wideners-v1 to accessible
|
| 29 | */
|
| 30 | public UseOnContext(final Level level, final @Nullable Player player, final InteractionHand hand, final ItemStack itemStack, final BlockHitResult hitResult) {
|
| 31 | this.player = player;
|
| 32 | this.hand = hand;
|
| 33 | this.hitResult = hitResult;
|
| 34 | this.itemStack = itemStack;
|
| 35 | this.level = level;
|
| 36 | }
|
| 37 |
|
| 38 | protected final BlockHitResult getHitResult() {
|
| 39 | return this.hitResult;
|
| 40 | }
|
| 41 |
|
| 42 | public BlockPos getClickedPos() {
|
| 43 | return this.hitResult.getBlockPos();
|
| 44 | }
|
| 45 |
|
| 46 | public Direction getClickedFace() {
|
| 47 | return this.hitResult.getDirection();
|
| 48 | }
|
| 49 |
|
| 50 | public Vec3 getClickLocation() {
|
| 51 | return this.hitResult.getLocation();
|
| 52 | }
|
| 53 |
|
| 54 | public boolean isInside() {
|
| 55 | return this.hitResult.isInside();
|
| 56 | }
|
| 57 |
|
| 58 | public ItemStack getItemInHand() {
|
| 59 | return this.itemStack;
|
| 60 | }
|
| 61 |
|
| 62 | public @Nullable Player getPlayer() {
|
| 63 | return this.player;
|
| 64 | }
|
| 65 |
|
| 66 | public InteractionHand getHand() {
|
| 67 | return this.hand;
|
| 68 | }
|
| 69 |
|
| 70 | public Level getLevel() {
|
| 71 | return this.level;
|
| 72 | }
|
| 73 |
|
| 74 | public Direction getHorizontalDirection() {
|
| 75 | return this.player == null ? Direction.NORTH : this.player.getDirection();
|
| 76 | }
|
| 77 |
|
| 78 | public boolean isSecondaryUseActive() {
|
| 79 | return this.player != null && this.player.isSecondaryUseActive();
|
| 80 | }
|
| 81 |
|
| 82 | public float getRotation() {
|
| 83 | return this.player == null ? 0.0F : this.player.getYRot();
|
| 84 | }
|
| 85 | }
|
| 86 |
|