public interface Entity extends EntityContainer, Identifiable, AttributeContainer, Taggable, ActionScheduler<Entity>
AttributeType
as
well as AttributeListener
for trigger code upon add, removal or change of those
attributes. Entities can create and kill other entities (tree-like structure) these events can be
accessed by adding EntityListener
. Entities
. Entity have can have a number of types (subclasses
of Entity
) which can be used to identify a collection of entities with similar state or
function.
public interface Animal extends Entity {}
public interface FlyingAnimal extends Animal {}
Entity e; // Previously created entity.
e.markAsType(FlyingAnimal.class);
assert e.isMarkedAsType(Animal.class);
NOTE: Taking an entity asType(Class)
is similar to casting but does not mark as the
entity with the type.Modifier and Type | Method and Description |
---|---|
boolean |
addEntityTypeListener(EntityTypeListener listener)
Adds a listener for the entity.
|
default <T extends Entity> |
asType(java.lang.Class<T> type)
Convenience method for wrapping the entity to a different type.
|
EntityContainer |
getContainer()
Gets the parent container.
|
java.util.Set<? extends EntityTypeListener> |
getEntityTypeListeners()
Gets all the entity listeners.
|
default java.util.Set<java.lang.Class<? extends Entity>> |
getMarkedAsTypes()
Gets the types this entity has been marked as.
|
default java.util.Optional<EntityContainer> |
getOptContainer()
This is a convenience method for getting the container (optional).
|
default boolean |
hasContainer()
Checks whether there is an associated container.
|
default boolean |
hasEntityTypeListener(EntityTypeListener listener)
Checks whether the container contains a particular listener.
|
boolean |
isAlive()
Checks if the entity is alive.
|
boolean |
isMarkedAsType(java.lang.Class<? extends Entity> type)
Checks whether the entity has the associated type.
|
boolean |
kill()
Kills the entity.
|
boolean |
markAsType(java.lang.Class<? extends Entity> type)
Adds the specified type to the entity.
|
boolean |
removeEntityTypeListener(EntityTypeListener listener)
Removes a entity listener.
|
void |
removeEntityTypeListeners()
Removes all listeners for entities.
|
java.util.stream.Stream<java.lang.Class<? extends Entity>> |
streamMarkedAsTypes()
Streams the types this entity has been marked as.
|
boolean |
transfer(EntityContainer destination)
Transfers this entity to the specified destination container.
|
void |
unmarkAsAllTypes()
Removes all the types from the entity.
|
boolean |
unmarkAsType(java.lang.Class<? extends Entity> type)
Removes the specified type from the entity.
|
addEntityListener, getEntities, getEntitiesAsType, getEntitiesOfType, getEntity, getEntityAsType, getEntityCount, getEntityIDs, getEntityListeners, getOptEntity, getOptEntityAsType, hasEntities, hasEntity, hasEntityListener, killEntities, killEntity, newEntity, newEntity, newEntity, newEntity, newEntity, newEntity, newEntity, newEntity, receiveEntity, removeEntityListener, removeEntityListeners, streamEntities, streamEntitiesAsType, streamEntitiesOfType, streamEntityIDs, transferAllEntities, transferEntities, transferEntities, transferEntity
equals, getID, getID, hashCode, is, not, toString
addAll, addAllAttributeListeners, addAllAttributes, addAttributeListener, addAttributeListener, fireAttributeChanged, fireAttributeChanged, getAttribute, getAttribute, getAttributeCount, getAttributeListenerNames, getAttributeListeners, getAttributeListeners, getAttributeListenerTypes, getAttributeListenerTypes, getAttributeNames, getAttributes, getAttributeTypes, getAttributeTypes, getOptAttribute, getOptAttribute, hasAttribute, hasAttribute, hasAttributeListener, hasAttributeListener, hasAttributeListeners, hasAttributeListeners, hasAttributes, removeAttribute, removeAttribute, removeAttributeListener, removeAttributeListener, removeAttributeListeners, removeAttributeListeners, removeAttributeListeners, removeAttributes, removeOptAttribute, removeOptAttribute, setAttribute, setAttribute, setOptAttribute, setOptAttribute, streamAttributes
getTags, streamTags
cancelAllScheduledForActor, newContextForActor, scheduleForActor, scheduleForActor, scheduleForActor
boolean addEntityTypeListener(EntityTypeListener listener)
listener
- Listener to add.true
if container did not already contain this listener.java.lang.NullPointerException
- if listener is null.ListenerSet.add(Object)
default <T extends Entity> T asType(java.lang.Class<T> type)
type
- Entity type to wrap to.Entities.asType(Entity, Class)
EntityContainer getContainer()
java.util.Set<? extends EntityTypeListener> getEntityTypeListeners()
default java.util.Set<java.lang.Class<? extends Entity>> getMarkedAsTypes()
streamMarkedAsTypes()
default java.util.Optional<EntityContainer> getOptContainer()
default boolean hasContainer()
default boolean hasEntityTypeListener(EntityTypeListener listener)
listener
- The EntityListener to check for.boolean isAlive()
boolean isMarkedAsType(java.lang.Class<? extends Entity> type)
type
- Entity type to check.boolean kill()
boolean markAsType(java.lang.Class<? extends Entity> type)
type
- Entity type to add.boolean removeEntityTypeListener(EntityTypeListener listener)
listener
- Listener to remove.true
if the listener was removed.java.lang.NullPointerException
- if listener is null.ListenerSet.remove(Object)
void removeEntityTypeListeners()
java.util.stream.Stream<java.lang.Class<? extends Entity>> streamMarkedAsTypes()
boolean transfer(EntityContainer destination)
destination
- Target container.void unmarkAsAllTypes()
boolean unmarkAsType(java.lang.Class<? extends Entity> type)
type
- Entity type to remove.