Search in sources :

Example 6 with DataContainer

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

the class MixinTileEntity method toContainer.

@Override
public DataContainer toContainer() {
    final DataContainer container = DataContainer.createNew().set(Queries.CONTENT_VERSION, getContentVersion()).set(Queries.WORLD_ID, ((World) this.world).getUniqueId().toString()).set(Queries.POSITION_X, this.getPos().getX()).set(Queries.POSITION_Y, this.getPos().getY()).set(Queries.POSITION_Z, this.getPos().getZ()).set(DataQueries.BLOCK_ENTITY_TILE_TYPE, this.tileType.getId());
    final NBTTagCompound compound = new NBTTagCompound();
    this.writeToNBT(compound);
    // We must filter the custom data so it isn't stored twice
    NbtDataUtil.filterSpongeCustomData(compound);
    container.set(DataQueries.UNSAFE_NBT, NbtTranslator.getInstance().translateFrom(compound));
    final Collection<DataManipulator<?, ?>> manipulators = ((IMixinCustomDataHolder) this).getCustomManipulators();
    if (!manipulators.isEmpty()) {
        container.set(DataQueries.DATA_MANIPULATORS, DataUtil.getSerializedManipulatorList(manipulators));
    }
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) DataManipulator(org.spongepowered.api.data.manipulator.DataManipulator) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) World(org.spongepowered.api.world.World) IMixinCustomDataHolder(org.spongepowered.common.interfaces.data.IMixinCustomDataHolder)

Example 7 with DataContainer

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

the class MixinTileEntityBeacon method toContainer.

@Override
public DataContainer toContainer() {
    DataContainer container = super.toContainer();
    container.set(of("effect1"), getField(1));
    container.set(of("effect2"), getField(2));
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer)

Example 8 with DataContainer

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

the class MixinTileEntityCommandBlock method toContainer.

@Override
@SuppressWarnings("deprecated")
public DataContainer toContainer() {
    DataContainer container = super.toContainer();
    container.set(of("StoredCommand"), this.getCommandBlockLogic().getCommand());
    container.set(of("SuccessCount"), this.getCommandBlockLogic().getSuccessCount());
    container.set(of("CustomName"), this.getCommandBlockLogic().getName());
    container.set(of("DoesTrackOutput"), this.getCommandBlockLogic().shouldTrackOutput());
    if (this.getCommandBlockLogic().shouldTrackOutput()) {
    }
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer)

Example 9 with DataContainer

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

the class MixinTileEntityEnchantmentTable method toContainer.

@Override
public DataContainer toContainer() {
    DataContainer container = super.toContainer();
    container.set(of("CustomName"), this.customName);
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer)

Example 10 with DataContainer

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

the class MixinWorldSettings method onSetGeneratorOptions.

@Inject(method = "setGeneratorOptions", at = @At(value = "RETURN"))
public void onSetGeneratorOptions(String generatorOptions, CallbackInfoReturnable<WorldSettings> cir) {
    // Minecraft uses a String, we want to return a fancy DataContainer
    // Parse the world generator settings as JSON
    DataContainer settings = null;
    try {
        settings = DataFormats.JSON.read(generatorOptions);
    } catch (JsonParseException | IOException ignored) {
    }
    // If null, assume custom
    if (settings == null) {
        settings = DataContainer.createNew().set(DataQueries.WORLD_CUSTOM_SETTINGS, generatorOptions);
    }
    this.generatorSettings = settings;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException) Inject(org.spongepowered.asm.mixin.injection.Inject)

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