Search in sources :

Example 6 with EntityBuilder

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

Example 7 with EntityBuilder

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

Example 8 with EntityBuilder

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

Example 9 with EntityBuilder

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

Example 10 with EntityBuilder

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

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