Skip to content

Commit

Permalink
Allow more than one mod on classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
Lassebq committed Jan 11, 2025
1 parent 5add2b9 commit 547887b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public interface LaunchWrapperMod {
* Returns an Injection which should dynamically create mappings, starting from an unobfuscated entry point
* or you can return MappingSource.fromMappings(mappings) with predetermined mappings
* This method must return an instance of MappingSource with all class/method/field mappings used by mixins from getMixins()
* This instance should also be the first Injection in a list returned by {@link #getInjections()}
* @return Instance of MappingsSource
*/
@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public LaunchWrapperModFile(File modLocation) throws IOException, InvalidMixinCo
e.printStackTrace();
}
}
injections.add(0, mappingSource);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.mcphackers.launchwrapper.loader.LaunchClassLoader;
import org.mcphackers.launchwrapper.micromixin.LaunchWrapperMod;
import org.mcphackers.launchwrapper.micromixin.LaunchWrapperModFile;
import org.mcphackers.launchwrapper.micromixin.MappingSource;
import org.mcphackers.launchwrapper.micromixin.tweak.injection.micromixin.MicroMixinInjection;
import org.mcphackers.launchwrapper.micromixin.tweak.injection.micromixin.PackageAccessFixer;
import org.mcphackers.launchwrapper.target.LaunchTarget;
Expand Down Expand Up @@ -42,21 +41,19 @@ public MicroMixinTweak(LaunchConfig launch, Tweak tweak) {
public void prepare(LaunchClassLoader loader) {
File modDir = new File(config.gameDir.get(), "mods");
List<File> modFiles = new ArrayList<>();
URL url = loader.getResource("launchwrapper.mod.json");
if (url != null) {
// TODO get all mods if multiple are on classpath
File f = Util.getSource(url, "launchwrapper.mod.json");
modFiles.add(f); // Classpath mod has the highest priority
}
// Classpath mods have the highest priority
modFiles.addAll(Util.getSource(loader, "launchwrapper.mod.json"));
if (modDir.isDirectory()) {
List<File> modList = Arrays.asList(modDir.listFiles());
modList.sort(Comparator.naturalOrder());
modFiles.addAll(modList);
for (File f : modList) {
if (!f.getName().endsWith(".jar")) {
continue;
}
modFiles.add(f);
}
}
for (File f : modFiles) {
if (!f.getName().endsWith(".jar")) {
continue;
}
try {
LaunchWrapperMod mod = new LaunchWrapperModFile(f);
mods.add(mod);
Expand Down Expand Up @@ -86,10 +83,6 @@ public List<Injection> getInjections() {
List<LaunchWrapperMod> mods = getMixins();
List<Injection> injects = new ArrayList<Injection>();
for (LaunchWrapperMod mod : mods) {
MappingSource mappingSource = mod.getMappingSource();
if (mappingSource != null) {
injects.add(mappingSource);
}
injects.addAll(mod.getInjections());
}
injects.addAll(baseTweak.getInjections());
Expand Down

0 comments on commit 547887b

Please sign in to comment.