use of org.terasology.entitySystem.entity.lifecycleEvents.OnAddedComponent in project Terasology by MovingBlocks.
the class EntityBuilder method build.
/**
* Produces an entity with the components contained in this entity builder
*
* @return The built entity.
*/
public EntityRef build() {
if (id.isPresent() && !entityManager.registerId(id.get())) {
return EntityRef.NULL;
}
long finalId = id.orElse(entityManager.createEntity());
components.values().forEach(c -> entityManager.getComponentStore().put(finalId, c));
entityManager.assignToPool(finalId, pool);
EntityRef entity = entityManager.getEntity(finalId);
if (sendLifecycleEvents && entityManager.getEventSystem() != null) {
// TODO: don't send OnAddedComponent when the entity is being re-loaded from storage
entity.send(OnAddedComponent.newInstance());
entity.send(OnActivatedComponent.newInstance());
}
// Retrieve the components again in case they were modified by the previous events
for (Component component : entityManager.iterateComponents(entity.getId())) {
entityManager.notifyComponentAdded(entity, component.getClass());
}
entity.setScope(scope.orElse(getEntityInfo().scope));
return entity;
}
Aggregations