Search in sources :

Example 11 with EntityRef

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

the class EntitySerializerTest method testPrefabMaintainedOverSerialization.

@Test
public void testPrefabMaintainedOverSerialization() throws Exception {
    EntityRef entity = entityManager.create(prefab);
    EntityData.Entity entityData = entitySerializer.serialize(entity);
    long nextId = entityManager.getNextId();
    entityManager.clear();
    entityManager.setNextId(nextId);
    EntityRef newEntity = entitySerializer.deserialize(entityData);
    assertTrue(newEntity.hasComponent(EntityInfoComponent.class));
    EntityInfoComponent comp = newEntity.getComponent(EntityInfoComponent.class);
    assertEquals(prefab, comp.parentPrefab);
}
Also used : EntityData(org.terasology.protobuf.EntityData) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) EntityInfoComponent(org.terasology.engine.entitySystem.entity.internal.EntityInfoComponent) Test(org.junit.jupiter.api.Test)

Example 12 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef 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.engine.entitySystem.entity.internal.EngineEntityManager) EntityData(org.terasology.protobuf.EntityData) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) WorldSerializerImpl(org.terasology.engine.persistence.serializers.WorldSerializerImpl) WorldSerializer(org.terasology.engine.persistence.serializers.WorldSerializer) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) PrefabSerializer(org.terasology.engine.persistence.serializers.PrefabSerializer) Test(org.junit.jupiter.api.Test)

Example 13 with EntityRef

use of org.terasology.engine.entitySystem.entity.EntityRef 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.engine.network.NetworkComponent) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 14 with EntityRef

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

the class ParticleUpdaterImplTest method testEmitterRegistration.

@Test
public void testEmitterRegistration() {
    EntityRef emitterEntity = mock(EntityRef.class);
    when(emitterEntity.getComponent(ParticleEmitterComponent.class)).thenReturn(new ParticleEmitterComponent());
    particleUpdater.addEmitter(emitterEntity);
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ParticleEmitterComponent(org.terasology.engine.particles.components.ParticleEmitterComponent) Test(org.junit.jupiter.api.Test)

Example 15 with EntityRef

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

the class StorageManagerTest method createClientMock.

private Client createClientMock(String clientId, EntityRef charac) {
    EntityRef clientEntity = createClientEntity(charac);
    Client client = mock(Client.class);
    when(client.getEntity()).thenReturn(clientEntity);
    when(client.getId()).thenReturn(clientId);
    return client;
}
Also used : Client(org.terasology.engine.network.Client) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Aggregations

EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)298 Test (org.junit.jupiter.api.Test)88 ClientComponent (org.terasology.engine.network.ClientComponent)55 Vector3f (org.joml.Vector3f)51 LocationComponent (org.terasology.engine.logic.location.LocationComponent)44 Vector3i (org.joml.Vector3i)36 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)34 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)29 StringComponent (org.terasology.unittest.stubs.StringComponent)26 NetworkComponent (org.terasology.engine.network.NetworkComponent)23 EntityData (org.terasology.protobuf.EntityData)23 Quaternionf (org.joml.Quaternionf)19 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)19 Component (org.terasology.gestalt.entitysystem.component.Component)19 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)15 Map (java.util.Map)14 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)13 BlockComponent (org.terasology.engine.world.block.BlockComponent)13 Block (org.terasology.engine.world.block.Block)11 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)10