use of mekanism.api.providers.IModuleDataProvider in project Mekanism by mekanism.
the class ModuleHelper method mapSupportedModules.
private void mapSupportedModules(String imcMethod, IItemProvider moduleContainer, Map<ModuleData<?>, ImmutableSet.Builder<Item>> supportedContainersBuilderMap) {
ImmutableSet.Builder<ModuleData<?>> supportedModulesBuilder = ImmutableSet.builder();
InterModComms.getMessages(Mekanism.MODID, imcMethod::equals).forEach(message -> {
Object body = message.getMessageSupplier().get();
if (body instanceof IModuleDataProvider) {
IModuleDataProvider<?> moduleDataProvider = (IModuleDataProvider<?>) body;
supportedModulesBuilder.add(moduleDataProvider.getModuleData());
logDebugReceivedIMC(imcMethod, message.getSenderModId(), moduleDataProvider);
} else if (body instanceof IModuleDataProvider[]) {
for (IModuleDataProvider<?> moduleDataProvider : ((IModuleDataProvider<?>[]) body)) {
supportedModulesBuilder.add(moduleDataProvider.getModuleData());
logDebugReceivedIMC(imcMethod, message.getSenderModId(), moduleDataProvider);
}
} else {
Mekanism.logger.warn("Received IMC message for '{}' from mod '{}' with an invalid body.", imcMethod, message.getSenderModId());
}
});
Set<ModuleData<?>> supported = supportedModulesBuilder.build();
if (!supported.isEmpty()) {
Item item = moduleContainer.getItem();
supportedModules.put(item, supported);
for (ModuleData<?> data : supported) {
supportedContainersBuilderMap.computeIfAbsent(data, d -> ImmutableSet.builder()).add(item);
}
}
}
Aggregations