Search in sources :

Example 26 with DataContainer

use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.

the class SpongeFluidStackBuilder method from.

@Override
public FluidStack.@NonNull Builder from(final FluidStack value) {
    this.fluidType = value.fluid();
    this.volume = value.volume();
    final DataContainer container = value.toContainer();
    if (container.contains(Constants.Sponge.UNSAFE_NBT)) {
        this.extra = container.getView(Constants.Sponge.UNSAFE_NBT).get().copy();
    }
    return this;
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer)

Example 27 with DataContainer

use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.

the class SpongeFluidStackSnapshotBuilder method from.

@Override
public FluidStackSnapshot.@NonNull Builder from(@NonNull final FluidStack fluidStack) {
    this.fluidType = fluidStack.fluid();
    this.volume = fluidStack.volume();
    final DataContainer datacontainer = fluidStack.toContainer();
    this.container = null;
    if (datacontainer.contains(Constants.Sponge.UNSAFE_NBT)) {
        this.container = datacontainer.getView(Constants.Sponge.UNSAFE_NBT).get();
    }
    return this;
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer)

Example 28 with DataContainer

use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.

the class SpongeTagTemplate method toContainer.

@Override
public DataContainer toContainer() {
    final JsonObject jsonObject = this.toJson();
    try {
        final DataContainer container = DataFormats.JSON.get().read(jsonObject.getAsString());
        container.set(DataQuery.of("replace"), this.replace);
        return container;
    } catch (IOException e) {
        SpongeCommon.logger().error("Error reading json serialized by minecraft", e);
        return DataContainer.createNew();
    }
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Example 29 with DataContainer

use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.

the class SignBlockEntityMixin_API method toContainer.

// @formatter:on
@Override
public DataContainer toContainer() {
    DataContainer container = super.toContainer();
    List<String> lines = Lists.newArrayList();
    for (Component line : this.messages) {
        lines.add(Component.Serializer.toJson(line));
    }
    container.set(Constants.TileEntity.SIGN_LINES, lines);
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer) Component(net.minecraft.network.chat.Component)

Example 30 with DataContainer

use of org.spongepowered.api.data.persistence.DataContainer in project SpongeCommon by SpongePowered.

the class CommandBlockEntityMixin_API method toContainer.

@Override
public DataContainer toContainer() {
    final DataContainer container = super.toContainer();
    container.set(Constants.TileEntity.CommandBlock.STORED_COMMAND, this.shadow$getCommandBlock().getCommand());
    container.set(Constants.TileEntity.CommandBlock.SUCCESS_COUNT, this.shadow$getCommandBlock().getSuccessCount());
    container.set(Constants.TileEntity.CUSTOM_NAME, this.shadow$getCommandBlock().getName());
    container.set(Constants.TileEntity.CommandBlock.DOES_TRACK_OUTPUT, this.shadow$getCommandBlock().shouldInformAdmins());
    if (this.shadow$getCommandBlock().shouldInformAdmins()) {
        container.set(Constants.TileEntity.CommandBlock.TRACKED_OUTPUT, LegacyComponentSerializer.legacySection().serialize(SpongeAdventure.asAdventure(this.shadow$getCommandBlock().getLastOutput())));
    }
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer)

Aggregations

DataContainer (org.spongepowered.api.data.persistence.DataContainer)43 ResourceKey (org.spongepowered.api.ResourceKey)14 DataView (org.spongepowered.api.data.persistence.DataView)12 CompoundTag (net.minecraft.nbt.CompoundTag)9 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)7 DataQuery (org.spongepowered.api.data.persistence.DataQuery)7 BasicConfigurationNode (org.spongepowered.configurate.BasicConfigurationNode)7 CommentedConfigurationNode (org.spongepowered.configurate.CommentedConfigurationNode)7 ConfigurationNode (org.spongepowered.configurate.ConfigurationNode)7 Optional (java.util.Optional)6 Nullable (org.checkerframework.checker.nullness.qual.Nullable)6 Map (java.util.Map)5 NonNull (org.checkerframework.checker.nullness.qual.NonNull)5 Sponge (org.spongepowered.api.Sponge)5 DataTranslator (org.spongepowered.api.data.persistence.DataTranslator)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Collection (java.util.Collection)4 DataManager (org.spongepowered.api.data.DataManager)4