From f3b15940ee62394d907138a47df189bb37cf8379 Mon Sep 17 00:00:00 2001 From: Christian Weeks Date: Fri, 25 May 2012 15:25:35 -0400 Subject: [PATCH] Changing up the mod list data --- .../cpw/mods/fml/client/FMLClientHandler.java | 38 ++++++++------ .../cpw/mods/fml/client/GuiModList.java | 31 +++++++----- .../cpw/mods/fml/client/GuiScrollingList.java | 4 +- .../cpw/mods/fml/client/GuiSlotModList.java | 9 ++-- .../cpw/mods/fml/common/FMLCommonHandler.java | 6 +++ .../fml/common/FMLModLoaderContainer.java | 8 +-- fml/common/cpw/mods/fml/common/Loader.java | 40 +++++++++------ .../cpw/mods/fml/common/ModMetadata.java | 50 ++++++++++++++++++- 8 files changed, 133 insertions(+), 53 deletions(-) diff --git a/fml/client/cpw/mods/fml/client/FMLClientHandler.java b/fml/client/cpw/mods/fml/client/FMLClientHandler.java index 9af9cda3e..b390dd5ba 100644 --- a/fml/client/cpw/mods/fml/client/FMLClientHandler.java +++ b/fml/client/cpw/mods/fml/client/FMLClientHandler.java @@ -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 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(Loader.getModList()); + this.mods=new ArrayList(); 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); diff --git a/fml/client/cpw/mods/fml/client/GuiScrollingList.java b/fml/client/cpw/mods/fml/client/GuiScrollingList.java index 6a4f91c02..056f4be7a 100644 --- a/fml/client/cpw/mods/fml/client/GuiScrollingList.java +++ b/fml/client/cpw/mods/fml/client/GuiScrollingList.java @@ -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; diff --git a/fml/client/cpw/mods/fml/client/GuiSlotModList.java b/fml/client/cpw/mods/fml/client/GuiSlotModList.java index 6ade71c35..6e2cd1706 100644 --- a/fml/client/cpw/mods/fml/client/GuiSlotModList.java +++ b/fml/client/cpw/mods/fml/client/GuiSlotModList.java @@ -36,7 +36,7 @@ public class GuiSlotModList extends GuiScrollingList public GuiSlotModList(GuiModList parent, ArrayList 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); } } diff --git a/fml/common/cpw/mods/fml/common/FMLCommonHandler.java b/fml/common/cpw/mods/fml/common/FMLCommonHandler.java index 60449b3df..0dc45405b 100644 --- a/fml/common/cpw/mods/fml/common/FMLCommonHandler.java +++ b/fml/common/cpw/mods/fml/common/FMLCommonHandler.java @@ -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); } } } diff --git a/fml/common/cpw/mods/fml/common/FMLModLoaderContainer.java b/fml/common/cpw/mods/fml/common/FMLModLoaderContainer.java index f0fb3e55b..7cc27513a 100644 --- a/fml/common/cpw/mods/fml/common/FMLModLoaderContainer.java +++ b/fml/common/cpw/mods/fml/common/FMLModLoaderContainer.java @@ -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"; diff --git a/fml/common/cpw/mods/fml/common/Loader.java b/fml/common/cpw/mods/fml/common/Loader.java index db591a80b..77bd4c991 100644 --- a/fml/common/cpw/mods/fml/common/Loader.java +++ b/fml/common/cpw/mods/fml/common/Loader.java @@ -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 authorList=new ArrayList(1); public String credits=""; public String parent=""; public String[] screenshots; + + public ModContainer parentMod; + public List childMods = new ArrayList(1); /** * @param mod2 @@ -53,4 +58,47 @@ public class ModMetadata this.mod=mod; this.type=(mod instanceof FMLModContainer ? ModType.FML : ModType.MODLOADER); } + + public void associate(Map 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