Search in sources :

Example 11 with DataContainer

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

the class SpongeEntitySnapshot method toContainer.

@Override
public DataContainer toContainer() {
    final List<DataView> dataList = DataUtil.getSerializedImmutableManipulatorList(this.manipulators);
    final DataContainer container = DataContainer.createNew().set(Queries.CONTENT_VERSION, getContentVersion()).set(Queries.WORLD_ID, this.worldUuid.toString()).set(DataQueries.ENTITY_TYPE, this.entityType.getId()).createView(DataQueries.SNAPSHOT_WORLD_POSITION).set(Queries.POSITION_X, this.position.getX()).set(Queries.POSITION_Y, this.position.getY()).set(Queries.POSITION_Z, this.position.getZ()).getContainer().createView(DataQueries.ENTITY_ROTATION).set(Queries.POSITION_X, this.rotation.getX()).set(Queries.POSITION_Y, this.rotation.getY()).set(Queries.POSITION_Z, this.rotation.getZ()).getContainer().createView(DataQueries.ENTITY_SCALE).set(Queries.POSITION_X, this.scale.getX()).set(Queries.POSITION_Y, this.scale.getY()).set(Queries.POSITION_Z, this.scale.getZ()).getContainer().set(DataQueries.DATA_MANIPULATORS, dataList);
    if (this.entityUuid != null) {
        container.set(DataQueries.ENTITY_ID, this.entityUuid.toString());
    }
    if (this.compound != null) {
        container.set(DataQueries.UNSAFE_NBT, NbtTranslator.getInstance().translateFrom(this.compound));
    }
    return container;
}
Also used : DataView(org.spongepowered.api.data.DataView) DataContainer(org.spongepowered.api.data.DataContainer)

Example 12 with DataContainer

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

the class MixinEntity method toContainer.

@Override
public DataContainer toContainer() {
    final Transform<World> transform = getTransform();
    final NBTTagCompound compound = new NBTTagCompound();
    writeToNBT(compound);
    // We must filter the custom data so it isn't stored twice
    NbtDataUtil.filterSpongeCustomData(compound);
    final DataContainer unsafeNbt = NbtTranslator.getInstance().translateFrom(compound);
    final DataContainer container = DataContainer.createNew().set(Queries.CONTENT_VERSION, getContentVersion()).set(DataQueries.ENTITY_CLASS, this.getClass().getName()).set(Queries.WORLD_ID, transform.getExtent().getUniqueId().toString()).createView(DataQueries.SNAPSHOT_WORLD_POSITION).set(Queries.POSITION_X, transform.getPosition().getX()).set(Queries.POSITION_Y, transform.getPosition().getY()).set(Queries.POSITION_Z, transform.getPosition().getZ()).getContainer().createView(DataQueries.ENTITY_ROTATION).set(Queries.POSITION_X, transform.getRotation().getX()).set(Queries.POSITION_Y, transform.getRotation().getY()).set(Queries.POSITION_Z, transform.getRotation().getZ()).getContainer().createView(DataQueries.ENTITY_SCALE).set(Queries.POSITION_X, transform.getScale().getX()).set(Queries.POSITION_Y, transform.getScale().getY()).set(Queries.POSITION_Z, transform.getScale().getZ()).getContainer().set(DataQueries.ENTITY_TYPE, this.entityType.getId()).set(DataQueries.UNSAFE_NBT, unsafeNbt);
    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 13 with DataContainer

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

the class SpongeFluidStackBuilder method from.

@Override
public FluidStack.Builder from(FluidStack value) {
    this.fluidType = value.getFluid();
    this.volume = value.getVolume();
    final DataContainer container = value.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 14 with DataContainer

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

the class MixinTileEntityFurnace method toContainer.

@Override
public DataContainer toContainer() {
    DataContainer container = super.toContainer();
    container.set(of("BurnTime"), this.getField(0));
    container.set(of("BurnTimeTotal"), this.getField(1));
    container.set(of("CookTime"), this.getField(3) - this.getField(2));
    container.set(of("CookTimeTotal"), this.getField(3));
    if (this.furnaceCustomName != null) {
        container.set(of("CustomName"), this.furnaceCustomName);
    }
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer)

Example 15 with DataContainer

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

the class MixinWorldServer method updateWorldGenerator.

@Override
public void updateWorldGenerator() {
    // Get the default generator for the world type
    DataContainer generatorSettings = this.getProperties().getGeneratorSettings();
    SpongeWorldGenerator newGenerator = createWorldGenerator(generatorSettings);
    // by the base generation populator
    if (newGenerator.getBaseGenerationPopulator() instanceof IChunkGenerator) {
        // from a mod chunk provider extending a provider that we mixed into
        if (WorldGenConstants.isValid((IChunkGenerator) newGenerator.getBaseGenerationPopulator(), IPopulatorProvider.class)) {
            ((IPopulatorProvider) newGenerator.getBaseGenerationPopulator()).addPopulators(newGenerator);
        }
    } else if (newGenerator.getBaseGenerationPopulator() instanceof IPopulatorProvider) {
        // If its not a chunk provider but is a populator provider then we call it as well
        ((IPopulatorProvider) newGenerator.getBaseGenerationPopulator()).addPopulators(newGenerator);
    }
    for (WorldGeneratorModifier modifier : this.getProperties().getGeneratorModifiers()) {
        modifier.modifyWorldGenerator(this.getProperties(), generatorSettings, newGenerator);
    }
    this.spongegen = createChunkGenerator(newGenerator);
    this.spongegen.setGenerationPopulators(newGenerator.getGenerationPopulators());
    this.spongegen.setPopulators(newGenerator.getPopulators());
    this.spongegen.setBiomeOverrides(newGenerator.getBiomeSettings());
    ChunkProviderServer chunkProviderServer = this.getChunkProvider();
    chunkProviderServer.chunkGenerator = this.spongegen;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) WorldGeneratorModifier(org.spongepowered.api.world.gen.WorldGeneratorModifier) IChunkGenerator(net.minecraft.world.gen.IChunkGenerator) IPopulatorProvider(org.spongepowered.common.interfaces.world.gen.IPopulatorProvider) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) SpongeWorldGenerator(org.spongepowered.common.world.gen.SpongeWorldGenerator)

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