Search in sources :

Example 61 with DataContainer

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;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer)

Example 62 with DataContainer

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;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer)

Example 63 with DataContainer

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();
}
Also used : DataView(org.spongepowered.api.data.DataView) DataContainer(org.spongepowered.api.data.DataContainer) ImmutableList(com.google.common.collect.ImmutableList)

Example 64 with DataContainer

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;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer)

Example 65 with 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;
}
Also used : DataView(org.spongepowered.api.data.DataView) DataContainer(org.spongepowered.api.data.DataContainer) ItemStack(net.minecraft.item.ItemStack)

Aggregations

DataContainer (org.spongepowered.api.data.DataContainer)110 DataView (org.spongepowered.api.data.DataView)30 DataQuery (org.spongepowered.api.data.DataQuery)28 Test (org.junit.Test)24 List (java.util.List)15 Map (java.util.Map)15 ArrayList (java.util.ArrayList)13 Nullable (javax.annotation.Nullable)11 Collection (java.util.Collection)10 ImmutableList (com.google.common.collect.ImmutableList)9 ImmutableMap (com.google.common.collect.ImmutableMap)9 IOException (java.io.IOException)9 Path (java.nio.file.Path)9 Optional (java.util.Optional)9 CatalogType (org.spongepowered.api.CatalogType)9 Sponge (org.spongepowered.api.Sponge)8 Set (java.util.Set)7 Collectors (java.util.stream.Collectors)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)7 DataSerializable (org.spongepowered.api.data.DataSerializable)7