Search in sources :

Example 6 with PersistedDataArray

use of org.terasology.persistence.typeHandling.PersistedDataArray in project Terasology by MovingBlocks.

the class EntityRefTypeHandler method deserializeCollection.

@Override
public List<EntityRef> deserializeCollection(PersistedData data, DeserializationContext context) {
    PersistedDataArray array = data.getAsArray();
    List<EntityRef> result = Lists.newArrayListWithCapacity(array.size());
    addEntitiesFromLongArray(result, array);
    return result;
}
Also used : PersistedDataArray(org.terasology.persistence.typeHandling.PersistedDataArray) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 7 with PersistedDataArray

use of org.terasology.persistence.typeHandling.PersistedDataArray in project Terasology by MovingBlocks.

the class NetEntityRefTypeHandler method deserialize.

@Override
public EntityRef deserialize(PersistedData data, DeserializationContext context) {
    if (data.isArray()) {
        PersistedDataArray array = data.getAsArray();
        if (array.isNumberArray() && array.size() == 3) {
            TIntList items = data.getAsArray().getAsIntegerArray();
            Vector3i pos = new Vector3i(items.get(0), items.get(1), items.get(2));
            return blockEntityRegistry.getBlockEntityAt(pos);
        }
    }
    if (data.isNumber()) {
        return networkSystem.getEntity(data.getAsInteger());
    }
    return EntityRef.NULL;
}
Also used : PersistedDataArray(org.terasology.persistence.typeHandling.PersistedDataArray) Vector3i(org.terasology.math.geom.Vector3i) TIntList(gnu.trove.list.TIntList)

Example 8 with PersistedDataArray

use of org.terasology.persistence.typeHandling.PersistedDataArray in project Terasology by MovingBlocks.

the class EnumTypeHandler method deserializeCollection.

@Override
public List<T> deserializeCollection(PersistedData data, DeserializationContext context) {
    if (data.isArray()) {
        PersistedDataArray array = data.getAsArray();
        List<T> result = Lists.newArrayListWithCapacity(array.size());
        for (PersistedData item : array) {
            result.add(deserialize(item, context));
        }
        return result;
    }
    return Lists.newArrayList();
}
Also used : PersistedDataArray(org.terasology.persistence.typeHandling.PersistedDataArray) PersistedData(org.terasology.persistence.typeHandling.PersistedData)

Aggregations

PersistedDataArray (org.terasology.persistence.typeHandling.PersistedDataArray)8 PersistedData (org.terasology.persistence.typeHandling.PersistedData)6 TIntList (gnu.trove.list.TIntList)1 EntityRef (org.terasology.entitySystem.entity.EntityRef)1 Vector3i (org.terasology.math.geom.Vector3i)1