use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.
the class DataProviderRegistrator method registerDataStoreDelegatingProvider.
public <H extends DataHolder, K, V extends Value<K>> void registerDataStoreDelegatingProvider(final Key<V> key, final Type typeToken) {
// Create dataprovider for mutable and immutable DataContainerHolders
if (GenericTypeReflector.isSuperType(DataProviderRegistrator.MUTABLE, typeToken)) {
this.asMutable(GenericTypeReflector.erase(typeToken)).create(key).get(holder -> {
final DataContainer dataContainer = ((DataContainerHolder) holder).data$getDataContainer();
return SpongeDataManager.getDatastoreRegistry().getDataStore(key, typeToken).deserialize(dataContainer).get(key).orElse(null);
}).set((holder, v) -> {
final DataContainer dataContainer = ((DataContainerHolder) holder).data$getDataContainer();
final DataManipulator.Mutable manipulator = DataManipulator.mutableOf();
manipulator.set(key, v);
SpongeDataManager.getDatastoreRegistry().getDataStore(key, typeToken).serialize(manipulator, dataContainer);
((DataContainerHolder.Mutable) holder).data$setDataContainer(dataContainer);
});
} else if (GenericTypeReflector.isSuperType(DataProviderRegistrator.IMMUTABLE, typeToken)) {
this.asImmutable((Class<? super H>) GenericTypeReflector.erase(typeToken)).create(key).get(holder -> {
final DataContainer dataContainer = ((DataContainerHolder) holder).data$getDataContainer();
return SpongeDataManager.getDatastoreRegistry().getDataStore(key, typeToken).deserialize(dataContainer).get(key).orElse(null);
}).set((holder, v) -> {
final DataContainer dataContainer = ((DataContainerHolder) holder).data$getDataContainer();
final DataManipulator.Mutable manipulator = DataManipulator.mutableOf();
manipulator.set(key, v);
SpongeDataManager.getDatastoreRegistry().getDataStore(key, typeToken).serialize(manipulator, dataContainer);
return (H) ((DataContainerHolder.Immutable) holder).data$withDataContainer(dataContainer);
});
}
}
use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.
the class JsonDataFormat method createContainer.
private static DataContainer createContainer(JsonReader reader) throws IOException {
DataContainer container = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
JsonDataFormat.readView(reader, container);
return container;
}
use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.
the class NBTTranslator method getViewFromCompound.
private static DataContainer getViewFromCompound(CompoundTag compound) {
checkNotNull(compound);
DataContainer container = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
NBTTranslator.INSTANCE.addTo(compound, container);
return container;
}
use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.
the class SpongeFluidStack method toContainer.
@Override
@NonNull
public DataContainer toContainer() {
final ResourceKey resourceKey = Sponge.game().registry(RegistryTypes.FLUID_TYPE).valueKey(this.fluidType);
final DataContainer container = DataContainer.createNew().set(Queries.CONTENT_VERSION, this.contentVersion()).set(Constants.Fluids.FLUID_TYPE, resourceKey).set(Constants.Fluids.FLUID_VOLUME, this.volume);
if (this.extraData != null) {
container.set(Constants.Sponge.UNSAFE_NBT, this.extraData);
}
return container;
}
use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.
the class SpongeFluidStackSnapshot method toContainer.
@Override
@NonNull
public DataContainer toContainer() {
final ResourceKey resourceKey = Sponge.game().registry(RegistryTypes.FLUID_TYPE).valueKey(this.fluidType);
final DataContainer container = DataContainer.createNew().set(Queries.CONTENT_VERSION, this.contentVersion()).set(Constants.Fluids.FLUID_TYPE, resourceKey).set(Constants.Fluids.FLUID_VOLUME, this.volume);
if (this.extraData != null) {
container.set(Constants.Sponge.UNSAFE_NBT, this.extraData);
}
return container;
}
Aggregations