HitResultHelper
com.jsmacrosce.jsmacros.client.api.helper.world.HitResultHelper
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
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
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.