Search in sources :

Example 1 with IModuleDataProvider

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);
        }
    }
}
Also used : MekanismAPI(mekanism.api.MekanismAPI) TextUtils(mekanism.common.util.text.TextUtils) OnOff(mekanism.common.util.text.BooleanStateDisplay.OnOff) Item(net.minecraft.item.Item) ICustomModule(mekanism.api.gear.ICustomModule) CompoundNBT(net.minecraft.nbt.CompoundNBT) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) ArrayList(java.util.ArrayList) ItemDataUtils(mekanism.common.util.ItemDataUtils) ITextComponent(net.minecraft.util.text.ITextComponent) HashSet(java.util.HashSet) ItemStack(net.minecraft.item.ItemStack) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) Map(java.util.Map) MekanismItems(mekanism.common.registries.MekanismItems) InterModComms(net.minecraftforge.fml.InterModComms) Nullable(javax.annotation.Nullable) Mekanism(mekanism.common.Mekanism) IItemProvider(mekanism.api.providers.IItemProvider) ImmutableSet(com.google.common.collect.ImmutableSet) MethodsReturnNonnullByDefault(mcp.MethodsReturnNonnullByDefault) MekanismIMC(mekanism.api.MekanismIMC) IModule(mekanism.api.gear.IModule) Collection(java.util.Collection) Set(java.util.Set) ModuleData(mekanism.api.gear.ModuleData) IModuleHelper(mekanism.api.gear.IModuleHelper) ItemModule(mekanism.common.item.ItemModule) List(java.util.List) NBT(net.minecraftforge.common.util.Constants.NBT) IHUDElement(mekanism.api.gear.IHUDElement) HUDColor(mekanism.api.gear.IHUDElement.HUDColor) NBTConstants(mekanism.api.NBTConstants) ResourceLocation(net.minecraft.util.ResourceLocation) IModuleDataProvider(mekanism.api.providers.IModuleDataProvider) Collections(java.util.Collections) Item(net.minecraft.item.Item) ImmutableSet(com.google.common.collect.ImmutableSet) ModuleData(mekanism.api.gear.ModuleData) IModuleDataProvider(mekanism.api.providers.IModuleDataProvider)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)1 Object2ObjectOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)1 MethodsReturnNonnullByDefault (mcp.MethodsReturnNonnullByDefault)1 MekanismAPI (mekanism.api.MekanismAPI)1 MekanismIMC (mekanism.api.MekanismIMC)1 NBTConstants (mekanism.api.NBTConstants)1 ICustomModule (mekanism.api.gear.ICustomModule)1 IHUDElement (mekanism.api.gear.IHUDElement)1 HUDColor (mekanism.api.gear.IHUDElement.HUDColor)1 IModule (mekanism.api.gear.IModule)1 IModuleHelper (mekanism.api.gear.IModuleHelper)1