Search in sources :

Example 11 with NetworkComponent

use of org.terasology.network.NetworkComponent 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 12 with NetworkComponent

use of org.terasology.network.NetworkComponent in project Terasology by MovingBlocks.

the class NetworkOwnershipTest method testClientSentNetInitialForExistingNetworkEntityOnConnect.

@Test
public void testClientSentNetInitialForExistingNetworkEntityOnConnect() {
    EntityRef entity = entityManager.create(new NetworkComponent());
    networkSystem.registerNetworkEntity(entity);
    connectClient();
    assertTrue(entity.getComponent(NetworkComponent.class).getNetworkId() != 0);
    verify(client).setNetInitial(entity.getComponent(NetworkComponent.class).getNetworkId());
}
Also used : NetworkComponent(org.terasology.network.NetworkComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Example 13 with NetworkComponent

use of org.terasology.network.NetworkComponent 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 14 with NetworkComponent

use of org.terasology.network.NetworkComponent 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 15 with NetworkComponent

use of org.terasology.network.NetworkComponent in project Terasology by MovingBlocks.

the class BaseEntityRef method toString.

@Override
public String toString() {
    Prefab parent = getParentPrefab();
    StringBuilder builder = new StringBuilder();
    builder.append("EntityRef{id = ");
    builder.append(getId());
    NetworkComponent networkComponent = getComponent(NetworkComponent.class);
    if (networkComponent != null) {
        builder.append(", netId = ");
        builder.append(networkComponent.getNetworkId());
    }
    if (parent != null) {
        builder.append(", prefab = '");
        builder.append(parent.getUrn());
        builder.append("'");
    }
    builder.append("}");
    return builder.toString();
}
Also used : NetworkComponent(org.terasology.network.NetworkComponent) Prefab(org.terasology.entitySystem.prefab.Prefab)

Aggregations

NetworkComponent (org.terasology.network.NetworkComponent)27 EntityRef (org.terasology.entitySystem.entity.EntityRef)18 Test (org.junit.Test)7 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)6 BlockComponent (org.terasology.world.block.BlockComponent)5 Component (org.terasology.entitySystem.Component)3 Prefab (org.terasology.entitySystem.prefab.Prefab)3 Vector3i (org.terasology.math.geom.Vector3i)3 Command (org.terasology.logic.console.commandSystem.annotations.Command)2 Map (java.util.Map)1 Before (org.junit.Before)1 Config (org.terasology.config.Config)1 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)1 EngineTime (org.terasology.engine.EngineTime)1 SimpleUri (org.terasology.engine.SimpleUri)1 ModuleManager (org.terasology.engine.module.ModuleManager)1 EntityManager (org.terasology.entitySystem.entity.EntityManager)1 EventLibrary (org.terasology.entitySystem.metadata.EventLibrary)1 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)1 LocationComponent (org.terasology.logic.location.LocationComponent)1