Search in sources :

Example 1 with OwnershipHelper

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

the class NetworkSystemImpl method connectToEntitySystem.

@Override
public void connectToEntitySystem(EngineEntityManager newEntityManager, EventLibrary newEventLibrary, BlockEntityRegistry blockEntityRegistry) {
    if (this.entityManager != null) {
        this.entityManager.unsubscribe(this);
    }
    this.entityManager = newEntityManager;
    this.entityManager.subscribeForChanges(this);
    this.blockManager = context.get(BlockManager.class);
    this.biomeManager = context.get(BiomeManager.class);
    this.ownershipHelper = new OwnershipHelper(newEntityManager.getComponentLibrary());
    this.storageManager = context.get(StorageManager.class);
    this.eventLibrary = newEventLibrary;
    this.componentLibrary = entityManager.getComponentLibrary();
    context.get(ComponentSystemManager.class).register(new NetworkEntitySystem(this), "engine:networkEntitySystem");
    TypeSerializationLibrary typeSerializationLibrary = new TypeSerializationLibrary(entityManager.getTypeSerializerLibrary());
    typeSerializationLibrary.add(EntityRef.class, new NetEntityRefTypeHandler(this, blockEntityRegistry));
    // TODO: Add network override types here (that use id lookup tables)
    eventSerializer = new EventSerializer(eventLibrary, typeSerializationLibrary);
    entitySerializer = new NetworkEntitySerializer(newEntityManager, entityManager.getComponentLibrary(), typeSerializationLibrary);
    entitySerializer.setComponentSerializeCheck(new NetComponentSerializeCheck());
    if (mode == NetworkMode.CLIENT) {
        entityManager.setEntityRefStrategy(new NetworkClientRefStrategy(this));
        applySerializationTables();
    }
    if (server != null) {
        server.connectToEntitySystem(newEntityManager, entitySerializer, eventSerializer, blockEntityRegistry);
    }
}
Also used : BiomeManager(org.terasology.world.biomes.BiomeManager) OwnershipHelper(org.terasology.entitySystem.entity.internal.OwnershipHelper) BlockManager(org.terasology.world.block.BlockManager) StorageManager(org.terasology.persistence.StorageManager) NetworkEntitySerializer(org.terasology.persistence.serializers.NetworkEntitySerializer) NetComponentSerializeCheck(org.terasology.network.serialization.NetComponentSerializeCheck) TypeSerializationLibrary(org.terasology.persistence.typeHandling.TypeSerializationLibrary) NetEntityRefTypeHandler(org.terasology.network.serialization.NetEntityRefTypeHandler) ComponentSystemManager(org.terasology.engine.ComponentSystemManager) EventSerializer(org.terasology.persistence.serializers.EventSerializer)

Example 2 with OwnershipHelper

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

the class OwnershipHelperTest method testListsOwnedEntities.

@Test
public void testListsOwnedEntities() {
    EntityRef ownedEntity = entityManager.create();
    OwnerComponent ownerComp = new OwnerComponent();
    ownerComp.child = ownedEntity;
    EntityRef ownerEntity = entityManager.create(ownerComp);
    OwnershipHelper helper = new OwnershipHelper(entityManager.getComponentLibrary());
    assertEqualsContent(Lists.newArrayList(ownedEntity), helper.listOwnedEntities(ownerEntity));
}
Also used : OwnerComponent(org.terasology.entitySystem.stubs.OwnerComponent) OwnershipHelper(org.terasology.entitySystem.entity.internal.OwnershipHelper) EntityRef(org.terasology.entitySystem.entity.EntityRef) Test(org.junit.Test)

Aggregations

OwnershipHelper (org.terasology.entitySystem.entity.internal.OwnershipHelper)2 Test (org.junit.Test)1 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)1 EntityRef (org.terasology.entitySystem.entity.EntityRef)1 OwnerComponent (org.terasology.entitySystem.stubs.OwnerComponent)1 NetComponentSerializeCheck (org.terasology.network.serialization.NetComponentSerializeCheck)1 NetEntityRefTypeHandler (org.terasology.network.serialization.NetEntityRefTypeHandler)1 StorageManager (org.terasology.persistence.StorageManager)1 EventSerializer (org.terasology.persistence.serializers.EventSerializer)1 NetworkEntitySerializer (org.terasology.persistence.serializers.NetworkEntitySerializer)1 TypeSerializationLibrary (org.terasology.persistence.typeHandling.TypeSerializationLibrary)1 BiomeManager (org.terasology.world.biomes.BiomeManager)1 BlockManager (org.terasology.world.block.BlockManager)1