use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class NameTagClientSystem method createOrUpdateNameTagFor.
private void createOrUpdateNameTagFor(EntityRef entity, NameTagComponent nameTagComponent) {
EntityRef nameTag = nameTagEntityToFloatingTextMap.get(entity);
Vector3f offset = new Vector3f(0, nameTagComponent.yOffset, 0);
if (nameTag != null) {
FloatingTextComponent floatingText = nameTag.getComponent(FloatingTextComponent.class);
floatingText.text = nameTagComponent.text;
floatingText.textColor = nameTagComponent.textColor;
floatingText.scale = nameTagComponent.scale;
nameTag.saveComponent(floatingText);
LocationComponent nameTagLoc = nameTag.getComponent(LocationComponent.class);
nameTagLoc.setLocalPosition(offset);
nameTag.saveComponent(nameTagLoc);
} else {
EntityBuilder nameTagBuilder = entityManager.newBuilder();
FloatingTextComponent floatingTextComponent = new FloatingTextComponent();
nameTagBuilder.addComponent(floatingTextComponent);
LocationComponent locationComponent = new LocationComponent();
nameTagBuilder.addComponent(locationComponent);
floatingTextComponent.text = nameTagComponent.text;
floatingTextComponent.textColor = nameTagComponent.textColor;
floatingTextComponent.scale = nameTagComponent.scale;
nameTagBuilder.setOwner(entity);
nameTagBuilder.setPersistent(false);
nameTag = nameTagBuilder.build();
nameTagEntityToFloatingTextMap.put(entity, nameTag);
Location.attachChild(entity, nameTag, offset, new Quaternionf());
}
}
use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class CameraClientSystem method ensureCameraEntityCreated.
private void ensureCameraEntityCreated() {
if (!localPlayer.getCameraEntity().exists()) {
ClientComponent clientComponent = localPlayer.getClientEntity().getComponent(ClientComponent.class);
// create the camera from the prefab
EntityBuilder builder = entityManager.newBuilder("engine:camera");
builder.setPersistent(false);
clientComponent.camera = builder.build();
// Ensure that the camera isn't destroyed by the purgeWorld command.
clientComponent.camera.setScope(EntityScope.GLOBAL);
localPlayer.getClientEntity().saveComponent(clientComponent);
}
}
use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class NetworkEntitySerializer method deserialize.
public EntityRef deserialize(EntityData.PackedEntity entityData) {
EntityBuilder target;
if (entityData.hasParentPrefabUri()) {
target = entityManager.newBuilder(entityData.getParentPrefabUri());
} else {
target = entityManager.newBuilder();
}
deserializeOnto(target, entityData);
if (entityData.hasId()) {
return entityManager.createEntityWithId(entityData.getId(), target.iterateComponents());
} else {
return target.build();
}
}
use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class BlockItemFactory method createBuilder.
/**
* Create a new block item builder for the given {@link BlockFamily}.
*
* @param blockFamily block family to create the block item builder for
* @param components potential components to add to the block item entity
* @param quantity item quantity (see {@link ItemComponent#stackCount})
* @return a pre-populated entity builder for a block item entity
*/
private EntityBuilder createBuilder(BlockFamily blockFamily, ComponentContainer components, byte quantity) {
Preconditions.checkNotNull(blockFamily, "Block family must not be null when creating block item");
EntityBuilder builder = entityManager.newBuilder("engine:blockItemBase");
addComponents(builder, components);
adjustLightComponent(builder, blockFamily);
adjustDisplayNameComponent(builder, blockFamily);
adjustItemComponent(builder, blockFamily, quantity);
adjustBlockItemComponent(builder, blockFamily);
return builder;
}
use of org.terasology.engine.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.
the class BlockTypeEntityGenerator method generateBlockTypeEntity.
private void generateBlockTypeEntity(Block block) {
EntityBuilder builder = entityManager.newBuilder(blockTypePrefab);
builder.getComponent(BlockTypeComponent.class).block = block;
// TODO: Copy across settings as necessary
Optional<Prefab> prefab = block.getPrefab();
if (prefab.isPresent()) {
for (Component comp : prefab.get().iterateComponents()) {
if (!(comp instanceof NetworkComponent)) {
builder.addComponent(entityManager.getComponentLibrary().copy(comp));
}
}
}
block.setEntity(builder.build());
}
Aggregations