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