Skip to content

Entity Components

// returns null if entity doesn't have this component
Velocity velocity = store.getComponent(ref, Velocity.getComponentType());
// or ensure it exists (creates default if missing)
Velocity velocity = store.ensureAndGetComponent(ref, Velocity.getComponentType());
// replace component (or add if missing)
store.putComponent(ref, MyComponent.getComponentType(), new MyComponent(newValue));
// add new component (throws if exists)
store.addComponent(ref, MyComponent.getComponentType(), new MyComponent());
// add with default value
MyComponent comp = store.addComponent(ref, MyComponent.getComponentType());
// remove component (throws if missing)
store.removeComponent(ref, MyComponent.getComponentType());
// remove if exists (no-op if missing)
store.tryRemoveComponent(ref, MyComponent.getComponentType());
ComponentPurpose
TransformComponentPosition and rotation
VelocityMovement velocity
HeadRotationHead/look direction
ModelComponentVisual model reference
BoundingBoxCollision bounds
UUIDComponentUnique identifier
DisplayNameComponentEntity display name
EntityStatMapEntity stats (health, stamina, mana, etc.)
InvulnerableDamage immunity flag
IntangibleCollision bypass flag
DespawnComponentAuto-despawn timer
EffectControllerComponentStatus effects (buffs, debuffs, DoT)

Mods can register their own components via getEntityStoreRegistry(). Components registered with a string ID and BuilderCodec are automatically persisted when the entity is saved. See Storing Data for the full pattern.

ComponentAccessor<EntityStore> is an interface implemented by both Store and CommandBuffer. Many APIs accept it to work in either context.

ImplementationReadsWritesContext
StoreImmediateImmediateCommands, event handlers, plugin code
CommandBufferImmediateQueued/batchedECS systems (tick, event systems)

In commands and plugin code, you typically have a Store directly - writes happen immediately.

In ECS systems, you receive a CommandBuffer - writes are queued and applied after all systems complete. This enables safe parallel processing.

// in a command - Store, immediate writes
public void execute(Ref<EntityStore> ref, Store<EntityStore> store, ...) {
store.addComponent(ref, MyComponent.getComponentType(), component); // happens now
}
// in a system - CommandBuffer, batched writes
public void tick(..., CommandBuffer<EntityStore> buffer, ...) {
buffer.addComponent(ref, MyComponent.getComponentType(), component); // queued
}