Skip to content

HitResultHelper ​

com.jsmacrosce.jsmacros.client.api.helper.world.HitResultHelper

Since1.9.1

Wraps a crosshair hit result, with shared access to its hit position and subtype-specific access for block and entity hits. Use InteractionManagerHelper.getTarget() for the current target or resolve(HitResult) to wrap a raw result. Misses use Block.

js
const interactions = Player.interactions();  
const target = interactions === null ? null : interactions.getTarget();  
if (target === null) {
 // nothing under the crosshair at all
} else if (target instanceof HitResults.Entity) {
 const entity = target.getEntity();  
 Chat.log(`the crosshair is on ${entity.getName()} at ${target.getPos()}`);  
} else if (target instanceof HitResults.Block) {
 const blockPos = target.getBlockPos();  
 if (blockPos !== null) {
   Chat.log(`the crosshair is on the ${target.getSide().getName()} face of ${blockPos}`);  
 }
}

// the point where the ray landed is on all three kinds
if (target !== null) { Chat.log(target.getPos()); }

Available in scripts as HitResults.Result.

Type Parameters ​

  • T: the Minecraft hit-result type wrapped by this helper

Nested types ​

Methods ​

asBlock ​

asBlock(): HitResultHelper.BlockSince1.9.1#
Returns this target as a block hit or miss, or null for other hit-result types.
Returns: this target as a Block, or null if it is not a block target.

asEntity ​

asEntity(): HitResultHelper.EntitySince1.9.1#
Returns this target as an entity hit, or null for other hit-result types.
Returns: this target as an Entity, or null if it is not an entity target.

getPos ​

getPos(): Pos3DSince1.9.1#
Returns the hit location as a world-space point, without rounding its coordinates.
Returns: where the hit landed, as a point in the world.

resolve ​

static resolve(HitResult hr): HitResultHelper<?>Since1.9.1#
Wraps a raw hit result as a Block for block hits and misses, or an Entity for entity hits. Returns null for a null input.

Parameters:

  • hr: the raw hit result to wrap, or null.
Returns: the matching subclass of this helper, or null if hr was null.

toString ​

toString(): String#
Returns a diagnostic string containing the hit position.
Returns: a diagnostic containing the position rendered from getPos().