Package dev.prozilla.pine.core.entity
Class Entity
java.lang.Object
dev.prozilla.pine.common.event.EventDispatcher<EntityEventType,Entity,Event<EntityEventType,Entity>>
dev.prozilla.pine.common.event.SimpleEventDispatcher<EntityEventType,Entity>
dev.prozilla.pine.core.entity.Entity
- All Implemented Interfaces:
EventDispatcherContext<EntityEventType,,Entity, Event<EntityEventType, Entity>> Destructible,Printable,ApplicationContext,ApplicationProvider,ComponentsContext,EntityContext,SceneContext,SceneProvider
public class Entity
extends SimpleEventDispatcher<EntityEventType,Entity>
implements Destructible, Printable, EntityContext, ComponentsContext, ApplicationProvider, SceneProvider
Represents a unique entity in the world with a list of components.
-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.prozilla.pine.common.event.EventDispatcherContext
EventDispatcherContext.EphemeralEventListener<EventType extends Enum<EventType>,E extends Event<EventType, ?>> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ApplicationComponents of this entityfinal intprotected booleanprotected final Scenefinal Transformprotected final WorldFields inherited from class dev.prozilla.pine.common.event.EventDispatcher
logger -
Constructor Summary
ConstructorsConstructorDescriptionCreates an entity at the position (0, 0)Creates an entity at the position (x, y)Creates an entity at the position (0, 0)Creates an entity at the position (x, y) -
Method Summary
Modifier and TypeMethodDescriptionAdds a child to this entity.Instantiates a prefab and adds the instance as a child of this entityvoidaddChildren(Entity... children) Adds children to this entity.<C extends Component>
CaddComponent(C component) Adds a component to this entity.voiddestroy()Destroys this entity at the end of the game loop.voidvoidbooleanChecks whether two entities are equal.getChildWithTag(String tag) Gets a child entity with a given tag.<ComponentType extends Component>
ComponentTypegetComponent(Class<ComponentType> componentClass) Returns a component of a given class or null of there isn't one.<ComponentType extends Component>
ComponentTypegetComponentInParent(Class<ComponentType> componentClass) <ComponentType extends Component>
ComponentTypegetComponentInParent(Class<ComponentType> componentClass, boolean includeAncestors) getComponents(Class<ComponentType> componentClass) Returns all components of a given class.getComponentsInChildren(Class<ComponentType> componentClass) getName()getParentWithTag(String tag) Gets a parent entity with a given tag.getScene()<ComponentType extends Component>
booleanhasComponent(Class<ComponentType> componentClass) Checks if this entity has a component of a given class.inthashCode()booleanChecks whether this entity has a given tag.protected voidinvoke(Event<EntityEventType, Entity> event) Invokes an event.booleanisActive()booleanisDescendantOf(Transform parent) booleanChecks whether this entity is registered in the entity manager.voidFormats and prints the names of this entity's parents.protected voidpropagate(Event<EntityEventType, Entity> event) Propagates the event to other objects in relation to the target object.voidvoidremoveChild(Entity child) Detaches a child from this entity without removing it from the world.voidremoveChildren(Entity... children) Detaches children from this entity without removing them from the world.voidremoveComponent(Component component) Removes a component from this entity.voidsetActive(boolean active) Toggles the active state of this entity.voidSetter for the parent entity.protected booleantoString()Returns a string representation of this object.Methods inherited from class dev.prozilla.pine.common.event.SimpleEventDispatcher
createEvent, invokeMethods inherited from class dev.prozilla.pine.common.event.EventDispatcher
addListener, invoke, removeListener, setLogger, shouldInvokeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface dev.prozilla.pine.core.ApplicationProvider
getAudioDevice, getConfig, getInput, getModManager, getRenderer, getTimer, getTracker, getWindowMethods inherited from interface dev.prozilla.pine.core.entity.EntityContext
isDescendantOfMethods inherited from interface dev.prozilla.pine.common.event.EventDispatcherContext
addListener, addTargetedListener, off, on, onceMethods inherited from interface dev.prozilla.pine.core.scene.SceneProvider
getCameraData, getWorld
-
Field Details
-
id
public final int id -
tag
-
isActive
protected boolean isActive -
transform
-
world
-
application
-
scene
-
components
Components of this entity
-
-
Constructor Details
-
Entity
Creates an entity at the position (0, 0) -
Entity
Creates an entity at the position (0, 0) -
Entity
Creates an entity at the position (x, y) -
Entity
Creates an entity at the position (x, y)
-
-
Method Details
-
destroy
public void destroy()Destroys this entity at the end of the game loop.- Specified by:
destroyin interfaceDestructible- Overrides:
destroyin classEventDispatcher<EntityEventType,Entity, Event<EntityEventType, Entity>>
-
destroyChildren
public void destroyChildren() -
destroyComponents
public void destroyComponents() -
addChild
Instantiates a prefab and adds the instance as a child of this entity- Parameters:
prefab- Prefab for the child entity- Returns:
- Child entity
- Throws:
IllegalStateExceptionIllegalArgumentException
-
addChild
Adds a child to this entity. Also adds the child to the world if this entity is inside the world.- Parameters:
child- Entity to add as a child- Returns:
- Child entity
- Throws:
IllegalStateExceptionIllegalArgumentException
-
addChildren
Adds children to this entity.- Parameters:
children- Child objects- Throws:
IllegalStateExceptionIllegalArgumentException
-
removeChild
Detaches a child from this entity without removing it from the world.- Parameters:
child- Child object- Throws:
IllegalStateExceptionIllegalArgumentException
-
removeChildren
public void removeChildren(Entity... children) throws IllegalStateException, IllegalArgumentException Detaches children from this entity without removing them from the world.- Parameters:
children- Child entities- Throws:
IllegalStateExceptionIllegalArgumentException
-
removeAllChildren
public void removeAllChildren() -
getFirstChild
- Specified by:
getFirstChildin interfaceEntityContext
-
getLastChild
- Specified by:
getLastChildin interfaceEntityContext
-
isDescendantOf
- Specified by:
isDescendantOfin interfaceEntityContext
-
getChildWithTag
Description copied from interface:EntityContextGets a child entity with a given tag.- Specified by:
getChildWithTagin interfaceEntityContext- Parameters:
tag- Tag of the child entity.- Returns:
- The child entity with the given tag, or null if there isn't one.
-
getParentWithTag
Description copied from interface:EntityContextGets a parent entity with a given tag.- Specified by:
getParentWithTagin interfaceEntityContext- Parameters:
tag- Tag of the parent entity.- Returns:
- The parent entity with the given tag, or null if there isn't one.
-
setParent
Setter for the parent entity.- Parameters:
parent- Parent entity
-
setActive
public void setActive(boolean active) Toggles the active state of this entity. -
isActive
public boolean isActive() -
addComponent
Adds a component to this entity.- Parameters:
component- Component
-
removeComponent
Removes a component from this entity.- Parameters:
component- Component
-
getComponentInParent
public <ComponentType extends Component> ComponentType getComponentInParent(Class<ComponentType> componentClass) - Specified by:
getComponentInParentin interfaceComponentsContext
-
getComponentInParent
public <ComponentType extends Component> ComponentType getComponentInParent(Class<ComponentType> componentClass, boolean includeAncestors) - Specified by:
getComponentInParentin interfaceComponentsContext
-
getComponentsInChildren
public <ComponentType extends Component> List<ComponentType> getComponentsInChildren(Class<ComponentType> componentClass) - Specified by:
getComponentsInChildrenin interfaceComponentsContext
-
hasComponent
Checks if this entity has a component of a given class.- Parameters:
componentClass- Class of the component.- Returns:
- True if this entity has a component of type
componentClass.
-
getComponent
public <ComponentType extends Component> ComponentType getComponent(Class<ComponentType> componentClass) Returns a component of a given class or null of there isn't one.- Specified by:
getComponentin interfaceComponentsContext- Parameters:
componentClass- Class of the component.- Returns:
- An instance of
componentClassthat is attached to this entity.
-
getComponents
public <ComponentType extends Component> List<ComponentType> getComponents(Class<ComponentType> componentClass) Returns all components of a given class.- Specified by:
getComponentsin interfaceComponentsContext- Parameters:
componentClass- Class of the components.- Returns:
- An ArrayList of instance of
componentClassthat are attached to this entity.
-
invoke
Description copied from class:EventDispatcherInvokes an event.- Overrides:
invokein classEventDispatcher<EntityEventType,Entity, Event<EntityEventType, Entity>> - Parameters:
event- The event to invoke
-
shouldPropagate
protected boolean shouldPropagate()- Overrides:
shouldPropagatein classEventDispatcher<EntityEventType,Entity, Event<EntityEventType, Entity>>
-
propagate
Description copied from class:EventDispatcherPropagates the event to other objects in relation to the target object. This method is called after the event has been invoked, unless the propagation was stopped.The default implementation does nothing.
- Overrides:
propagatein classEventDispatcher<EntityEventType,Entity, Event<EntityEventType, Entity>> - Parameters:
event- The event to propagate
-
getName
-
getName
-
hasTag
Checks whether this entity has a given tag. -
getApplication
- Specified by:
getApplicationin interfaceApplicationProvider
-
getLogger
- Specified by:
getLoggerin interfaceApplicationContext- Specified by:
getLoggerin interfaceApplicationProvider- Overrides:
getLoggerin classEventDispatcher<EntityEventType,Entity, Event<EntityEventType, Entity>>
-
getScene
- Specified by:
getScenein interfaceSceneProvider
-
isRegistered
public boolean isRegistered()Checks whether this entity is registered in the entity manager. -
hashCode
public int hashCode() -
equals
Checks whether two entities are equal.- Parameters:
entity- Other entity- Returns:
- True if the entities are equal
-
printHierarchy
public void printHierarchy()Formats and prints the names of this entity's parents. -
toString
Description copied from interface:PrintableReturns a string representation of this object.
-