Search in sources :

Example 6 with PlayerStore

use of org.terasology.persistence.PlayerStore in project Terasology by MovingBlocks.

the class StorageManagerTest method testGetUnstoredPlayerReturnsNewStor.

@Test
public void testGetUnstoredPlayerReturnsNewStor() {
    PlayerStore store = esm.loadPlayerStore(PLAYER_ID);
    assertNotNull(store);
    assertEquals(new Vector3f(), store.getRelevanceLocation());
    assertFalse(store.hasCharacter());
    assertEquals(PLAYER_ID, store.getId());
}
Also used : PlayerStore(org.terasology.persistence.PlayerStore) Vector3f(org.terasology.math.geom.Vector3f) Test(org.junit.Test)

Example 7 with PlayerStore

use of org.terasology.persistence.PlayerStore in project Terasology by MovingBlocks.

the class PlayerSystem method onConnect.

@ReceiveEvent(components = ClientComponent.class)
public void onConnect(ConnectedEvent connected, EntityRef entity) {
    LocationComponent loc = entity.getComponent(LocationComponent.class);
    // for new clients, the player store will return default values
    PlayerStore playerStore = connected.getPlayerStore();
    Client owner = networkSystem.getOwner(entity);
    Vector3i minViewDist = ViewDistance.LEGALLY_BLIND.getChunkDistance();
    if (playerStore.hasCharacter()) {
        Vector3f storedLocation = playerStore.getRelevanceLocation();
        loc.setWorldPosition(storedLocation);
        entity.saveComponent(loc);
        if (worldProvider.isBlockRelevant(storedLocation)) {
            // chunk for spawning location is ready, so spawn right now
            playerStore.restoreEntities();
            EntityRef character = playerStore.getCharacter();
            Vector3i viewDist = owner.getViewDistance().getChunkDistance();
            addRelevanceEntity(entity, viewDist, owner);
            restoreCharacter(entity, character);
        } else {
            // otherwise wait until chunk is ready
            addRelevanceEntity(entity, minViewDist, owner);
            clientsPreparingToSpawn.add(new SpawningClientInfo(entity, storedLocation, playerStore));
        }
    } else {
        Vector3f spawnPosition = worldGenerator.getSpawnPosition(entity);
        loc.setWorldPosition(spawnPosition);
        entity.saveComponent(loc);
        addRelevanceEntity(entity, minViewDist, owner);
        if (worldProvider.isBlockRelevant(spawnPosition)) {
            spawnPlayer(entity);
        } else {
            clientsPreparingToSpawn.add(new SpawningClientInfo(entity, spawnPosition));
        }
    }
}
Also used : PlayerStore(org.terasology.persistence.PlayerStore) Vector3f(org.terasology.math.geom.Vector3f) Vector3i(org.terasology.math.geom.Vector3i) Client(org.terasology.network.Client) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 8 with PlayerStore

use of org.terasology.persistence.PlayerStore in project Terasology by MovingBlocks.

the class PlayerSystem method update.

@Override
public void update(float delta) {
    Iterator<SpawningClientInfo> i = clientsPreparingToSpawn.iterator();
    while (i.hasNext()) {
        SpawningClientInfo spawning = i.next();
        if (worldProvider.isBlockRelevant(spawning.position)) {
            PlayerStore playerStore = spawning.playerStore;
            if (playerStore == null) {
                spawnPlayer(spawning.clientEntity);
            } else {
                playerStore.restoreEntities();
                EntityRef character = playerStore.getCharacter();
                restoreCharacter(spawning.clientEntity, character);
            }
            i.remove();
        }
    }
    i = clientsPreparingToRespawn.iterator();
    while (i.hasNext()) {
        SpawningClientInfo spawning = i.next();
        if (worldProvider.isBlockRelevant(spawning.position)) {
            respawnPlayer(spawning.clientEntity);
            i.remove();
        }
    }
}
Also used : PlayerStore(org.terasology.persistence.PlayerStore) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Aggregations

PlayerStore (org.terasology.persistence.PlayerStore)8 Test (org.junit.Test)5 Vector3f (org.terasology.math.geom.Vector3f)4 EntityRef (org.terasology.entitySystem.entity.EntityRef)3 LocationComponent (org.terasology.logic.location.LocationComponent)2 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)1 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)1 EntityRefComponent (org.terasology.entitySystem.stubs.EntityRefComponent)1 Vector3i (org.terasology.math.geom.Vector3i)1 Client (org.terasology.network.Client)1 ConnectedEvent (org.terasology.network.events.ConnectedEvent)1 StorageManager (org.terasology.persistence.StorageManager)1