Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
What is an EntityFactory
An EntityFactory is used to create and manage entities and EntityContainers. It provides methods to create, kill, import, export and move between in-tree containers. JALSE provides a default implementation - DefaultEntityFactory!
EntityFactory needed?Why is an
An EntityFactory is needed to create and maintain entity instances (since Entity is an
interface the factory will deal with its implementation). A factory can be used to maintain an entire tree (or sub-tree) as EntityContainer only moves in one direction (container -> entity -> container).
A factory can be used to create a different Entity system or just to use single entities.
newEntity(UUID, EntityContainer) and should create the entity instance with the parent as the supplied target container.
tryKillEntity(Entity) and this should be used to tell if the entity could actually be killed (immortal).
withinSameTree(EntityContainer, EntityContainer) and this should be used to tell if the two containers are within the same tree. If two containers are within the same tree a internal transfer should be tried first with
tryTakeFromTree(Entity, EntityContainer) (which may not be possible and require an import).
exportEntity(Entity) which removes all references the Entity has to its container making it ready for transfer to a entirely different tree. If an entity is alive but has no parent association
tryImportEntity can be called to try and import the entity into the tree (and all child entities).