Skip to main content

Raycast (Bi-Entity Action Type)

Casts a ray from the actor's eye position straight at the target entity, limited to the distance between them, and runs actions on whatever it passes through.

Type ID: apoli:raycast (alias apoli:raycast_between)

This is the same action as the Raycast entity action, with the same fields, and only the aiming differs. Two extra fields matter here:

FieldTypeDefaultDescription
aim_at_targetBooleantrueAims at the target instead of along the actor's look direction.
stop_at_targetBooleantrueLimits the ray's length to the distance from the actor to the target.

The numeric fields accept expressions, evaluated against the actor. The target and actor are both bound, so the fields can read target_ variables. An explicit direction overrides the automatic aim.

To test whether the target is inside the actor's ray, beam or cone without casting anything, use the raycast bi-entity condition.

Example

Draw a beam between two entities and break whatever is between them:

{
   "type":"apoli:raycast",
   "particle":{
      "type":"minecraft:electric_spark"
   },
   "spacing":0.3,
   "pierce_blocks":true,
   "block_action":{
      "type":"apoli:set_block",
      "block":"minecraft:air"
   }
}

Check line of sight by running a hit_action only when something is in the way:

{
   "type":"apoli:raycast",
   "entity":false,
   "hit_action":{
      "type":"apoli:play_sound",
      "sound":"minecraft:block.note_block.bass"
   }
}

Values the hooks can read

While this action runs, it binds expression variables that the hooks, and anything nested inside them, can read:

VariableIn hit_action and miss_actionIn bientity_actionIn block_action
distanceto where the ray stoppedto that entity's hit pointto that block's hit point
hit_x, hit_y, hit_zwhere the ray stoppedthat entity's hit pointthat block's hit point
count1 if anything was hit, otherwise 0how many entities the ray hit1
index0the zero-based order of this entity along the raythe pierce step

So the hit distance can go straight into a resource, instead of being approximated with a table of hard-coded bands:

"hit_action": {
  "type": "apoli:modify_resource",
  "resource": "example:last_shot_distance",
  "modifier": {
    "operation": "set_base",
    "value": "distance"
  }
}

Or the damage can scale with how far the shot travelled:

"bientity_action": {
    "type": "apoli:damage",
    "damage_type": "minecraft:player_attack",
    "amount": "max(1, 20 - distance)"
}