Search in sources :

Example 16 with EntityBuilder

use of org.terasology.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.entitySystem.entity.EntityBuilder)

Example 17 with EntityBuilder

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

the class NetworkOwnershipTest method testClientSendInitialForRelevantOwnedItems.

@Test
public void testClientSendInitialForRelevantOwnedItems() {
    EntityBuilder builder = entityManager.newBuilder();
    NetworkComponent netCompA = builder.addComponent(new NetworkComponent());
    netCompA.replicateMode = NetworkComponent.ReplicateMode.RELEVANT;
    builder.setOwner(clientEntity);
    EntityRef entityA = builder.build();
    networkSystem.registerNetworkEntity(entityA);
    connectClient();
    verify(client, times(1)).setNetInitial(entityA.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 18 with EntityBuilder

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

the class NetworkOwnershipTest method testClientSentInitialForOwnershipChain.

@Test
public void testClientSentInitialForOwnershipChain() {
    NetworkComponent netCompA = new NetworkComponent();
    netCompA.replicateMode = NetworkComponent.ReplicateMode.OWNER;
    EntityRef entityA = entityManager.create(netCompA);
    EntityBuilder builder = entityManager.newBuilder();
    NetworkComponent netCompB = builder.addComponent(new NetworkComponent());
    netCompB.replicateMode = NetworkComponent.ReplicateMode.OWNER;
    builder.setOwner(entityA);
    EntityRef entityB = builder.build();
    networkSystem.registerNetworkEntity(entityA);
    networkSystem.registerNetworkEntity(entityB);
    connectClient();
    verify(client, times(0)).setNetInitial(entityA.getComponent(NetworkComponent.class).getNetworkId());
    verify(client, times(0)).setNetInitial(entityB.getComponent(NetworkComponent.class).getNetworkId());
    entityA.setOwner(clientEntity);
    networkSystem.updateOwnership(entityA);
    verify(client, times(1)).setNetInitial(entityA.getComponent(NetworkComponent.class).getNetworkId());
    verify(client, times(1)).setNetInitial(entityB.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 19 with EntityBuilder

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

the class NetworkOwnershipTest method testClientSentInitialIfOwnedEntityRegistered.

@Test
public void testClientSentInitialIfOwnedEntityRegistered() {
    connectClient();
    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);
    assertTrue(entity.getComponent(NetworkComponent.class).getNetworkId() != 0);
    verify(client).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 20 with EntityBuilder

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

the class WorldSerializerTest method testNotPersistedIfFlagedOtherwise.

@Test
public void testNotPersistedIfFlagedOtherwise() throws Exception {
    EngineEntityManager entityManager = context.get(EngineEntityManager.class);
    EntityBuilder entityBuilder = entityManager.newBuilder();
    PrefabSerializer prefabSerializer = new PrefabSerializer(entityManager.getComponentLibrary(), entityManager.getTypeSerializerLibrary());
    WorldSerializer worldSerializer = new WorldSerializerImpl(entityManager, prefabSerializer);
    entityBuilder.setPersistent(false);
    // just used to express that an entity got created
    @SuppressWarnings("unused") EntityRef entity = entityBuilder.build();
    EntityData.GlobalStore worldData = worldSerializer.serializeWorld(false);
    assertEquals(0, worldData.getEntityCount());
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) EntityData(org.terasology.protobuf.EntityData) EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) WorldSerializerImpl(org.terasology.persistence.serializers.WorldSerializerImpl) WorldSerializer(org.terasology.persistence.serializers.WorldSerializer) EntityRef(org.terasology.entitySystem.entity.EntityRef) PrefabSerializer(org.terasology.persistence.serializers.PrefabSerializer) Test(org.junit.Test)

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