Changing up the mod list data
This commit is contained in:
parent
d45134eb9a
commit
f3b15940ee
8 changed files with 133 additions and 53 deletions
|
@ -816,26 +816,34 @@ public class FMLClientHandler implements IFMLSidedHandler
|
|||
public ModMetadata readMetadataFrom(InputStream input, ModContainer mod) throws Exception
|
||||
{
|
||||
JsonNode root=new JdomParser().func_27366_a(new InputStreamReader(input));
|
||||
List<JsonNode> lst=root.func_27217_b();
|
||||
JsonNode modinfo = null;
|
||||
for (JsonNode tmodinfo : lst) {
|
||||
if (mod.getName().equals(tmodinfo.func_27213_a("modid"))) {
|
||||
modinfo = tmodinfo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (modinfo == null) {
|
||||
FMLCommonHandler.instance().getFMLLogger().fine(String.format("Unable to process JSON modinfo file for %s", mod.getName()));
|
||||
return null;
|
||||
}
|
||||
ModMetadata meta=new ModMetadata(mod);
|
||||
try {
|
||||
meta.name=root.func_27213_a("name");
|
||||
meta.description=root.func_27213_a("description");
|
||||
meta.version=root.func_27213_a("version");
|
||||
meta.credits=root.func_27213_a("credits");
|
||||
List authors=root.func_27217_b("authors");
|
||||
meta.name=modinfo.func_27213_a("name");
|
||||
meta.description=modinfo.func_27213_a("description");
|
||||
meta.version=modinfo.func_27213_a("version");
|
||||
meta.credits=modinfo.func_27213_a("credits");
|
||||
List authors=modinfo.func_27217_b("authors");
|
||||
StringBuilder sb=new StringBuilder();
|
||||
for (int i=0; i<authors.size(); i++) {
|
||||
sb.append(((JsonNode)authors.get(i)).func_27216_b());
|
||||
if (i<authors.size()-1) {
|
||||
sb.append(", ");
|
||||
}
|
||||
meta.authorList.add(((JsonNode)authors.get(i)).func_27216_b());
|
||||
}
|
||||
meta.authorList=sb.toString();
|
||||
meta.logoFile=root.func_27213_a("logoFile");
|
||||
meta.url=root.func_27213_a("url");
|
||||
meta.updateUrl=root.func_27213_a("updateUrl");
|
||||
meta.parent=root.func_27213_a("parent");
|
||||
List screenshots=root.func_27217_b("screenshots");
|
||||
meta.logoFile=modinfo.func_27213_a("logoFile");
|
||||
meta.url=modinfo.func_27213_a("url");
|
||||
meta.updateUrl=modinfo.func_27213_a("updateUrl");
|
||||
meta.parent=modinfo.func_27213_a("parent");
|
||||
List screenshots=modinfo.func_27217_b("screenshots");
|
||||
meta.screenshots=new String[screenshots.size()];
|
||||
for (int i=0; i<screenshots.size(); i++) {
|
||||
meta.screenshots[i]=((JsonNode)screenshots.get(i)).func_27216_b();
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
package cpw.mods.fml.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import cpw.mods.fml.common.FMLModContainer;
|
||||
import cpw.mods.fml.common.FMLModLoaderContainer;
|
||||
|
@ -47,16 +49,23 @@ public class GuiModList extends GuiScreen
|
|||
public GuiModList(GuiScreen mainMenu)
|
||||
{
|
||||
this.mainMenu=mainMenu;
|
||||
this.mods=new ArrayList<ModContainer>(Loader.getModList());
|
||||
this.mods=new ArrayList<ModContainer>();
|
||||
mods.add(new FMLModLoaderContainer());
|
||||
for (ModContainer mod : Loader.getModList()) {
|
||||
if (mod.getMetadata()!=null && mod.getMetadata().parentMod != null) {
|
||||
continue;
|
||||
}
|
||||
mods.add(mod);
|
||||
}
|
||||
}
|
||||
|
||||
public void func_6448_a()
|
||||
{
|
||||
for (ModContainer mod : mods) {
|
||||
listWidth=Math.max(listWidth,getFontRenderer().func_871_a(mod.getName())+10);
|
||||
listWidth=Math.max(listWidth,getFontRenderer().func_871_a(mod.getVersion())+10);
|
||||
listWidth=Math.max(listWidth,getFontRenderer().func_871_a(mod.getName()) + 10);
|
||||
listWidth=Math.max(listWidth,getFontRenderer().func_871_a(mod.getVersion()) + 10);
|
||||
}
|
||||
listWidth=Math.min(listWidth, 150);
|
||||
StringTranslate translations = StringTranslate.func_20162_a();
|
||||
this.field_949_e.add(new GuiSmallButton(6, this.field_951_c / 2 - 75, this.field_950_d - 38, translations.func_20163_a("gui.done")));
|
||||
this.modList=new GuiSlotModList(this, mods, listWidth);
|
||||
|
@ -84,19 +93,15 @@ public class GuiModList extends GuiScreen
|
|||
if (selectedMod!=null) {
|
||||
if (selectedMod.getMetadata()!=null) {
|
||||
this.func_548_a(this.field_6451_g, selectedMod.getMetadata().name, detailCentre, 35, 0xFFFFFF);
|
||||
/* String modInfomation=String.format(
|
||||
"Version: %s\n" +
|
||||
"Credits: %s\n" +
|
||||
"Authors: %s\n" +
|
||||
"URL : %s\n" +
|
||||
"Updates: %s\n" +
|
||||
"Description:\n" +
|
||||
"%s",selectedMod.getMetadata().version,selectedMod.getMetadata().credits,selectedMod.getMetadata().authorList,selectedMod.getMetadata().url,selectedMod.getMetadata().updateUrl,selectedMod.getMetadata().description);*/
|
||||
this.func_548_a(this.field_6451_g, String.format("Version: %s", selectedMod.getMetadata().version), detailCentre, 45, 0xFFFFFF);
|
||||
this.func_548_a(this.field_6451_g, String.format("Credits: %s", selectedMod.getMetadata().credits), detailCentre, 55, 0xFFFFFF);
|
||||
this.func_548_a(this.field_6451_g, String.format("Authors: %s", selectedMod.getMetadata().authorList), detailCentre, 65, 0xFFFFFF);
|
||||
this.func_548_a(this.field_6451_g, String.format("Authors: %s", selectedMod.getMetadata().getAuthorList()), detailCentre, 65, 0xFFFFFF);
|
||||
this.func_548_a(this.field_6451_g, String.format("URL: %s", selectedMod.getMetadata().url), detailCentre, 75, 0xFFFFFF);
|
||||
this.func_548_a(this.field_6451_g, String.format("Updates: %s", selectedMod.getMetadata().updateUrl), detailCentre, 85, 0xFFFFFF);
|
||||
if (selectedMod.getMetadata().childMods.isEmpty()) {
|
||||
this.func_548_a(this.field_6451_g, "No child mods for this mod", detailCentre, 85, 0xFFFFFF);
|
||||
} else {
|
||||
this.func_548_a(this.field_6451_g, String.format("Child mods: %s", selectedMod.getMetadata().getChildModList()), detailCentre, 85, 0xFFFFFF);
|
||||
}
|
||||
this.getFontRenderer().func_27278_a(selectedMod.getMetadata().description, this.listWidth + 15, 100, this.field_951_c - this.listWidth - 30, 0xDDDDDD);
|
||||
} else {
|
||||
this.func_548_a(this.field_6451_g, selectedMod.getName(), detailCentre, 35, 0xFFFFFF);
|
||||
|
|
|
@ -11,8 +11,8 @@ import org.lwjgl.opengl.GL11;
|
|||
public abstract class GuiScrollingList
|
||||
{
|
||||
private final Minecraft client;
|
||||
private final int listWidth;
|
||||
private final int listHeight;
|
||||
protected final int listWidth;
|
||||
protected final int listHeight;
|
||||
protected final int top;
|
||||
protected final int bottom;
|
||||
private final int right;
|
||||
|
|
|
@ -36,7 +36,7 @@ public class GuiSlotModList extends GuiScrollingList
|
|||
|
||||
public GuiSlotModList(GuiModList parent, ArrayList<ModContainer> mods, int listWidth)
|
||||
{
|
||||
super(parent.getMinecraftInstance(), listWidth, parent.field_950_d, 32, parent.field_950_d - 65 + 4, 10, 25);
|
||||
super(parent.getMinecraftInstance(), listWidth, parent.field_950_d, 32, parent.field_950_d - 65 + 4, 10, 35);
|
||||
this.parent=parent;
|
||||
this.mods=mods;
|
||||
}
|
||||
|
@ -68,15 +68,16 @@ public class GuiSlotModList extends GuiScrollingList
|
|||
@Override
|
||||
protected int getContentHeight()
|
||||
{
|
||||
return (1 + this.getSize()) * 25;
|
||||
return (this.getSize()) * 35 + 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawSlot(int listIndex, int var2, int var3, int var4, Tessellator var5)
|
||||
{
|
||||
ModContainer mc=mods.get(listIndex);
|
||||
this.parent.getFontRenderer().func_873_b(mc.getName(), this.left + 3 , var3 + 2, 0xFFFFFF);
|
||||
this.parent.getFontRenderer().func_873_b(mc.getVersion(), this.left + 3 , var3 + 12, 0xCCCCCC);
|
||||
this.parent.getFontRenderer().func_873_b(this.parent.getFontRenderer().func_50107_a(mc.getName(), listWidth - 9), this.left + 3 , var3 + 2, 0xFFFFFF);
|
||||
this.parent.getFontRenderer().func_873_b(this.parent.getFontRenderer().func_50107_a(mc.getVersion(), listWidth - 9), this.left + 3 , var3 + 12, 0xCCCCCC);
|
||||
this.parent.getFontRenderer().func_873_b(this.parent.getFontRenderer().func_50107_a(mc.getMetadata() !=null ? mc.getMetadata().getChildModCountString() : "Metadata not found", listWidth - 9), this.left + 3 , var3 + 22, 0xCCCCCC);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -472,11 +472,15 @@ public class FMLCommonHandler
|
|||
InputStream input=jar.getInputStream(infoFile);
|
||||
ModMetadata data=sidedDelegate.readMetadataFrom(input, mod);
|
||||
mod.setMetadata(data);
|
||||
} else {
|
||||
getFMLLogger().fine(String.format("Failed to find mcmod.info file in %s for %s", mod.getSource().getName(), mod.getName()));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Something wrong but we don't care
|
||||
getFMLLogger().fine(String.format("Failed to find mcmod.info file in %s for %s", mod.getSource().getName(), mod.getName()));
|
||||
getFMLLogger().throwing("FMLCommonHandler", "loadMetadataFor", e);
|
||||
}
|
||||
} else {
|
||||
try
|
||||
|
@ -493,6 +497,8 @@ public class FMLCommonHandler
|
|||
catch (Exception e)
|
||||
{
|
||||
// Something wrong but we don't care
|
||||
getFMLLogger().fine(String.format("Failed to find %s.info file in %s for %s", mod.getName(), mod.getSource().getName(), mod.getName()));
|
||||
getFMLLogger().throwing("FMLCommonHandler", "loadMetadataFor", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
package cpw.mods.fml.common;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author cpw
|
||||
*
|
||||
|
@ -41,11 +43,11 @@ public class FMLModLoaderContainer extends FMLModContainer
|
|||
md.name="Forge Mod Loader";
|
||||
md.version=Loader.instance().getFMLVersionString();
|
||||
md.credits="Made possible with help from many people";
|
||||
md.authorList="cpw, LexManos";
|
||||
md.authorList=Arrays.asList("cpw, LexManos");
|
||||
md.description="The Forge Mod Loader provides the ability for systems to load mods " +
|
||||
"from the file system. It also provides key capabilities for mods to be able " +
|
||||
"to cooperate and provide a good modding environment." +
|
||||
"The mod loading system is compatible with ModLoader, all your ModLoader" +
|
||||
"to cooperate and provide a good modding environment. " +
|
||||
"The mod loading system is compatible with ModLoader, all your ModLoader " +
|
||||
"mods should work.";
|
||||
md.url="https://github.com/cpw/FML/wiki";
|
||||
md.updateUrl="https://github.com/cpw/FML/wiki";
|
||||
|
|
|
@ -34,6 +34,7 @@ import java.util.regex.Pattern;
|
|||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import cpw.mods.fml.common.ModContainer.SourceType;
|
||||
import cpw.mods.fml.common.toposort.ModSorter;
|
||||
import cpw.mods.fml.common.toposort.TopologicalSort;
|
||||
|
||||
|
@ -234,7 +235,13 @@ public class Loader
|
|||
}
|
||||
mod.nextState();
|
||||
}
|
||||
// Link up mod metadatas
|
||||
|
||||
for (ModContainer mod : mods) {
|
||||
if (mod.getMetadata()!=null) {
|
||||
mod.getMetadata().associate(namedMods);
|
||||
}
|
||||
}
|
||||
log.fine("Mod pre-initialization complete");
|
||||
}
|
||||
|
||||
|
@ -364,15 +371,15 @@ public class Loader
|
|||
File[] minecraftSources=modClassLoader.getParentSources();
|
||||
if (minecraftSources.length==1 && minecraftSources[0].isFile()) {
|
||||
log.fine(String.format("Minecraft is a file at %s, loading",minecraftSources[0].getAbsolutePath()));
|
||||
attemptFileLoad(minecraftSources[0]);
|
||||
attemptFileLoad(minecraftSources[0], SourceType.CLASSPATH);
|
||||
} else {
|
||||
for (int i=0; i<minecraftSources.length; i++) {
|
||||
if (minecraftSources[i].isFile()) {
|
||||
log.fine(String.format("Found a minecraft related file at %s, loading",minecraftSources[i].getAbsolutePath()));
|
||||
attemptFileLoad(minecraftSources[i]);
|
||||
attemptFileLoad(minecraftSources[i], SourceType.CLASSPATH);
|
||||
} else if (minecraftSources[i].isDirectory()) {
|
||||
log.fine(String.format("Found a minecraft related directory at %s, loading",minecraftSources[i].getAbsolutePath()));
|
||||
attemptDirLoad(minecraftSources[i],"");
|
||||
attemptDirLoad(minecraftSources[i],"",SourceType.CLASSPATH);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -388,7 +395,7 @@ public class Loader
|
|||
if (modFile.isDirectory())
|
||||
{
|
||||
log.fine(String.format("Found a directory %s, attempting to load it", modFile.getName()));
|
||||
boolean modFound = attemptDirLoad(modFile,"");
|
||||
boolean modFound = attemptDirLoad(modFile,"", SourceType.DIR);
|
||||
|
||||
if (modFound)
|
||||
{
|
||||
|
@ -406,7 +413,7 @@ public class Loader
|
|||
if (matcher.matches())
|
||||
{
|
||||
log.fine(String.format("Found a zip or jar file %s, attempting to load it", matcher.group(0)));
|
||||
boolean modFound = attemptFileLoad(modFile);
|
||||
boolean modFound = attemptFileLoad(modFile, SourceType.JAR);
|
||||
|
||||
if (modFound)
|
||||
{
|
||||
|
@ -429,7 +436,7 @@ public class Loader
|
|||
log.info(String.format("Forge Mod Loader has loaded %d mods", mods.size()));
|
||||
}
|
||||
|
||||
private boolean attemptDirLoad(File modDir, String path)
|
||||
private boolean attemptDirLoad(File modDir, String path, SourceType sourceType)
|
||||
{
|
||||
if (path.length()==0) {
|
||||
extendClassLoader(modDir);
|
||||
|
@ -450,7 +457,7 @@ public class Loader
|
|||
{
|
||||
if (file.isDirectory()) {
|
||||
log.finest(String.format("Recursing into package %s", path+file.getName()));
|
||||
foundAModClass|=attemptDirLoad(file,path+file.getName()+".");
|
||||
foundAModClass|=attemptDirLoad(file,path+file.getName()+".", sourceType);
|
||||
continue;
|
||||
}
|
||||
Matcher fname = modClass.matcher(file.getName());
|
||||
|
@ -459,7 +466,7 @@ public class Loader
|
|||
}
|
||||
String clazzName=path+fname.group(2);
|
||||
log.fine(String.format("Found a mod class %s in directory %s, attempting to load it", clazzName, modDir.getName()));
|
||||
loadModClass(modDir, file.getName(), clazzName);
|
||||
loadModClass(modDir, file.getName(), clazzName, sourceType);
|
||||
log.fine(String.format("Successfully loaded mod class %s", file.getName()));
|
||||
foundAModClass = true;
|
||||
}
|
||||
|
@ -467,7 +474,7 @@ public class Loader
|
|||
return foundAModClass;
|
||||
}
|
||||
|
||||
private void loadModClass(File classSource, String classFileName, String clazzName)
|
||||
private void loadModClass(File classSource, String classFileName, String clazzName, SourceType sourceType)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -477,9 +484,11 @@ public class Loader
|
|||
if (clazz.isAnnotationPresent(Mod.class))
|
||||
{
|
||||
// an FML mod
|
||||
log.fine(String.format("FML mod class %s found, loading", clazzName));
|
||||
mod = FMLModContainer.buildFor(clazz);
|
||||
log.fine(String.format("FML mod class %s loaded", clazzName));
|
||||
log.severe("Currently, the FML mod type is disabled");
|
||||
throw new LoaderException();
|
||||
// log.fine(String.format("FML mod class %s found, loading", clazzName));
|
||||
// mod = FMLModContainer.buildFor(clazz);
|
||||
// log.fine(String.format("FML mod class %s loaded", clazzName));
|
||||
}
|
||||
else if (FMLCommonHandler.instance().isModLoaderMod(clazz))
|
||||
{
|
||||
|
@ -492,6 +501,7 @@ public class Loader
|
|||
// Unrecognized
|
||||
}
|
||||
if (mod!=null) {
|
||||
mod.setSourceType(sourceType);
|
||||
FMLCommonHandler.instance().loadMetadataFor(mod);
|
||||
mods.add(mod);
|
||||
mod.nextState();
|
||||
|
@ -516,7 +526,7 @@ public class Loader
|
|||
}
|
||||
}
|
||||
|
||||
private boolean attemptFileLoad(File modFile)
|
||||
private boolean attemptFileLoad(File modFile, SourceType sourceType)
|
||||
{
|
||||
extendClassLoader(modFile);
|
||||
boolean foundAModClass = false;
|
||||
|
@ -534,7 +544,7 @@ public class Loader
|
|||
String pkg = match.group(1).replace('/', '.');
|
||||
String clazzName = pkg + match.group(2);
|
||||
log.fine(String.format("Found a mod class %s in file %s, attempting to load it", clazzName, modFile.getName()));
|
||||
loadModClass(modFile, ze.getName(), clazzName);
|
||||
loadModClass(modFile, ze.getName(), clazzName, sourceType);
|
||||
log.fine(String.format("Mod class %s loaded successfully", clazzName, modFile.getName()));
|
||||
foundAModClass = true;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,9 @@ package cpw.mods.fml.common;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import cpw.mods.fml.common.modloader.ModLoaderModContainer;
|
||||
|
@ -39,11 +41,14 @@ public class ModMetadata
|
|||
|
||||
public String logoFile="";
|
||||
public String version="";
|
||||
public String authorList="";
|
||||
public List<String> authorList=new ArrayList<String>(1);
|
||||
public String credits="";
|
||||
public String parent="";
|
||||
public String[] screenshots;
|
||||
|
||||
public ModContainer parentMod;
|
||||
public List<ModContainer> childMods = new ArrayList<ModContainer>(1);
|
||||
|
||||
/**
|
||||
* @param mod2
|
||||
* @param type2
|
||||
|
@ -53,4 +58,47 @@ public class ModMetadata
|
|||
this.mod=mod;
|
||||
this.type=(mod instanceof FMLModContainer ? ModType.FML : ModType.MODLOADER);
|
||||
}
|
||||
|
||||
public void associate(Map<String, ModContainer> mods) {
|
||||
if (parent!=null && parent.length() > 0) {
|
||||
ModContainer mc=mods.get(parent);
|
||||
if (mc!=null && mc.getMetadata()!=null) {
|
||||
mc.getMetadata().childMods.add(mod);
|
||||
parentMod = mc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getChildModCountString()
|
||||
{
|
||||
return String.format("%d child mod%s", childMods.size(), childMods.size()!=1 ? "s" : "");
|
||||
}
|
||||
|
||||
public String getAuthorList() {
|
||||
StringBuilder sb=new StringBuilder();
|
||||
for (int i=0; i<authorList.size(); i++) {
|
||||
sb.append(authorList.get(i));
|
||||
if (i<authorList.size()-1) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getChildModList()
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
for (int i=0; i<childMods.size(); i++) {
|
||||
sb.append(childMods.get(i).getMetadata().name);
|
||||
if (i<childMods.size()-1) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue