Class Entity

java.lang.Object
technology.sola.ecs.Entity

@NullMarked public class Entity extends Object
An Entity is identified by its index in the World that ties a set of Components together.
  • Method Details

    • getIndexInWorld

      public int getIndexInWorld()
      Gets the integer id of this Entity.
      Returns:
      the id of this Entity
    • getUniqueId

      public String getUniqueId()
      Gets the unique id of this entity that persists through serialization and deserialization.
      Returns:
      the unique id of the Entity
    • getName

      public @Nullable String getName()
      Gets the name of this Entity. A name is optional and will be null if not manually set.
      Returns:
      the name of the Entity
    • setName

      public Entity setName(@Nullable String name)
      Sets the name of this Entity. A name can be used to look up an Entity via World.findEntityByName(String).
      Parameters:
      name - the name of the Entity
      Returns:
      this Entity
    • isDisabled

      public boolean isDisabled()
      Returns whether this Entity should be considered disabled or not.
      Returns:
      true if this Entity is disabled
    • setDisabled

      public Entity setDisabled(boolean disabled)
      Updates the disabled state of this Entity.
      Parameters:
      disabled - the new disabled state of this Entity
      Returns:
      this
    • destroy

      public void destroy()
      Queues this Entity for destruction. This typically should happen at the end of the current frame.
    • addComponent

      public Entity addComponent(Component component)
      Adds a Component to this Entity.
      Parameters:
      component - the Component to add
      Returns:
      this Entity
    • getComponent

      public <T extends Component> @Nullable T getComponent(Class<T> componentClass)
      Gets a Component instance for the class passed in.
      Type Parameters:
      T - the type of the Component class to get
      Parameters:
      componentClass - the class of the Component to get
      Returns:
      the Component instance or null
    • hasComponent

      public <T extends Component> boolean hasComponent(Class<T> componentClass)
      Returns true if this Entity has the Component.
      Type Parameters:
      T - the type extending Component
      Parameters:
      componentClass - Component class to check for
      Returns:
      true if Entity has the Component
    • removeComponent

      public void removeComponent(Class<? extends Component> componentClassToRemove)
      Removes a Component from this Entity.
      Parameters:
      componentClassToRemove - the Class of the Component to remove
    • getCurrentComponents

      public List<Class<? extends Component>> getCurrentComponents()
      Returns a list of the current Component classes that this entity has.
      Returns:
      the list of Component classes