use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class PojoSectorManager method newBuilder.
@Override
public EntityBuilder newBuilder(Prefab prefab) {
EntityBuilder builder = newBuilder();
builder.addPrefab(prefab);
return builder;
}
use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class VisualCharacterSystem method createVisualCharacterIfNotOwnCharacter.
void createVisualCharacterIfNotOwnCharacter(EntityRef characterEntity, VisualCharacterComponent visualCharacterComponent) {
boolean isCharacterOfLocalPlayer = characterEntity.getOwner().equals(localPlayer.getClientEntity());
if (isCharacterOfLocalPlayer) {
return;
}
CreateVisualCharacterEvent event = new CreateVisualCharacterEvent(entityManager.newBuilder());
characterEntity.send(event);
EntityBuilder entityBuilder = event.getVisualCharacterBuilder();
EntityRef visualCharacterEntity = createAndAttachVisualEntityStrategy.createAndAttachVisualEntity(entityBuilder, characterEntity);
visualCharacterComponent.visualCharacter = visualCharacterEntity;
characterEntity.saveComponent(visualCharacterComponent);
}
use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class FirstPersonClientSystem method getHandEntity.
private EntityRef getHandEntity() {
if (handEntity == null) {
// create the hand entity
EntityBuilder entityBuilder = entityManager.newBuilder("engine:hand");
entityBuilder.setPersistent(false);
handEntity = entityBuilder.build();
}
return handEntity;
}
use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class PlayerFactory method findSpawnPositionFromLocationComponent.
public Vector3f findSpawnPositionFromLocationComponent(LocationComponent locationComponent) {
EntityBuilder builder = entityManager.newBuilder("engine:player");
// spawn a little bit above the ground
float extraSpace = 0.5f;
float entityHeight = getHeightOf(builder) + extraSpace;
return findSpawnPos(locationComponent.getWorldPosition(new Vector3f()), entityHeight).orElseThrow(() -> new RuntimeException("Failed to find an acceptable spawn location."));
}
use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class PlayerFactory method newInstance.
/**
* Creates a new player character entity. The desired spawning location is derived from
* the {@link LocationComponent} of the controller.
* @param controller the controlling client entity
* @return a new player character entity
*/
public EntityRef newInstance(EntityRef controller) {
EntityBuilder builder = entityManager.newBuilder("engine:player");
LocationComponent location = controller.getComponent(LocationComponent.class);
Vector3f spawnPosition = findSpawnPositionFromLocationComponent(location);
location.setWorldPosition(spawnPosition);
controller.saveComponent(location);
logger.debug("Spawing player at: {}", spawnPosition);
builder.getComponent(LocationComponent.class).setWorldPosition(spawnPosition);
builder.setOwner(controller);
CharacterComponent playerComponent = builder.getComponent(CharacterComponent.class);
playerComponent.controller = controller;
EntityRef player = builder.build();
Location.attachChild(player, controller, new Vector3f(), new Quaternionf(0, 0, 0, 1));
return player;
}
Aggregations