Search in sources :

Example 11 with EntityBuilder

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());
    }
}
Also used : Vector3f(org.joml.Vector3f) Quaternionf(org.joml.Quaternionf) FloatingTextComponent(org.terasology.engine.rendering.logic.FloatingTextComponent) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent)

Example 12 with EntityBuilder

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);
    }
}
Also used : EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) ClientComponent(org.terasology.engine.network.ClientComponent)

Example 13 with EntityBuilder

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();
    }
}
Also used : EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder)

Example 14 with EntityBuilder

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;
}
Also used : EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder)

Example 15 with EntityBuilder

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());
}
Also used : NetworkComponent(org.terasology.engine.network.NetworkComponent) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) Component(org.terasology.gestalt.entitysystem.component.Component) NetworkComponent(org.terasology.engine.network.NetworkComponent) Prefab(org.terasology.engine.entitySystem.prefab.Prefab)

Aggregations

EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)29 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)12 NetworkComponent (org.terasology.engine.network.NetworkComponent)7 LocationComponent (org.terasology.engine.logic.location.LocationComponent)6 Vector3f (org.joml.Vector3f)5 Test (org.junit.jupiter.api.Test)5 Quaternionf (org.joml.Quaternionf)4 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)4 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)3 BlockComponent (org.terasology.engine.world.block.BlockComponent)2 Component (org.terasology.gestalt.entitysystem.component.Component)2 Vector3i (org.joml.Vector3i)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 StaticSound (org.terasology.engine.audio.StaticSound)1 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)1 Context (org.terasology.engine.context.Context)1 ContextImpl (org.terasology.engine.context.internal.ContextImpl)1 EntityManager (org.terasology.engine.entitySystem.entity.EntityManager)1