Class Archetype<ECS_TYPE>

java.lang.Object
com.hypixel.hytale.component.Archetype<ECS_TYPE>
Type Parameters:
ECS_TYPE - The ECS entity data type.
All Implemented Interfaces:
Query<ECS_TYPE>

public class Archetype<ECS_TYPE> extends Object implements Query<ECS_TYPE>
An entity archetype, which describes a set of component types.

This is used both to group entities of the same type and to allow for easier creation of entities.

  • Method Details

    • empty

      public static <ECS_TYPE> Archetype<ECS_TYPE> empty()
      Type Parameters:
      ECS_TYPE - The ECS entity data type.
      Returns:
      the reusable empty archetype.
    • getMinIndex

      public int getMinIndex()
      Returns:
      The minimum ComponentType.getIndex() contained within this Archetype.
      See Also:
    • count

      public int count()
      Returns:
      The number of component types in this Archetype
    • length

      public int length()
      Returns:
      The length of the internal array. To be used with getMinIndex() and get(int)
      See Also:
    • get

      @Nullable public ComponentType<ECS_TYPE,?> get(int index)
      Parameters:
      index - The ComponentType.getIndex() of the component type.
      Returns:
      The component type with the specified index if it exists within the Archetype.
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if this Archetype contains no component types, false otherwise.
    • contains

      public boolean contains(@Nonnull ComponentType<ECS_TYPE,?> componentType)
      Parameters:
      componentType - The ComponentType to test for.
      Returns:
      true if this Archetype contains the provided ComponentType
    • contains

      public boolean contains(@Nonnull Archetype<ECS_TYPE> archetype)
      Parameters:
      archetype - The Archetype of component types to check for.
      Returns:
      true if this Archetype contains all ComponentType's from the provided Archetype.
    • validateComponentType

      public void validateComponentType(@Nonnull ComponentType<ECS_TYPE,?> componentType)
      Called to validate that the provided ComponentType exists within this Archetype.

      Throws an IllegalArgumentException if the ComponentType does not exist within this Archetype.

      Parameters:
      componentType - The ComponentType to validate.
    • validateComponents

      public void validateComponents(@Nonnull Component<ECS_TYPE>[] components, @Nullable ComponentType<ECS_TYPE, UnknownComponents<ECS_TYPE>> ignore)
      Called to validate that the provided array of Component's matches this Archetype.

      Throws an IllegalStateException if any Component does not match the expected ComponentType.

      Parameters:
      components - The array of components to validate.
      ignore - An optional ComponentType to ignore during validation.
    • hasSerializableComponents

      public boolean hasSerializableComponents(@Nonnull ComponentRegistry.Data<ECS_TYPE> data)
      Determines whether this archetype has any serializable components.
      Parameters:
      data - The component registry data.
      Returns:
      true if this archetype has any serializable components, false otherwise.
    • getSerializableArchetype

      @Nonnull public Archetype<ECS_TYPE> getSerializableArchetype(@Nonnull ComponentRegistry.Data<ECS_TYPE> data, @Nullable Predicate<ComponentType<ECS_TYPE,?>> filter)
      Gets a new archetype containing only the serializable components from this archetype.
      Parameters:
      data - The component registry data.
      filter - Optional additional predicate; components failing the test are excluded. null means no additional filtering.
      Returns:
      a new archetype containing only the serializable components from this archetype.
    • asExactQuery

      @Nonnull public ExactArchetypeQuery<ECS_TYPE> asExactQuery()
      Returns:
      the exact archetype query for this archetype.
    • of

      @Nonnull public static <ECS_TYPE> Archetype<ECS_TYPE> of(@Nonnull ComponentType<ECS_TYPE,?> componentTypes)
      Creates a new Archetype instance from a single ComponentType.
      Type Parameters:
      ECS_TYPE - The ECS entity data type.
      Parameters:
      componentTypes - The component type.
      Returns:
      the new archetype, containing only the provided component type.
    • of

      @SafeVarargs public static <ECS_TYPE> Archetype<ECS_TYPE> of(@Nonnull ComponentType<ECS_TYPE,?>... componentTypes)
      Creates a new Archetype instance from multiple ComponentType's.
      Type Parameters:
      ECS_TYPE - The ECS entity data type.
      Parameters:
      componentTypes - The component types.
      Returns:
      the new archetype, containing the provided component types.
    • add

      @Nonnull public static <ECS_TYPE, T extends Component<ECS_TYPE>> Archetype<ECS_TYPE> add(@Nonnull Archetype<ECS_TYPE> archetype, @Nonnull ComponentType<ECS_TYPE,T> componentType)
      Adds a ComponentType to an existing Archetype, returning a new Archetype instance.
      Type Parameters:
      ECS_TYPE - The ECS entity data type.
      T - The component type.
      Parameters:
      archetype - The existing archetype.
      componentType - The component type to add.
      Returns:
      the new archetype with the added component type.
    • remove

      public static <ECS_TYPE, T extends Component<ECS_TYPE>> Archetype<ECS_TYPE> remove(@Nonnull Archetype<ECS_TYPE> archetype, @Nonnull ComponentType<ECS_TYPE,T> componentType)
      Removes a ComponentType from an existing Archetype, returning a new Archetype instance.
      Type Parameters:
      ECS_TYPE - The ECS entity data type.
      T - The component type.
      Parameters:
      archetype - The existing archetype.
      componentType - The component type to remove.
      Returns:
      the new archetype with the removed component type.
    • test

      public boolean test(@Nonnull Archetype<ECS_TYPE> archetype)
      Description copied from interface: Query
      Controls if this query should process the provided Archetype.
      Specified by:
      test in interface Query<ECS_TYPE>
      Returns:
      true if the archetype should be processed by this query.
    • requiresComponentType

      public boolean requiresComponentType(@Nonnull ComponentType<ECS_TYPE,?> componentType)
      Description copied from interface: Query
      Controls if a query requires a component and so if used by a system it should be automatically unregistered if a component type is removed.
      Specified by:
      requiresComponentType in interface Query<ECS_TYPE>
      Returns:
      true if the componentType is required.
    • validateRegistry

      public void validateRegistry(@Nonnull ComponentRegistry<ECS_TYPE> registry)
      Description copied from interface: Query
      Validates that the provided ComponentRegistry is compatible with this query.
      Specified by:
      validateRegistry in interface Query<ECS_TYPE>
      Parameters:
      registry - The component registry to validate against.
    • validate

      public void validate()
      Description copied from interface: Query
      Validates the internal state of this query.
      Specified by:
      validate in interface Query<ECS_TYPE>
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object