Search in sources :

Example 11 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project MinecraftForge by MinecraftForge.

the class FMLNetworkHandler method enhanceStatusQuery.

public static void enhanceStatusQuery(JsonObject jsonobject) {
    JsonObject fmlData = new JsonObject();
    fmlData.addProperty("type", "FML");
    JsonArray modList = new JsonArray();
    for (ModContainer mc : Loader.instance().getActiveModList()) {
        JsonObject modData = new JsonObject();
        modData.addProperty("modid", mc.getModId());
        modData.addProperty("version", mc.getVersion());
        modList.add(modData);
    }
    fmlData.add("modList", modList);
    jsonobject.add("modinfo", fmlData);
}
Also used : JsonArray(com.google.gson.JsonArray) ModContainer(net.minecraftforge.fml.common.ModContainer) JsonObject(com.google.gson.JsonObject)

Example 12 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project MinecraftForge by MinecraftForge.

the class DirectoryDiscoverer method exploreFileSystem.

public void exploreFileSystem(String path, File modDir, List<ModContainer> harvestedMods, ModCandidate candidate, @Nullable MetadataCollection mc) {
    if (path.length() == 0) {
        File metadata = new File(modDir, "mcmod.info");
        try {
            FileInputStream fis = new FileInputStream(metadata);
            try {
                mc = MetadataCollection.from(fis, modDir.getName());
            } finally {
                IOUtils.closeQuietly(fis);
            }
            FMLLog.fine("Found an mcmod.info file in directory %s", modDir.getName());
        } catch (Exception e) {
            mc = MetadataCollection.from(null, "");
            FMLLog.fine("No mcmod.info file found in directory %s", modDir.getName());
        }
    }
    File[] content = modDir.listFiles(new ClassFilter());
    // Always sort our content
    Arrays.sort(content);
    for (File file : content) {
        if (file.isDirectory()) {
            FMLLog.finer("Recursing into package %s", path + file.getName());
            exploreFileSystem(path + file.getName() + "/", file, harvestedMods, candidate, mc);
            continue;
        }
        Matcher match = classFile.matcher(file.getName());
        if (match.matches()) {
            ASMModParser modParser = null;
            FileInputStream fis = null;
            try {
                fis = new FileInputStream(file);
                modParser = new ASMModParser(fis);
                candidate.addClassEntry(path + file.getName());
            } catch (LoaderException e) {
                FMLLog.log(Level.ERROR, e, "There was a problem reading the file %s - probably this is a corrupt file", file.getPath());
                throw e;
            } catch (Exception e) {
                throw Throwables.propagate(e);
            } finally {
                IOUtils.closeQuietly(fis);
            }
            modParser.validate();
            modParser.sendToTable(table, candidate);
            ModContainer container = ModContainerFactory.instance().build(modParser, candidate.getModContainer(), candidate);
            if (container != null) {
                harvestedMods.add(container);
                container.bindMetadata(mc);
            }
        }
    }
}
Also used : LoaderException(net.minecraftforge.fml.common.LoaderException) ModContainer(net.minecraftforge.fml.common.ModContainer) Matcher(java.util.regex.Matcher) ASMModParser(net.minecraftforge.fml.common.discovery.asm.ASMModParser) File(java.io.File) FileInputStream(java.io.FileInputStream) LoaderException(net.minecraftforge.fml.common.LoaderException)

Example 13 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project MinecraftForge by MinecraftForge.

the class FMLInterModComms method enqueueMessage.

private static void enqueueMessage(Object sourceMod, String modTarget, IMCMessage message) {
    ModContainer mc;
    if (sourceMod instanceof ModContainer) {
        mc = (ModContainer) sourceMod;
    } else {
        mc = FMLCommonHandler.instance().findContainerFor(sourceMod);
    }
    if (mc != null && Loader.isModLoaded(modTarget)) {
        message.setSender(mc);
        modMessages.put(modTarget, message);
    }
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer)

Example 14 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project RFToolsDimensions by McJty.

the class RFToolsTools method findModID.

public static String findModID(Object obj) {
    if (modSourceID == null) {
        modSourceID = new HashMap<>();
        for (ModContainer mod : Loader.instance().getModList()) {
            modSourceID.put(mod.getSource().getName(), mod.getModId());
        }
        modSourceID.put("1.8.0.jar", "minecraft");
        modSourceID.put("1.8.8.jar", "minecraft");
        modSourceID.put("1.8.9.jar", "minecraft");
        modSourceID.put("Forge", "minecraft");
    }
    String path;
    try {
        if (obj instanceof Class) {
            path = ((Class) obj).getProtectionDomain().getCodeSource().getLocation().toString();
        } else {
            path = obj.getClass().getProtectionDomain().getCodeSource().getLocation().toString();
        }
    } catch (Exception e) {
        return "<Unknown>";
    }
    try {
        path = URLDecoder.decode(path, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        return "<Unknown>";
    }
    String modName = "<Unknown>";
    for (String s : modSourceID.keySet()) {
        if (path.contains(s)) {
            modName = modSourceID.get(s);
            break;
        }
    }
    if (modName.equals("Minecraft Coder Pack")) {
        modName = "minecraft";
    } else if (modName.equals("Forge")) {
        modName = "minecraft";
    }
    return modName;
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) UnsupportedEncodingException(java.io.UnsupportedEncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 15 with ModContainer

use of net.minecraftforge.fml.common.ModContainer in project Railcraft by Railcraft.

the class MappingRegistry method getMissingMappingFromFML.

private Object getMissingMappingFromFML(boolean isBlock, String name, int i) {
    ResourceLocation location = new ResourceLocation(name);
    String modName = name.split(":")[0];
    if (Loader.isModLoaded(modName)) {
        try {
            FMLMissingMappingsEvent.MissingMapping mapping = new FMLMissingMappingsEvent.MissingMapping(isBlock ? GameRegistry.Type.BLOCK : GameRegistry.Type.ITEM, location, i);
            ListMultimap<String, FMLMissingMappingsEvent.MissingMapping> missingMapping = ArrayListMultimap.create();
            missingMapping.put(modName, mapping);
            FMLMissingMappingsEvent event = new FMLMissingMappingsEvent(missingMapping);
            for (ModContainer container : Loader.instance().getModList()) {
                if (container instanceof FMLModContainer) {
                    event.applyModContainer(container);
                    ((FMLModContainer) container).handleModStateEvent(event);
                    if (mapping.getAction() != FMLMissingMappingsEvent.Action.DEFAULT) {
                        break;
                    }
                }
            }
            if (mapping.getAction() == FMLMissingMappingsEvent.Action.REMAP) {
                return mapping.getTarget();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : FMLModContainer(net.minecraftforge.fml.common.FMLModContainer) FMLModContainer(net.minecraftforge.fml.common.FMLModContainer) ModContainer(net.minecraftforge.fml.common.ModContainer) ResourceLocation(net.minecraft.util.ResourceLocation) FMLMissingMappingsEvent(net.minecraftforge.fml.common.event.FMLMissingMappingsEvent)

Aggregations

ModContainer (net.minecraftforge.fml.common.ModContainer)34 ResourceLocation (net.minecraft.util.ResourceLocation)4 DummyModContainer (net.minecraftforge.fml.common.DummyModContainer)4 LoaderException (net.minecraftforge.fml.common.LoaderException)4 Nullable (javax.annotation.Nullable)3 ForgeModContainer (net.minecraftforge.common.ForgeModContainer)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 JsonObject (com.google.gson.JsonObject)2 File (java.io.File)2 InputStream (java.io.InputStream)2 List (java.util.List)2 Map (java.util.Map)2 BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)1 SetMultimap (com.google.common.collect.SetMultimap)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 RCConfig (ivorius.reccomplex.RCConfig)1