Search in sources :

Example 36 with DataContainer

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

the class SpongeManipulatorRegistry method bake.

void bake() {
    checkState(this.tempRegistry != null);
    // ValueProcessors
    this.tempRegistry.valueProcessorMap.forEach((key, value) -> {
        ImmutableList.Builder<ValueProcessor<?, ?>> valueListBuilder = ImmutableList.builder();
        value.sort(ComparatorUtil.VALUE_PROCESSOR_COMPARATOR);
        valueListBuilder.addAll(value);
        final ValueProcessorDelegate<?, ?> delegate = new ValueProcessorDelegate(key, valueListBuilder.build());
        this.valueDelegates.put(key, delegate);
    });
    // DataProcessors
    this.tempRegistry.processorMap.forEach((key, value) -> {
        ImmutableList.Builder<DataProcessor<?, ?>> dataListBuilder = ImmutableList.builder();
        value.sort(ComparatorUtil.DATA_PROCESSOR_COMPARATOR);
        dataListBuilder.addAll(value);
        final DataProcessorDelegate<?, ?> delegate = new DataProcessorDelegate(dataListBuilder.build());
        this.dataProcessorDelegates.put(key, delegate);
    });
    SpongeDataManager manager = SpongeDataManager.getInstance();
    // DataManipulatorBuilders part 2 (Have to register them back for serialization stuff
    this.dataProcessorDelegates.forEach((key, value) -> {
        if (!Modifier.isInterface(key.getModifiers()) && !Modifier.isAbstract(key.getModifiers())) {
            DataFunction<DataContainer, DataManipulator, Optional<? extends DataManipulator<?, ?>>> function = ((DataProcessor) value)::fill;
            SpongeDataManipulatorBuilder builder = new SpongeDataManipulatorBuilder(value, key, function);
            manager.builderMap.put(key, checkNotNull(builder));
            manager.registerBuilder(key, builder);
        } else {
            final Class<? extends DataManipulator<?, ?>> clazz = this.interfaceToImplDataManipulatorClasses.get(key);
            DataFunction<DataContainer, DataManipulator, Optional<? extends DataManipulator<?, ?>>> function = ((DataProcessor) value)::fill;
            SpongeDataManipulatorBuilder builder = new SpongeDataManipulatorBuilder(value, clazz, function);
            manager.builderMap.put(key, checkNotNull(builder));
            manager.registerBuilder(key, builder);
        }
    });
    // Immutable DataProcessors
    this.tempRegistry.immutableProcessorMap.forEach((key, value) -> {
        ImmutableList.Builder<DataProcessor<?, ?>> dataListBuilder = ImmutableList.builder();
        value.sort(ComparatorUtil.DATA_PROCESSOR_COMPARATOR);
        dataListBuilder.addAll(value);
        final DataProcessorDelegate<?, ?> delegate = new DataProcessorDelegate(dataListBuilder.build());
        this.immutableDataProcessorDelegates.put(key, delegate);
    });
    // NBT processors
    ImmutableTable.Builder<Class<? extends DataManipulator<?, ?>>, NbtDataType, NbtDataProcessor<?, ?>> builder = ImmutableTable.builder();
    this.tempRegistry.nbtProcessorMap.forEach((key, value) -> {
        final HashMultimap<NbtDataType, NbtDataProcessor<?, ?>> processorMultimap = HashMultimap.create();
        for (NbtDataProcessor<?, ?> nbtDataProcessor : value) {
            processorMultimap.put(nbtDataProcessor.getTargetType(), nbtDataProcessor);
        }
        for (Map.Entry<NbtDataType, Collection<NbtDataProcessor<?, ?>>> nbtDataTypeCollectionEntry : processorMultimap.asMap().entrySet()) {
            ImmutableList.Builder<NbtDataProcessor<?, ?>> processorBuilder = ImmutableList.builder();
            processorBuilder.addAll(nbtDataTypeCollectionEntry.getValue());
            final NbtDataType dataType = nbtDataTypeCollectionEntry.getKey();
            builder.put(key, dataType, new SpongeNbtProcessorDelegate(processorBuilder.build(), dataType));
        }
    });
    this.nbtProcessorTable = builder.build();
    ImmutableSet.Builder<DataRegistration<?, ?>> registrationBuilder = ImmutableSet.builder();
    ImmutableMap.Builder<Class<? extends DataManipulator<?, ?>>, DataRegistration<?, ?>> manipulatorBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<Class<? extends ImmutableDataManipulator<?, ?>>, DataRegistration<?, ?>> immutableBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<String, DataRegistration<?, ?>> idBuilder = ImmutableMap.builder();
    ImmutableMultimap.Builder<PluginContainer, DataRegistration<?, ?>> pluginBuilder = ImmutableMultimap.builder();
    this.tempRegistry.registrations.forEach(registration -> {
        registrationBuilder.add(registration);
        manipulatorBuilder.put(registration.getManipulatorClass(), registration);
        if (!registration.getImplementationClass().equals(registration.getManipulatorClass())) {
            manipulatorBuilder.put(registration.getImplementationClass(), registration);
        }
        immutableBuilder.put(registration.getImmutableManipulatorClass(), registration);
        if (!registration.getImmutableImplementationClass().equals(registration.getImmutableManipulatorClass())) {
            immutableBuilder.put(registration.getImmutableImplementationClass(), registration);
        }
        idBuilder.put(registration.getId(), registration);
        pluginBuilder.put(registration.getPluginContainer(), registration);
    });
    this.registrations = registrationBuilder.build();
    this.manipulatorRegistrationMap = manipulatorBuilder.build();
    this.immutableRegistrationMap = immutableBuilder.build();
    this.registrationMap = idBuilder.build();
    this.pluginBasedRegistrations = pluginBuilder.build();
    final SpongeConfig<CustomDataConfig> dataConfig = SpongeImpl.getDataConfig();
    dataConfig.reload();
    dataConfig.save();
    final CustomDataRegistrationCategory config = dataConfig.getConfig().getDataRegistrationConfig();
    config.populateRegistrations(this.registrations);
    // Save the list of registered id's, this way the config can be re-understood.
    dataConfig.save();
    // Finalizes the registration by setting the temporary object to null
    this.tempRegistry = null;
}
Also used : CustomDataRegistrationCategory(org.spongepowered.common.config.category.CustomDataRegistrationCategory) ImmutableList(com.google.common.collect.ImmutableList) NbtValueProcessor(org.spongepowered.common.data.nbt.value.NbtValueProcessor) CustomDataConfig(org.spongepowered.common.config.type.CustomDataConfig) NbtDataType(org.spongepowered.common.data.nbt.NbtDataType) DataProcessorDelegate(org.spongepowered.common.data.util.DataProcessorDelegate) DataContainer(org.spongepowered.api.data.DataContainer) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) SpongeDataManipulatorBuilder(org.spongepowered.common.data.builder.manipulator.SpongeDataManipulatorBuilder) ImmutableDataManipulator(org.spongepowered.api.data.manipulator.ImmutableDataManipulator) ValueProcessorDelegate(org.spongepowered.common.data.util.ValueProcessorDelegate) PluginContainer(org.spongepowered.api.plugin.PluginContainer) Optional(java.util.Optional) ImmutableDataManipulator(org.spongepowered.api.data.manipulator.ImmutableDataManipulator) DataManipulator(org.spongepowered.api.data.manipulator.DataManipulator) NbtDataProcessor(org.spongepowered.common.data.nbt.data.NbtDataProcessor) ImmutableTable(com.google.common.collect.ImmutableTable) ImmutableMap(com.google.common.collect.ImmutableMap) DataRegistration(org.spongepowered.api.data.DataRegistration) Collection(java.util.Collection) NbtDataProcessor(org.spongepowered.common.data.nbt.data.NbtDataProcessor) SpongeNbtProcessorDelegate(org.spongepowered.common.data.nbt.SpongeNbtProcessorDelegate) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 37 with DataContainer

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

the class SpongeImmutableDataManipulatorBuilder method build.

@Override
public Optional<I> build(DataView container) throws InvalidDataException {
    final DataContainer usedContainer;
    if (container instanceof DataContainer) {
        usedContainer = (DataContainer) container;
    } else {
        usedContainer = container.copy();
    }
    Optional<T> optional = this.buildFunction.apply(usedContainer, create());
    return optional.isPresent() ? Optional.of(optional.get().asImmutable()) : Optional.empty();
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer)

Example 38 with DataContainer

use of org.spongepowered.api.data.DataContainer in project modules-extra by CubeEngine.

the class Recall method block.

public static Optional<BlockSnapshot> block(Map<String, Object> data, Map<String, Object> locationData) {
    DataContainer container = DataContainer.createNew();
    toContainer(container, locationData, Report.WORLD);
    toContainer(container, locationData, Report.X);
    toContainer(container, locationData, Report.Y);
    toContainer(container, locationData, Report.Z);
    toContainer(container, data, BLOCK_STATE);
    toContainer(container, data, BLOCK_DATA);
    toContainer(container, data, BLOCK_UNSAFE_DATA);
    return Sponge.getGame().getRegistry().createBuilder(BlockSnapshot.Builder.class).build(container);
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer)

Example 39 with DataContainer

use of org.spongepowered.api.data.DataContainer in project modules-extra by CubeEngine.

the class KitData method toContainer.

@Override
public DataContainer toContainer() {
    DataContainer container = super.toContainer();
    container.set(TIMES, this.times);
    container.set(TIME, this.time);
    return container;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer)

Example 40 with DataContainer

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

the class VoidWorldGeneratorModifier method modifyWorldGenerator.

@Override
public void modifyWorldGenerator(WorldProperties world, DataContainer settings, WorldGenerator worldGenerator) {
    worldGenerator.getGenerationPopulators().clear();
    worldGenerator.getPopulators().clear();
    for (BiomeType biome : Sponge.getRegistry().getAllOf(BiomeType.class)) {
        BiomeGenerationSettings biomeSettings = worldGenerator.getBiomeSettings(biome);
        biomeSettings.getGenerationPopulators().clear();
        biomeSettings.getPopulators().clear();
        biomeSettings.getGroundCoverLayers().clear();
    }
    worldGenerator.setBaseGenerationPopulator((world1, buffer, biomes) -> {
    });
    worldGenerator.setBiomeGenerator(buffer -> buffer.getBiomeWorker().fill((x, y, z) -> BiomeTypes.VOID));
}
Also used : WorldGenerator(org.spongepowered.api.world.gen.WorldGenerator) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Sponge(org.spongepowered.api.Sponge) DataContainer(org.spongepowered.api.data.DataContainer) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings) BiomeType(org.spongepowered.api.world.biome.BiomeType) BiomeTypes(org.spongepowered.api.world.biome.BiomeTypes) WorldGeneratorModifier(org.spongepowered.api.world.gen.WorldGeneratorModifier) BiomeType(org.spongepowered.api.world.biome.BiomeType) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings)

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