use of org.spongepowered.api.data.DataContainer in project SpongeCommon by SpongePowered.
the class SpongeFluidStackBuilder method from.
@Override
public FluidStack.Builder from(FluidStackSnapshot fluidStackSnapshot) {
checkArgument(fluidStackSnapshot instanceof SpongeFluidStackSnapshot, "Invalid implementation found of FluidStackSnapshot!");
this.fluidType = fluidStackSnapshot.getFluid();
this.volume = fluidStackSnapshot.getVolume();
final DataContainer container = fluidStackSnapshot.toContainer();
if (container.contains(DataQueries.UNSAFE_NBT)) {
this.extra = container.getView(DataQueries.UNSAFE_NBT).get().copy();
}
return this;
}
use of org.spongepowered.api.data.DataContainer in project SpongeCommon by SpongePowered.
the class SpongeFluidStackSnapshotBuilder method from.
@Override
public FluidStackSnapshot.Builder from(FluidStack fluidStack) {
this.fluidType = fluidStack.getFluid();
this.volume = fluidStack.getVolume();
DataContainer datacontainer = fluidStack.toContainer();
this.container = null;
if (datacontainer.contains(DataQueries.UNSAFE_NBT)) {
this.container = datacontainer.getView(DataQueries.UNSAFE_NBT).get();
}
return this;
}
use of org.spongepowered.api.data.DataContainer in project SpongeCommon by SpongePowered.
the class DataUtil method getSerializedManipulatorList.
private static <T extends DataSerializable> List<DataView> getSerializedManipulatorList(Iterable<T> manipulators, Function<T, DataRegistration> func) {
checkNotNull(manipulators);
final ImmutableList.Builder<DataView> builder = ImmutableList.builder();
for (T manipulator : manipulators) {
final DataContainer container = DataContainer.createNew();
container.set(Queries.CONTENT_VERSION, DataVersions.Data.CURRENT_CUSTOM_DATA);
container.set(DataQueries.DATA_ID, func.apply(manipulator).getId()).set(DataQueries.INTERNAL_DATA, manipulator.toContainer());
builder.add(container);
}
return builder.build();
}
use of org.spongepowered.api.data.DataContainer in project SpongeCommon by SpongePowered.
the class SpongeParticleEffect method toContainer.
@Override
public DataContainer toContainer() {
DataContainer dataContainer = DataContainer.createNew();
dataContainer.set(DataQueries.PARTICLE_TYPE, this.type);
dataContainer.set(DataQueries.PARTICLE_OPTIONS, this.options.entrySet().stream().map(entry -> DataContainer.createNew().set(DataQueries.PARTICLE_OPTION_KEY, entry.getKey()).set(DataQueries.PARTICLE_OPTION_VALUE, entry.getValue())).collect(Collectors.toList()));
return dataContainer;
}
use of org.spongepowered.api.data.DataContainer in project SpongeCommon by SpongePowered.
the class MixinTileEntityLockable method toContainer.
@Override
public DataContainer toContainer() {
DataContainer container = super.toContainer();
if (this.code != null) {
container.set(DataQueries.BLOCK_ENTITY_LOCK_CODE, this.code.getLock());
}
List<DataView> items = Lists.newArrayList();
for (int i = 0; i < getSizeInventory(); i++) {
ItemStack stack = getStackInSlot(i);
if (!stack.isEmpty()) {
// todo make a helper object for this
DataContainer stackView = DataContainer.createNew().set(Queries.CONTENT_VERSION, 1).set(DataQueries.BLOCK_ENTITY_SLOT, i).set(DataQueries.BLOCK_ENTITY_SLOT_ITEM, ((org.spongepowered.api.item.inventory.ItemStack) stack).toContainer());
items.add(stackView);
}
}
container.set(DataQueries.BLOCK_ENTITY_ITEM_CONTENTS, items);
return container;
}
Aggregations