use of org.lanternpowered.server.data.io.store.ObjectStore in project LanternServer by LanternPowered.
the class EntitySerializer method serialize.
@Override
public DataView serialize(LanternEntity object) {
final DataView dataView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
dataView.set(ID, object.getType().getId());
// noinspection unchecked
final ObjectStore<LanternEntity> store = (ObjectStore) ObjectStoreRegistry.get().get(object.getClass()).get();
store.serialize(object, dataView);
if (store instanceof IdentifiableObjectStore) {
((IdentifiableObjectStore) store).serializeUniqueId(dataView, object.getUniqueId());
}
return dataView;
}
use of org.lanternpowered.server.data.io.store.ObjectStore in project LanternServer by LanternPowered.
the class TileEntitySerializer method serialize.
@Override
public DataView serialize(LanternTileEntity object) {
final DataView dataView = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
dataView.set(ID, object.getType().getId());
// noinspection unchecked
final ObjectStore<LanternTileEntity> store = (ObjectStore) ObjectStoreRegistry.get().get(object.getClass()).get();
store.serialize(object, dataView);
return dataView;
}
use of org.lanternpowered.server.data.io.store.ObjectStore in project LanternServer by LanternPowered.
the class TileEntitySerializer method deserialize.
@Override
public LanternTileEntity deserialize(DataView dataView) throws InvalidDataException {
final String id = fixTileId(dataView, dataView.getString(ID).get());
dataView.remove(ID);
final LanternTileEntityType tileEntityType = (LanternTileEntityType) Sponge.getRegistry().getType(TileEntityType.class, id).orElseThrow(() -> new InvalidDataException("Unknown tile entity id: " + id));
// noinspection unchecked
final ObjectStore<LanternTileEntity> store = (ObjectStore) ObjectStoreRegistry.get().get(tileEntityType.getTileEntityType()).get();
// noinspection unchecked
final LanternTileEntity entity = (LanternTileEntity) tileEntityType.getTileEntityConstructor().get();
store.deserialize(entity, dataView);
return entity;
}
use of org.lanternpowered.server.data.io.store.ObjectStore in project LanternServer by LanternPowered.
the class EntitySerializer method deserialize.
@Override
public LanternEntity deserialize(DataView dataView) throws InvalidDataException {
String id0 = dataView.getString(ID).get();
final String id;
// Fast fail if the data isn't old
if (dataView.getInt(DATA_VERSION).orElse(0) < 704) {
id = fixEntityId(dataView, id0);
} else {
id = id0;
}
dataView.remove(ID);
final LanternEntityType entityType = (LanternEntityType) Sponge.getRegistry().getType(EntityType.class, id).orElseThrow(() -> new InvalidDataException("Unknown entity id: " + id));
// noinspection unchecked
final ObjectStore<LanternEntity> store = (ObjectStore) ObjectStoreRegistry.get().get(entityType.getEntityClass()).get();
final UUID uniqueId;
if (store instanceof IdentifiableObjectStore) {
uniqueId = ((IdentifiableObjectStore) store).deserializeUniqueId(dataView);
} else {
uniqueId = UUID.randomUUID();
}
// noinspection unchecked
final LanternEntity entity = (LanternEntity) entityType.getEntityConstructor().apply(uniqueId);
store.deserialize(entity, dataView);
return entity;
}
Aggregations