Raycast (Bi-Entity Action Type)

Casts a ray from the actor straight at the target entity.

Casts a ray from the actor’s eye position straight at the target entity, clamped 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 entity-action Raycast (Entity Action Type) with the same fields with only the aiming differs. Two extra fields matter here:

FieldTypeDefaultDescription
aim_at_targetBooleantrueAim at the target instead of the actor’s look direction.
stop_at_targetBooleantrueClamp the ray’s length to the actor→target distance.

Setting an explicit direction overrides the automatic aim.

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 / 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, else 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 by a table of hard-coded bands:

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

Or scale the damage by how far the shot travelled:

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