Commit 2bf580ed3572c4e820f511bcfaf15ca09889b71c

Authored by Mumfrey
1 parent a1377b8d

LiteLoader 1.6.2 - register mod files as resource packs

.classpath
... ... @@ -5,7 +5,8 @@
5 5 <classpathentry combineaccessrules="false" kind="src" path="/Client"/>
6 6 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
7 7 <classpathentry kind="lib" path="/Client/jars/libraries/org/lwjgl/lwjgl/lwjgl/2.9.0/lwjgl-2.9.0.jar"/>
8   - <classpathentry kind="lib" path="/Client/jars/versions/1.6.2/1.6.2.jar"/>
9 8 <classpathentry kind="lib" path="/Client/jars/libraries/com/google/code/gson/gson/2.2.2/gson-2.2.2.jar"/>
  9 + <classpathentry kind="lib" path="/Client/jars/libraries/com/google/guava/guava/14.0/guava-14.0.jar"/>
  10 + <classpathentry kind="lib" path="/Client/jars/libraries/commons-io/commons-io/2.4/commons-io-2.4.jar"/>
10 11 <classpathentry kind="output" path="bin"/>
11 12 </classpath>
... ...
java/com/mumfrey/liteloader/core/LiteLoader.java
... ... @@ -38,20 +38,7 @@ import java.util.zip.ZipInputStream;
38 38  
39 39 import javax.activity.InvalidActivityException;
40 40  
41   -import net.minecraft.src.ChatMessageComponent;
42   -import net.minecraft.src.Minecraft;
43   -import net.minecraft.src.GuiControls;
44   -import net.minecraft.src.GuiNewChat;
45   -import net.minecraft.src.GuiScreen;
46   -import net.minecraft.src.ILogAgent;
47   -import net.minecraft.src.IPlayerUsage;
48   -import net.minecraft.src.NetHandler;
49   -import net.minecraft.src.Packet1Login;
50   -import net.minecraft.src.Packet3Chat;
51   -import net.minecraft.src.PlayerUsageSnooper;
52   -import net.minecraft.src.Profiler;
53   -import net.minecraft.src.ScaledResolution;
54   -import net.minecraft.src.Timer;
  41 +import net.minecraft.src.*;
55 42  
56 43 import com.mumfrey.liteloader.ChatFilter;
57 44 import com.mumfrey.liteloader.ChatListener;
... ... @@ -68,6 +55,7 @@ import com.mumfrey.liteloader.RenderListener;
68 55 import com.mumfrey.liteloader.Tickable;
69 56 import com.mumfrey.liteloader.gui.GuiControlsPaginated;
70 57 import com.mumfrey.liteloader.permissions.PermissionsManagerClient;
  58 +import com.mumfrey.liteloader.resources.ModResourcePack;
71 59 import com.mumfrey.liteloader.util.ModUtilities;
72 60 import com.mumfrey.liteloader.util.PrivateFields;
73 61  
... ... @@ -194,6 +182,11 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
194 182 private Map<String, ModFile> modFiles = new HashMap<String, ModFile>();
195 183  
196 184 /**
  185 + * Registered resource packs
  186 + */
  187 + private Map<String, ResourcePack> registeredResourcePacks = new HashMap<String, ResourcePack>();
  188 +
  189 + /**
197 190 * List of loaded mods, for crash reporting
198 191 */
199 192 private String loadedModsList = "none";
... ... @@ -614,6 +607,46 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
614 607 }
615 608  
616 609 /**
  610 + * Register a
  611 + *
  612 + * @param name
  613 + * @param resourcePack
  614 + * @return
  615 + */
  616 + public boolean registerModResourcePack(ModResourcePack resourcePack)
  617 + {
  618 + if (!this.registeredResourcePacks.containsKey(resourcePack.func_130077_b())) // TODO adamsrc -> getName()
  619 + {
  620 + List<ResourcePack> defaultResourcePacks = PrivateFields.defaultResourcePacks.get(this.minecraft);
  621 + if (!defaultResourcePacks.contains(resourcePack))
  622 + {
  623 + defaultResourcePacks.add(resourcePack);
  624 + this.registeredResourcePacks.put(resourcePack.func_130077_b(), resourcePack); // TODO adamsrc -> getName()
  625 + return true;
  626 + }
  627 + }
  628 +
  629 + return false;
  630 + }
  631 +
  632 + /**
  633 + * @param name
  634 + * @return
  635 + */
  636 + public boolean unRegisterModResourcePack(ModResourcePack resourcePack)
  637 + {
  638 + if (this.registeredResourcePacks.containsValue(resourcePack))
  639 + {
  640 + List<ResourcePack> defaultResourcePacks = PrivateFields.defaultResourcePacks.get(this.minecraft);
  641 + this.registeredResourcePacks.remove(resourcePack.func_130077_b()); // TODO adamsrc -> getName()
  642 + defaultResourcePacks.remove(resourcePack);
  643 + return true;
  644 + }
  645 +
  646 + return false;
  647 + }
  648 +
  649 + /**
617 650 * Get the "mods" folder
618 651 */
619 652 public File getModsFolder()
... ... @@ -811,6 +844,16 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
811 844 }
812 845  
813 846 /**
  847 + * @param mod
  848 + * @return
  849 + */
  850 + private ModFile getModFile(LiteMod mod)
  851 + {
  852 + String modClassName = mod.getClass().getSimpleName();
  853 + return this.modFiles.containsKey(modClassName) ? this.modFiles.get(modClassName) : null;
  854 + }
  855 +
  856 + /**
814 857 * Enumerate the java class path and "mods" folder to find mod classes, then
815 858 * load the classes
816 859 */
... ... @@ -1135,6 +1178,8 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
1135 1178  
1136 1179 logger.info("Discovered " + this.modsToLoad.size() + " total mod(s)");
1137 1180  
  1181 + boolean addedResources = false;
  1182 +
1138 1183 for (Class<? extends LiteMod> mod : this.modsToLoad.values())
1139 1184 {
1140 1185 try
... ... @@ -1147,6 +1192,14 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
1147 1192 {
1148 1193 this.mods.add(newMod);
1149 1194 logger.info("Successfully added mod " + newMod.getName() + " version " + newMod.getVersion());
  1195 +
  1196 + // Get the mod file and register it as a resource pack if it exists
  1197 + ModFile modFile = this.getModFile(newMod);
  1198 + if (modFile != null && modFile.registerAsResourcePack(newMod.getName()))
  1199 + {
  1200 + logger.info("Adding " + modFile.getAbsolutePath() + " to resources list");
  1201 + addedResources = true;
  1202 + }
1150 1203 }
1151 1204 else
1152 1205 {
... ... @@ -1159,6 +1212,11 @@ public final class LiteLoader implements FilenameFilter, IPlayerUsage
1159 1212 th.printStackTrace();
1160 1213 }
1161 1214 }
  1215 +
  1216 + if (addedResources)
  1217 + {
  1218 + this.minecraft.func_110436_a(); // TODO adamsrc -> refreshResourcePacks
  1219 + }
1162 1220 }
1163 1221  
1164 1222 /**
... ...
java/com/mumfrey/liteloader/core/ModFile.java
... ... @@ -6,6 +6,7 @@ import java.util.Map;
6 6  
7 7 import com.google.gson.Gson;
8 8 import com.google.gson.JsonSyntaxException;
  9 +import com.mumfrey.liteloader.resources.ModResourcePack;
9 10  
10 11 /**
11 12 * Wrapper for file which represents a mod file to load with associated version information and
... ... @@ -59,6 +60,11 @@ public class ModFile extends File
59 60 private boolean hasRevision = false;
60 61  
61 62 /**
  63 + * Resource pack we have registered with minecraft
  64 + */
  65 + private ModResourcePack resourcePack = null;
  66 +
  67 + /**
62 68 * ALL of the parsed metadata from the file, associated with the mod later on for retrieval via the loader
63 69 */
64 70 private HashMap<String, String> metaData = new HashMap<String, String>();
... ... @@ -162,6 +168,23 @@ public class ModFile extends File
162 168 return this.metaData;
163 169 }
164 170  
  171 + /**
  172 + * Registers this file as a minecraft resource pack
  173 + *
  174 + * @param name
  175 + * @return true if the pack was added
  176 + */
  177 + public boolean registerAsResourcePack(String name)
  178 + {
  179 + if (this.resourcePack == null)
  180 + {
  181 + this.resourcePack = new ModResourcePack(name, this);
  182 + return LiteLoader.getInstance().registerModResourcePack(this.resourcePack);
  183 + }
  184 +
  185 + return false;
  186 + }
  187 +
165 188 @Override
166 189 public int compareTo(File other)
167 190 {
... ...
java/com/mumfrey/liteloader/resources/ModResourcePack.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.FileResourcePack;
  7 +import net.minecraft.src.MetadataSection;
  8 +import net.minecraft.src.MetadataSerializer;
  9 +
  10 +/**
  11 + * Resource pack which wraps a mod file
  12 + *
  13 + * @author Adam Mummery-Smith
  14 + */
  15 +public class ModResourcePack extends FileResourcePack
  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 ModResourcePack(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 +}
... ...
java/com/mumfrey/liteloader/util/PrivateFields.java
... ... @@ -2,9 +2,9 @@ package com.mumfrey.liteloader.util;
2 2  
3 3 import java.lang.reflect.Field;
4 4 import java.lang.reflect.Modifier;
  5 +import java.util.List;
5 6 import java.util.Map;
6 7  
7   -import net.minecraft.src.Minecraft;
8 8 import net.minecraft.src.*;
9 9  
10 10 /**
... ... @@ -141,10 +141,11 @@ public class PrivateFields&lt;P, T&gt;
141 141 public static final StaticFields<TileEntity, Map> tileEntityNameToClassMap = new StaticFields<TileEntity, Map> (TileEntity.class, "nameToClassMap", "a", "field_70326_a"); // TileEntity/nameToClassMap
142 142 }
143 143  
144   - public static final PrivateFields<Minecraft, Timer> minecraftTimer = new PrivateFields<Minecraft, Timer> (Minecraft.class, "timer", "S", "field_71428_T"); // Minecraft/timer
145   - public static final PrivateFields<Minecraft, Profiler> minecraftProfiler = new PrivateFields<Minecraft, Profiler> (Minecraft.class, "mcProfiler", "C", "field_71424_I"); // Minecraft/mcProfiler
146   - public static final PrivateFields<RenderManager, Map> entityRenderMap = new PrivateFields<RenderManager, Map> (RenderManager.class, "entityRenderMap", "q", "field_78729_o"); // RenderManager/entityRenderMap
147   - public static final PrivateFields<GuiControls, GuiScreen> guiControlsParentScreen = new PrivateFields<GuiControls, GuiScreen> (GuiControls.class, "parentScreen", "b", "field_73909_b"); // GuiControls/parentScreen
148   - public static final PrivateFields<PlayerUsageSnooper, IPlayerUsage> playerStatsCollector = new PrivateFields<PlayerUsageSnooper, IPlayerUsage>(PlayerUsageSnooper.class, "playerStatsCollector", "d", "field_76478_d"); // PlayerUsageSnooper/playerStatsCollector
  144 + public static final PrivateFields<Minecraft, Timer> minecraftTimer = new PrivateFields<Minecraft, Timer> (Minecraft.class, "timer", "S", "field_71428_T"); // Minecraft/timer
  145 + public static final PrivateFields<Minecraft, Profiler> minecraftProfiler = new PrivateFields<Minecraft, Profiler> (Minecraft.class, "mcProfiler", "C", "field_71424_I"); // Minecraft/mcProfiler
  146 + public static final PrivateFields<Minecraft, List<ResourcePack>> defaultResourcePacks = new PrivateFields<Minecraft, List<ResourcePack>> (Minecraft.class, "field_110449_ao", "aq", "field_110449_ao"); // Minecraft/field_110449_ao
  147 + public static final PrivateFields<RenderManager, Map> entityRenderMap = new PrivateFields<RenderManager, Map> (RenderManager.class, "entityRenderMap", "q", "field_78729_o"); // RenderManager/entityRenderMap
  148 + public static final PrivateFields<GuiControls, GuiScreen> guiControlsParentScreen = new PrivateFields<GuiControls, GuiScreen> (GuiControls.class, "parentScreen", "b", "field_73909_b"); // GuiControls/parentScreen
  149 + public static final PrivateFields<PlayerUsageSnooper, IPlayerUsage> playerStatsCollector = new PrivateFields<PlayerUsageSnooper, IPlayerUsage>(PlayerUsageSnooper.class, "playerStatsCollector", "d", "field_76478_d"); // PlayerUsageSnooper/playerStatsCollector
149 150 }
150 151  
... ...