minecraft:target_nearby_sensor for you with a switch.Get GodCraftOverview
minecraft:target_nearby_sensor is an entity component: it goes in the components object of a custom mob, or in one of its component groups. Watches for targets at two distances and runs events when one comes close, moves away, or goes out of sight. Creepers use this to start swelling.
Fields
| Field | Type | Default | Description |
|---|---|---|---|
inside_range | Decimal | "1" | Distance in blocks that counts as close. |
must_see | Boolean | "false" | If true, the target must be visible for the close event to fire. |
on_inside_range | String | none | Event to run when a target comes within the close range. |
on_outside_range | String | none | Event to run when a target moves beyond the close range but stays within the outer range. |
on_vision_lost_inside_range | String | none | Event to run when a close target can no longer be seen. |
outside_range | Decimal | "5" | Distance in blocks that counts as the outer range. |
Example
Inside the components object of BP/entities/<name>.json (values are the defaults or placeholders):
BP/entities/<name>.json
{
"minecraft:target_nearby_sensor": {
"inside_range": "1",
"must_see": "false",
"on_inside_range": "",
"on_outside_range": "",
"on_vision_lost_inside_range": "",
"outside_range": "5"
}
}