ComponentType
ComponentType
Section titled “ComponentType”Package: com.hypixel.hytale.component
public class ComponentType<ECS_TYPE, T extends Component<ECS_TYPE>> implements Comparable<ComponentType<ECS_TYPE, ?>>, Query<ECS_TYPE>A type-safe key that identifies a specific component within the ECS. Every component class registered with the system has a corresponding ComponentType instance. This instance is used to get, add, and remove components on entities via Store, and also serves as the simplest form of Query for system matching.
ComponentType instances are created exclusively through ComponentRegistryProxy.registerComponent() — plugin code does not instantiate them directly.
Static Fields
Section titled “Static Fields”@Nonnullpublic static final ComponentType[] EMPTY_ARRAY = new ComponentType[0]Shared empty array constant. Used by internal APIs to avoid allocating empty arrays.
Methods
Section titled “Methods”Registry Access
Section titled “Registry Access”@Nonnullpublic ComponentRegistry<ECS_TYPE> getRegistry()Returns the ComponentRegistry that this type is registered in. There is one ComponentRegistry per store type (EntityStore.REGISTRY, ChunkStore.REGISTRY).
Type Class
Section titled “Type Class”@Nonnullpublic Class<? super T> getTypeClass()Returns the Java class that this component type represents. This is the class passed to registerComponent() at registration time. The ? super T bound allows registration with a supertype class for polymorphic component access.
public int getIndex()Returns the numeric index assigned to this component type within its registry. The index is a dense, auto-incrementing integer starting from zero. It is used internally for archetype bitmask operations and array-indexed component storage. Plugin code typically does not need this value.
Query Interface
Section titled “Query Interface”ComponentType implements Query<ECS_TYPE>, which means a ComponentType can be passed directly anywhere a Query is expected. This is a key design insight: a single component type IS a query.
public boolean test(@Nonnull Archetype<ECS_TYPE> archetype)Returns true if the given archetype contains this component type. Equivalent to archetype.contains(this). This is how the ECS system pipeline determines which archetype chunks a system should process.
public boolean requiresComponentType(ComponentType<ECS_TYPE, ?> componentType)Returns true if this query requires the given component type — i.e., returns this.equals(componentType). For a single ComponentType query, the only required type is itself.
What This Means for Systems
Section titled “What This Means for Systems”When you register a system with a query, you are specifying which archetypes the system operates on. Because ComponentType implements Query, you can pass a component type directly as a system’s query:
// A system that processes all entities with a HealthComponentsystemType.getQuery() // returns ComponentType<EntityStore, HealthComponent>This system will match every archetype that contains the health component, regardless of what other components the archetype has. For more complex queries (requiring multiple components, excluding components), composite Query implementations are used.
Ordering
Section titled “Ordering”ComponentType implements Comparable<ComponentType<ECS_TYPE, ?>>. Ordering is by getIndex(), which ensures a canonical ordering for archetype signatures and deterministic iteration order.
ComponentType instances are typically stored as static fields or plugin instance fields:
// During setup, via ComponentRegistryProxyprivate ComponentType<EntityStore, HealthComponent> HEALTH_TYPE;
@Overrideprotected void setup() { ComponentRegistryProxy<EntityStore> registry = getEntityStoreRegistry(); HEALTH_TYPE = registry.registerComponent(HealthComponent.class, HealthComponent::new);}
// Later, during gameplayHealthComponent health = store.getComponent(ref, HEALTH_TYPE);if (health != null) { health.setCurrentHp(health.getCurrentHp() - damage);}Related Types
Section titled “Related Types”- Store — uses
ComponentTypeas the key forgetComponent(),addComponent(),removeComponent() - Ref — entity reference passed alongside
ComponentTypefor component access - ComponentRegistryProxy — creates
ComponentTypeinstances viaregisterComponent() - PluginBase — provides
getEntityStoreRegistry()andgetChunkStoreRegistry() Component— base class for all ECS component dataComponentRegistry— the underlying registry that stores all component types for a store typeQuery— interface for archetype matching;ComponentTypeis the simplest implementationArchetype— groups entities by component signature; matched against queries- SystemType — the system-side counterpart to
ComponentType; identifies system classes within a registry ISystem— ECS systems that declare queries to select which entities they process