Search in sources :

Example 11 with DataContainer

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

the class SpongeBlockEntityArchetypeBuilder method blockEntityData.

@Override
public BlockEntityArchetype.Builder blockEntityData(final DataView dataView) {
    final DataContainer copy = Objects.requireNonNull(dataView, "DataView cannot be null!").copy();
    this.data = copy;
    return this;
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer)

Example 12 with DataContainer

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

the class SchematicTranslator method translate.

@Override
public DataContainer translate(final Schematic schematic) throws InvalidDataException {
    final DataContainer data = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED);
    final DataView view = data.createView(Constants.Sponge.Schematic.SCHEMATIC);
    this.addTo(schematic, view);
    return data;
}
Also used : DataView(org.spongepowered.api.data.persistence.DataView) DataContainer(org.spongepowered.api.data.persistence.DataContainer)

Example 13 with DataContainer

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

the class SpongeEntitySnapshot method toContainer.

@Override
public DataContainer toContainer() {
    final DataContainer unsafeNbt = NBTTranslator.INSTANCE.translateFrom(this.compound == null ? new CompoundTag() : this.compound);
    final DataContainer container = DataContainer.createNew(DataView.SafetyMode.NO_DATA_CLONED).set(Queries.CONTENT_VERSION, this.contentVersion()).set(Queries.WORLD_KEY, this.worldKey.formatted()).createView(Constants.Sponge.SNAPSHOT_WORLD_POSITION).set(Queries.POSITION_X, this.position.x()).set(Queries.POSITION_Y, this.position.y()).set(Queries.POSITION_Z, this.position.z()).container().createView(Constants.Entity.ROTATION).set(Queries.POSITION_X, this.rotation.x()).set(Queries.POSITION_Y, this.rotation.y()).set(Queries.POSITION_Z, this.rotation.z()).container().createView(Constants.Entity.SCALE).set(Queries.POSITION_X, this.scale.x()).set(Queries.POSITION_Y, this.scale.y()).set(Queries.POSITION_Z, this.scale.z()).container().set(Constants.Entity.TYPE, net.minecraft.world.entity.EntityType.getKey((net.minecraft.world.entity.EntityType<?>) this.entityType)).set(Constants.Sponge.UNSAFE_NBT, unsafeNbt);
    if (this.uniqueId != null) {
        container.set(Constants.Entity.UUID, this.uniqueId.toString());
    }
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 14 with DataContainer

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

the class SpongeEntityArchetypeBuilder method entityData.

@Override
public EntityArchetype.Builder entityData(final DataView view) {
    final DataContainer container = Objects.requireNonNull(view, "Provided DataView cannot be null!").copy();
    new DelegateDataValidator(SpongeEntityArchetype.VALIDATORS, ValidationTypes.ENTITY.get()).validate(container);
    this.compound = NBTTranslator.INSTANCE.translate(container);
    SpongeEntityArchetypeBuilder.stripCompound(this.compound);
    return this;
}
Also used : DelegateDataValidator(org.spongepowered.common.data.nbt.validation.DelegateDataValidator) DataContainer(org.spongepowered.api.data.persistence.DataContainer)

Example 15 with DataContainer

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

the class SpongeGameProfile method toContainer.

@Override
@NonNull
public DataContainer toContainer() {
    final DataContainer container = DataContainer.createNew().set(Queries.CONTENT_VERSION, this.contentVersion()).set(Constants.Profile.UUID, this.uniqueId().toString());
    if (this.name != null) {
        container.set(Constants.Profile.NAME, this.name);
    }
    if (!this.properties.isEmpty()) {
        final List<DataContainer> entries = new ArrayList<>(this.properties.size());
        for (final ProfileProperty property : this.properties) {
            entries.add(property.toContainer());
        }
        container.set(Constants.Profile.PROPERTIES, entries);
    }
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.persistence.DataContainer) ProfileProperty(org.spongepowered.api.profile.property.ProfileProperty) ArrayList(java.util.ArrayList) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

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