Commit 29ceeb585a2f14eb86f673f8bafc76a08d6ac29b

Authored by Mumfrey
1 parent 2bf580ed

LiteLoader 1.6.2 - register class path entries with mods as resource packs as we…

…ll, so that mods work in Eclipse
java/com/mumfrey/liteloader/core/ClassPathMod.java 0 → 100644
  1 +package com.mumfrey.liteloader.core;
  2 +
  3 +import java.io.File;
  4 +
  5 +import com.mumfrey.liteloader.resources.ModResourcePack;
  6 +import com.mumfrey.liteloader.resources.ModResourcePackDir;
  7 +
  8 +/**
  9 + * Mod file reference for a file loaded from class path
  10 + *
  11 + * @author Adam Mummery-Smith
  12 + */
  13 +public class ClassPathMod extends ModFile
  14 +{
  15 + private static final long serialVersionUID = -4759310661966590773L;
  16 +
  17 + public ClassPathMod(File file, String name, String version)
  18 + {
  19 + super(file, "");
  20 +
  21 + this.modName = name;
  22 + this.version = version;
  23 + }
  24 +
  25 + @Override
  26 + protected void parseVersionFile(String strVersionData)
  27 + {
  28 + // Nope
  29 + }
  30 +
  31 + @Override
  32 + public boolean registerAsResourcePack(String name)
  33 + {
  34 + if (this.resourcePack == null)
  35 + {
  36 + if (this.isDirectory())
  37 + {
  38 + this.resourcePack = new ModResourcePackDir(name, this);
  39 + }
  40 + else
  41 + {
  42 + this.resourcePack = new ModResourcePack(name, this);
  43 + }
  44 +
  45 + return LiteLoader.getInstance().registerModResourcePack(this.resourcePack);
  46 + }
  47 +
  48 + return false;
  49 + }
  50 +}
... ...
java/com/mumfrey/liteloader/core/LiteLoader.java
... ... @@ -55,7 +55,6 @@ import com.mumfrey.liteloader.RenderListener;
55 55 import com.mumfrey.liteloader.Tickable;
56 56 import com.mumfrey.liteloader.gui.GuiControlsPaginated;
57 57 import com.mumfrey.liteloader.permissions.PermissionsManagerClient;
58   -import com.mumfrey.liteloader.resources.ModResourcePack;
59 58 import com.mumfrey.liteloader.util.ModUtilities;
60 59 import com.mumfrey.liteloader.util.PrivateFields;
61 60  
... ... @@ -613,7 +612,7 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
613 612 * @param resourcePack
614 613 * @return
615 614 */
616   - public boolean registerModResourcePack(ModResourcePack resourcePack)
  615 + public boolean registerModResourcePack(ResourcePack resourcePack)
617 616 {
618 617 if (!this.registeredResourcePacks.containsKey(resourcePack.func_130077_b())) // TODO adamsrc -> getName()
619 618 {
... ... @@ -633,7 +632,7 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
633 632 * @param name
634 633 * @return
635 634 */
636   - public boolean unRegisterModResourcePack(ModResourcePack resourcePack)
  635 + public boolean unRegisterModResourcePack(ResourcePack resourcePack)
637 636 {
638 637 if (this.registeredResourcePacks.containsValue(resourcePack))
639 638 {
... ... @@ -1127,6 +1126,7 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
1127 1126 }
1128 1127  
1129 1128 this.modsToLoad.put(mod.getSimpleName(), (Class<? extends LiteMod>)mod);
  1129 + this.modFiles.put(mod.getSimpleName(), new ClassPathMod(packagePath, mod.getSimpleName().substring(7), LiteLoader.getVersion()));
1130 1130 }
1131 1131  
1132 1132 if (modClasses.size() > 0)
... ...
java/com/mumfrey/liteloader/core/ModFile.java
... ... @@ -4,6 +4,8 @@ import java.io.File;
4 4 import java.util.HashMap;
5 5 import java.util.Map;
6 6  
  7 +import net.minecraft.src.ResourcePack;
  8 +
7 9 import com.google.gson.Gson;
8 10 import com.google.gson.JsonSyntaxException;
9 11 import com.mumfrey.liteloader.resources.ModResourcePack;
... ... @@ -22,52 +24,52 @@ public class ModFile extends File
22 24 /**
23 25 * Gson parser for JSON
24 26 */
25   - private static Gson gson = new Gson();
  27 + protected static Gson gson = new Gson();
26 28  
27 29 /**
28 30 * True if the metadata information is parsed successfully, the mod will be added
29 31 */
30   - private boolean valid = false;
  32 + protected boolean valid = false;
31 33  
32 34 /**
33 35 * True if parsed from JSON, false if fallback mode using legacy version.txt
34 36 */
35   - private boolean json = false;
  37 + protected boolean json = false;
36 38  
37 39 /**
38 40 * Name of the mod specified in the JSON file, this can be any string but should be the same between mod versions
39 41 */
40   - private String modName;
  42 + protected String modName;
41 43  
42 44 /**
43 45 * Loader version
44 46 */
45   - private String version;
  47 + protected String version;
46 48  
47 49 /**
48 50 * File time stamp, used as sorting criteria when no revision information is found
49 51 */
50   - private long timeStamp;
  52 + protected long timeStamp;
51 53  
52 54 /**
53 55 * Revision number from the json file
54 56 */
55   - private float revision = 0.0F;
  57 + protected float revision = 0.0F;
56 58  
57 59 /**
58 60 * True if the revision number was successfully read, used as a semaphore so that we know when revision is a valid number
59 61 */
60   - private boolean hasRevision = false;
  62 + protected boolean hasRevision = false;
61 63  
62 64 /**
63 65 * Resource pack we have registered with minecraft
64 66 */
65   - private ModResourcePack resourcePack = null;
  67 + protected ResourcePack resourcePack = null;
66 68  
67 69 /**
68 70 * ALL of the parsed metadata from the file, associated with the mod later on for retrieval via the loader
69 71 */
70   - private HashMap<String, String> metaData = new HashMap<String, String>();
  72 + protected HashMap<String, String> metaData = new HashMap<String, String>();
71 73  
72 74 /**
73 75 * @param file
... ... @@ -83,7 +85,7 @@ public class ModFile extends File
83 85 }
84 86  
85 87 @SuppressWarnings("unchecked")
86   - private void parseVersionFile(String strVersionData)
  88 + protected void parseVersionFile(String strVersionData)
87 89 {
88 90 // Assume that it's json if the file starts with a brace
89 91 if (strVersionData.trim().startsWith("{"))
... ...
java/com/mumfrey/liteloader/resources/ModResourcePackDir.java 0 → 100644
  1 +package com.mumfrey.liteloader.resources;
  2 +
  3 +import java.io.File;
  4 +import java.io.IOException;
  5 +
  6 +import net.minecraft.src.FolderResourcePack;
  7 +import net.minecraft.src.MetadataSection;
  8 +import net.minecraft.src.MetadataSerializer;
  9 +
  10 +/**
  11 + * Resource pack which wraps a mod directory on the classpath
  12 + *
  13 + * @author Adam Mummery-Smith
  14 + */
  15 +public class ModResourcePackDir extends FolderResourcePack
  16 +{
  17 + /**
  18 + * Display name, only shows up in debug output
  19 + */
  20 + private final String name;
  21 +
  22 + /**
  23 + * @param name Friendly name
  24 + * @param modFile
  25 + */
  26 + public ModResourcePackDir(String name, File modFile)
  27 + {
  28 + super(modFile);
  29 + this.name = name;
  30 + }
  31 +
  32 + /* (non-Javadoc)
  33 + * @see net.minecraft.src.AbstractResourcePack#getMetadataSection(net.minecraft.src.MetadataSerializer, java.lang.String)
  34 + */
  35 + @Override
  36 + public MetadataSection func_135058_a(MetadataSerializer metadataSerializer, String metadataSectionName) throws IOException // TODO adamsrc -> getMetadataSection
  37 + {
  38 + try
  39 + {
  40 + // This will fail when fetching pack.mcmeta if there isn't one in the mod file, since we don't care we
  41 + // just catch the exception and return null instead
  42 + return super.func_135058_a(metadataSerializer, metadataSectionName); // TODO adamsrc -> getMetadataSection
  43 + }
  44 + catch (Exception ex) {}
  45 +
  46 + return null;
  47 + }
  48 +
  49 + /* (non-Javadoc)
  50 + * @see net.minecraft.src.AbstractResourcePack#getName()
  51 + */
  52 + @Override
  53 + public String func_130077_b() // TODO adamsrc -> getName()
  54 + {
  55 + return this.name;
  56 + }
  57 +}
... ...