Skip to main content
The ECS (Entity Component System) is the backbone of Hytale’s game engine. Every NPC, player, block entity, projectile, and effect is an entity made up of components. HRTK’s ECS surface lets you create entities, attach and remove components, look up entities, and check entity state - all within the live game. If you are new to ECS, here are the key concepts:
  • Entity Store - The database that holds all entities and their components. Every entity lives inside the store.
  • Ref - A lightweight reference (like an ID) to an entity in the store. You use refs to look up, modify, or destroy entities.
  • Component - A data object attached to an entity. Components hold state but no logic. For example, TransformComponent holds position/rotation, HealthComponent holds HP values.
  • Archetype - The set of component types an entity has. Entities with the same components share an archetype, which lets the engine look them up efficiently.
Understanding these concepts helps when writing mod tests, because nearly every game system in Hytale reads and writes components on entities through the store.

@EcsTest

Annotate a test method with @EcsTest to receive an EcsTestContext and automatically get the "ecs" tag. Tests marked with @EcsTest run on the world thread and have full access to the entity store.
Use IsolationStrategy.SNAPSHOT on your suite when your ECS tests mutate state. The snapshot captures the store before the suite and restores it after, so your tests do not pollute the live server.

EcsTestContext Methods

EcsAssert Methods

How EcsAssert Works Internally

Because hrtk-api is a compile-only dependency (it never ships with the server), all ECS assertions use reflection under the hood. You pass the store, refs, and component types as Object in your code, but they must be the correct Hytale types at runtime.
This design lets your mod compile against hrtk-api without needing the Hytale server JAR at compile time.

Why Test ECS Operations?

ECS testing matters for modders because:
  1. Component integrity - Verify that your custom components attach and detach correctly without corrupting the archetype.
  2. Query correctness - Confirm that your systems find the right entities. A missing component means your system silently skips entities it should process.
  3. Lifecycle safety - Catch bugs where entities are used after destruction, or components are read before they are attached.
  4. Regression detection - Server updates can change how the ECS handles edge cases. Tests catch these regressions early.

Next Steps