Search in sources :

Example 26 with EntityBuilder

use of org.terasology.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.

the class PojoEntityPool method create.

@Override
public EntityRef create(Iterable<Component> components, boolean sendLifecycleEvents) {
    EntityBuilder builder = newBuilder();
    builder.addComponents(components);
    builder.setSendLifecycleEvents(sendLifecycleEvents);
    return builder.build();
}
Also used : EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder)

Example 27 with EntityBuilder

use of org.terasology.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.

the class BehaviorNodeFactory method refreshPrefabs.

private void refreshPrefabs() {
    Collection<Prefab> prefabs = prefabManager.listPrefabs(BehaviorNodeComponent.class);
    if (prefabs.size() == 0) {
        // called from main menu
        List<String> nodes = Arrays.asList("counter", "timer", "loop", "lookup", "dynselector", "fail", "parallel", "playMusic", "playSound", "running", "selector", "setAnimation", "sequence", "succeed");
        prefabs = Lists.newArrayList();
        for (String node : nodes) {
            prefabs.add(Assets.get(new ResourceUrn("engine:" + node), Prefab.class).orElse(null));
        }
    }
    for (Prefab prefab : prefabs) {
        EntityBuilder entityBuilder = entityManager.newBuilder(prefab);
        entityBuilder.setPersistent(false);
        EntityRef entityRef = entityBuilder.build();
        BehaviorNodeComponent component = entityRef.getComponent(BehaviorNodeComponent.class);
        addToCategory(component);
        nodeComponents.add(component);
    }
}
Also used : EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) ResourceUrn(org.terasology.assets.ResourceUrn) Prefab(org.terasology.entitySystem.prefab.Prefab) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 28 with EntityBuilder

use of org.terasology.entitySystem.entity.EntityBuilder in project Terasology by MovingBlocks.

the class NetworkOwnershipTest method testClientSentInitialOnlyOnce.

@Test
public void testClientSentInitialOnlyOnce() {
    EntityBuilder builder = entityManager.newBuilder();
    NetworkComponent netComp = builder.addComponent(new NetworkComponent());
    netComp.replicateMode = NetworkComponent.ReplicateMode.OWNER;
    builder.setOwner(clientEntity);
    EntityRef entity = builder.build();
    networkSystem.registerNetworkEntity(entity);
    connectClient();
    networkSystem.updateOwnership(entity);
    verify(client, times(1)).setNetInitial(entity.getComponent(NetworkComponent.class).getNetworkId());
}
Also used : NetworkComponent(org.terasology.network.NetworkComponent) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 29 with EntityBuilder

use of org.terasology.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.entitySystem.entity.EntityBuilder) CreateVisualCharacterEvent(org.terasology.logic.characters.events.CreateVisualCharacterEvent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 30 with EntityBuilder

use of org.terasology.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 Quat4f(1, 0, 0, 0));
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) FloatingTextComponent(org.terasology.rendering.logic.FloatingTextComponent) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) EntityRef(org.terasology.entitySystem.entity.EntityRef) LocationComponent(org.terasology.logic.location.LocationComponent) Quat4f(org.terasology.math.geom.Quat4f)

Aggregations

EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)34 EntityRef (org.terasology.entitySystem.entity.EntityRef)16 LocationComponent (org.terasology.logic.location.LocationComponent)10 NetworkComponent (org.terasology.network.NetworkComponent)7 Test (org.junit.Test)5 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)5 Prefab (org.terasology.entitySystem.prefab.Prefab)5 Vector3f (org.terasology.math.geom.Vector3f)5 Vector3i (org.terasology.math.geom.Vector3i)5 Component (org.terasology.entitySystem.Component)4 DoDamageEvent (org.terasology.logic.health.DoDamageEvent)3 ItemComponent (org.terasology.logic.inventory.ItemComponent)3 Quat4f (org.terasology.math.geom.Quat4f)3 Block (org.terasology.world.block.Block)3 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)2 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)2 LightComponent (org.terasology.rendering.logic.LightComponent)2 BlockComponent (org.terasology.world.block.BlockComponent)2 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1