Skip to content

Entity Detector

The Entity Detector block
Entity Detector. Asset render of the block model, not an in-game screenshot.

The detector watches the area around it. It notices when a player, mob or item comes into range or leaves, and it can count and list what it sees. It is the device behind alarms, automatic doors and visitor counters.

Entity Detector

Shaped crafting table recipe. Progression: early automation. Ingredients: 4 × Iron Ingot, 1 × Glass Pane, 2 × Tripwire Hook, 1 × Redstone, 1 × Copper Ingot. It appears in the recipe book once you pick up one of its ingredients.

Place it where things will pass, for example beside a door; its lens faces you. Link it to a Network Repeater. It looks in every direction, so its facing does not change what it sees.

The Entity Detector form with name, radius, event filter, readings and trust controls.
The Entity Detector's form. Tall forms scroll when the window is small. In-game screenshot from FilaSignal's automated client test.

Open it with an empty hand:

Setting Meaning
Device name, Save alias The name programs use, such as gate.
Radius, Save radius How far it looks, 1 to 16 blocks from its center. Default 8.
Events report Which entities raise entityEnter, entityLeave and countChanged: all, player, hostile, passive, item or other.
Refresh Shows what it sees right now.

Players (except spectators), mobs, animals, dropped items and other entities. Each has a category: player, hostile, passive, item or other, matching the Entity constants.

An entity in an event is a dictionary:

Field Value
name the player’s name, the custom name or the entity’s displayed name
type the entity type ID, such as minecraft:zombie
category a constant such as Entity.HOSTILE
hostile, player true or false
x, y, z, distance block position and distance in blocks
uuid players only

A result of scan(...) or nearest(...) has type, category as text (such as "hostile"), x, y, z and distance, plus name for players and entities with a visible custom name. No health, inventories or other private details are available.

Yes. With a drive, the detector can run its own program and use device.scan(...), device.count(...), device.nearest(...), device.census(...) and device.radius(), plus device.entityEnter and the other events.

detectors.named(alias)

Refer to an Entity Detector by its name. Use it in a constant, then handle its events with on NAME.event(...).

Parameters: alias: string. Gives: EntityDetector. Cost: 4 operations.

const gate = detectors.named("gate")

detectors.from(alias)

Resolve an entity detector by name.

Parameters: alias: string. Gives: EntityDetector, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied. Capability: detector.read. Cost: 16 operations.

gate, err = detectors.from("gate")

A filter is an Entity constant such as Entity.HOSTILE, the same word as text, or an entity type ID such as "minecraft:zombie".

Properties: gate.connected, gate.id, gate.kind, gate.name. They are read-only.

gate.census(filter)

Count matches and say whether the scan was cut short: count, truncated (true when more than 256 entities were in range, so count is a lower bound) and nearest (a match or nil). Filters: Entity.ALL, Entity.PLAYER, Entity.HOSTILE, Entity.PASSIVE, Entity.ITEM, Entity.OTHER or an entity type ID such as "minecraft:zombie".

Parameters: filter: enum or string. Gives: dict, or an error. Errors: argument.invalid, detector.busy, device.type, device.unavailable, device.unknown, host.denied. Capability: detector.read. Cost: 32 operations.

seen, err = gate.census("hostile")

gate.count(filter)

Count matching entities within the radius. At most 256 entities are examined; use census to learn whether a count was cut short. Filters: Entity.ALL, Entity.PLAYER, Entity.HOSTILE, Entity.PASSIVE, Entity.ITEM, Entity.OTHER or an entity type ID such as "minecraft:zombie".

Parameters: filter: enum or string. Gives: number, or an error. Errors: argument.invalid, detector.busy, device.type, device.unavailable, device.unknown, host.denied. Capability: detector.read. Cost: 32 operations.

zombies, err = gate.count("minecraft:zombie")

gate.nearest(filter)

Describe the nearest matching entity, or nil when none is present. Filters: Entity.ALL, Entity.PLAYER, Entity.HOSTILE, Entity.PASSIVE, Entity.ITEM, Entity.OTHER or an entity type ID such as "minecraft:zombie".

Parameters: filter: enum or string. Gives: dict, or an error. Errors: argument.invalid, detector.busy, device.type, device.unavailable, device.unknown, host.denied. Capability: detector.read. Cost: 32 operations.

closest, err = gate.nearest("player")

gate.radius()

Read the configured detection radius in blocks (1–16).

Gives: number, or an error. Errors: device.type, device.unavailable, device.unknown, host.denied. Capability: detector.read. Cost: 4 operations.

radius, err = gate.radius()

gate.scan(filter)

List up to 32 matching entities, nearest first, with type, category, x, y, z, distance and name for players or named entities. Filters: Entity.ALL, Entity.PLAYER, Entity.HOSTILE, Entity.PASSIVE, Entity.ITEM, Entity.OTHER or an entity type ID such as "minecraft:zombie".

Parameters: filter: enum or string. Gives: list, or an error. Errors: argument.invalid, detector.busy, device.type, device.unavailable, device.unknown, host.denied. Capability: detector.read. Cost: 32 operations.

hostiles, err = gate.scan("hostile")
EventWhen it runs
entityEnter(entity)Runs when an entity enters the detector's range. entity has name, type, category, hostile, player, x, y, z and distance.
entityLeave(entity)Runs when an entity leaves the detector's range.
countChanged(count, previous)Runs when the number of entities in range changes.
connectedRuns when the device becomes reachable, for example after its area loads.
disconnectedRuns when the device stops being reachable: unloaded, unlinked or removed.
programStartedRuns when the device's own program starts.
programStoppedRuns when the device's own program stops.
programFailed(message)Runs when the device's own program stops on an error.
  • It examines at most 256 entities. With more in range, count stops at 256, census reports truncated: true, and events report arrivals but no departures or counts.
  • scan returns at most 32 entities, nearest first.
  • A server runs at most 16 new scans per tick; more return detector.busy, so try again on the next tick. Calls in the same tick share one scan.
  • Events compare readings every 10 ticks, and only while a program listens.
const gate = detectors.named("gate")
on gate.countChanged(count, previous) {
if count > previous {
print(str(count) + " things near the gate")
}
}
on gate.entityEnter(entity) {
if entity.player {
print("Welcome, " + entity.name)
} else if entity.hostile {
print("A " + entity.type + " is coming!")
}
}