Search in sources :

Example 11 with NetworkComponent

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

the class PojoEntityRef method toString.

@Override
public String toString() {
    Prefab parent = getParentPrefab();
    StringBuilder builder = new StringBuilder();
    builder.append("EntityRef{id = ");
    builder.append(id);
    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.engine.network.NetworkComponent) Prefab(org.terasology.engine.entitySystem.prefab.Prefab)

Example 12 with NetworkComponent

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

Example 13 with NetworkComponent

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

the class NetworkOwnershipTest method testClientNoInitialEntityIfNotOwnedAndReplicateToOwner.

@Test
public void testClientNoInitialEntityIfNotOwnedAndReplicateToOwner() {
    connectClient();
    NetworkComponent netComp = new NetworkComponent();
    netComp.replicateMode = NetworkComponent.ReplicateMode.OWNER;
    EntityRef entity = entityManager.create(netComp);
    networkSystem.registerNetworkEntity(entity);
    assertTrue(entity.getComponent(NetworkComponent.class).getNetworkId() != 0);
    verify(client, times(0)).setNetInitial(entity.getComponent(NetworkComponent.class).getNetworkId());
}
Also used : NetworkComponent(org.terasology.engine.network.NetworkComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Test(org.junit.jupiter.api.Test)

Example 14 with NetworkComponent

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

the class NetworkOwnershipTest method testClientSentNetInitialForNewNetworkEntity.

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

Example 15 with NetworkComponent

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

Aggregations

NetworkComponent (org.terasology.engine.network.NetworkComponent)27 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)17 Test (org.junit.jupiter.api.Test)7 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)7 BlockComponent (org.terasology.engine.world.block.BlockComponent)5 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)4 Component (org.terasology.gestalt.entitysystem.component.Component)3 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)2 LocationComponent (org.terasology.engine.logic.location.LocationComponent)2 ByteString (com.google.protobuf.ByteString)1 Vector3f (org.joml.Vector3f)1 Vector3i (org.joml.Vector3i)1 Vector3ic (org.joml.Vector3ic)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)1 EngineTime (org.terasology.engine.core.EngineTime)1 ModuleManager (org.terasology.engine.core.module.ModuleManager)1 BeforeDeactivateComponent (org.terasology.engine.entitySystem.entity.lifecycleEvents.BeforeDeactivateComponent)1 BeforeEntityCreated (org.terasology.engine.entitySystem.entity.lifecycleEvents.BeforeEntityCreated)1 OnActivatedComponent (org.terasology.engine.entitySystem.entity.lifecycleEvents.OnActivatedComponent)1