Class EntityQuery
count() is a single cheap RPC, the natural probe for
eventually(timeout, () -> assertThat(query.count()).isEqualTo(n)); snapshot() reads all
matching entities in one main-thread burst, so the returned states are internally consistent and share one
tick stamp — the property that makes "N in flight, zero after" accounting deterministic.
Only entities in loaded chunks are visible (the Bukkit contract). In a world with no players keep the
relevant chunks loaded — e.g. via the console command forceload add — or the server unloads them,
taking their entities out of query range.
-
Method Summary
Modifier and TypeMethodDescriptionintcount()Counts the matching entities — one RPC, the cheap probe shape for retrying assertions.Returns a copy of this query filtered to one entity type.snapshot()Snapshots all matching entities in one main-thread burst.Returns a copy of this query restricted to a block-aligned bounding box (inclusive on every axis).
-
Method Details
-
ofType
Returns a copy of this query filtered to one entity type.- Parameters:
typeKey- Namespaced entity type key, e.g.minecraft:block_display(theminecraft:prefix is optional).- Returns:
- A new query with the type filter applied.
-
within
Returns a copy of this query restricted to a block-aligned bounding box (inclusive on every axis).An entity matches when its hitbox intersects the box (the Bukkit nearby-entities semantic), not only when its position lies inside it — a large entity standing just outside the box whose hitbox overlaps it still counts.
- Parameters:
min- Minimum corner.max- Maximum corner.- Returns:
- A new query with the spatial bound applied.
-
count
public int count()Counts the matching entities — one RPC, the cheap probe shape for retrying assertions.- Returns:
- The number of matching entities right now.
-
description
- Returns:
- A read-only description of the world and filters, without executing the query.
-
snapshot
Snapshots all matching entities in one main-thread burst.- Returns:
- Internally consistent snapshots sharing one tick stamp.
-