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;
}
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();
}
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);
}
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;
}
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));
}
Aggregations