Search in sources :

Example 1 with EntityBuilder

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

the class VisualCharacterSystemTest method setup.

@BeforeEach
public void setup() throws Exception {
    this.system = new VisualCharacterSystem();
    Context context = new ContextImpl();
    this.localPlayer = Mockito.mock(LocalPlayer.class);
    context.put(LocalPlayer.class, localPlayer);
    Mockito.doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            return clientEntityReturnedByLocalPlayer;
        }
    }).when(localPlayer).getClientEntity();
    this.entityManager = Mockito.mock(EntityManager.class);
    Mockito.doReturn(Mockito.mock(EntityBuilder.class)).when(entityManager).newBuilder();
    context.put(EntityManager.class, this.entityManager);
    InjectionHelper.inject(system, context);
    system.setCreateAndAttachVisualEntityStrategy((entityBuilder, characterEntity) -> Mockito.mock(EntityRef.class));
}
Also used : Context(org.terasology.engine.context.Context) Answer(org.mockito.stubbing.Answer) EntityManager(org.terasology.engine.entitySystem.entity.EntityManager) LocalPlayer(org.terasology.engine.logic.players.LocalPlayer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) ContextImpl(org.terasology.engine.context.internal.ContextImpl) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with EntityBuilder

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

Example 3 with EntityBuilder

use of org.terasology.engine.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.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 4 with EntityBuilder

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

the class PojoEntityManager method createEntityWithId.

@Override
public EntityRef createEntityWithId(long id, Iterable<Component> components) {
    EntityBuilder builder = newBuilder();
    builder.setId(id);
    builder.addComponents(components);
    return builder.build();
}
Also used : EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder)

Example 5 with EntityBuilder

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

the class PojoEntityPool 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)

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