Entity Queries
Lookup by UUID
Section titled “Lookup by UUID”EntityStore entityStore = world.getEntityStore();
// get entity by UUIDRef<EntityStore> ref = entityStore.getRefFromUUID(uuid);if (ref != null && ref.isValid()) { // found entity}Lookup by Network ID
Section titled “Lookup by Network ID”// get entity by client network IDRef<EntityStore> ref = entityStore.getRefFromNetworkId(networkId);Iterating Entities
Section titled “Iterating Entities”forEachChunk
Section titled “forEachChunk”Iterate archetype chunks containing entities with specific components:
Store<EntityStore> store = world.getEntityStore().getStore();
// ComponentType implements Query, so pass it directlystore.forEachChunk(Player.getComponentType(), (archetypeChunk, commandBuffer) -> { for (int index = 0; index < archetypeChunk.size(); index++) { Player player = archetypeChunk.getComponent(index, Player.getComponentType()); TransformComponent transform = archetypeChunk.getComponent(index, TransformComponent.getComponentType()); // process each player }});forEachEntityParallel
Section titled “forEachEntityParallel”For parallel processing with index provided:
store.forEachEntityParallel(Player.getComponentType(), (index, archetypeChunk, commandBuffer) -> { Player player = archetypeChunk.getComponent(index, Player.getComponentType()); // process player (thread-safe operations only)});Query Combinators
Section titled “Query Combinators”Combine component requirements with Query.and() and Query.or():
// entities with both Player AND Health componentsQuery<EntityStore> query = Query.and(Player.getComponentType(), Health.getComponentType());store.forEachChunk(query, (archetypeChunk, commandBuffer) -> { ... });
// entities with Player OR NPC componentsQuery<EntityStore> query = Query.or(Player.getComponentType(), NPC.getComponentType());EntityUtils
Section titled “EntityUtils”Helper methods for working with entities:
// get Entity component from refEntity entity = EntityUtils.getEntity(ref, store);
// check if archetype contains an Entity componentboolean hasEntity = EntityUtils.hasEntity(archetype);
// convert archetype chunk index to HolderHolder<EntityStore> holder = EntityUtils.toHolder(index, archetypeChunk);ECS Events
Section titled “ECS Events”Dispatch events to specific entities using invoke():
// dispatch to single entityDamage damageEvent = new Damage(source, amount, causeIndex);store.invoke(targetRef, damageEvent);
// check if cancelledif (damageEvent.isCancelled()) { return;}To listen to ECS events, create an EntityEventSystem or WorldEventSystem and register it on the store. The getQuery() method on EntityEventSystem uses the same query system described above to filter which entities receive the event.
See ECS Events for the full guide on listening, dispatching, query filtering, and cancellation.