2222 */
2323package com .falsepattern .lib .mixin ;
2424
25+ import com .falsepattern .lib .DeprecationDetails ;
2526import com .falsepattern .lib .StableAPI ;
2627import com .falsepattern .lib .util .FileUtil ;
2728import lombok .val ;
4041import java .nio .file .Paths ;
4142import java .util .ArrayList ;
4243import java .util .Arrays ;
44+ import java .util .Collections ;
45+ import java .util .HashSet ;
4346import java .util .List ;
4447import java .util .Set ;
4548import java .util .function .Predicate ;
@@ -57,6 +60,8 @@ static Logger createLogger(String modName) {
5760 return LogManager .getLogger (modName + " Mixin Loader" );
5861 }
5962
63+ @ Deprecated
64+ @ DeprecationDetails (deprecatedSince = "1.4.0" )
6065 @ StableAPI .Expose
6166 static File findJarOf (final ITargetedMod mod ) {
6267 File result = null ;
@@ -83,6 +88,32 @@ static File findJarOf(final ITargetedMod mod) {
8388 return result ;
8489 }
8590
91+ @ StableAPI .Expose (since = "1.4.0" )
92+ static Set <File > findJarsOf (IMixinPlugin self , final ITargetedMod mod ) {
93+ if (!self .useNewFindJar ()) {
94+ val jar = findJarOf (mod );
95+ return jar == null ? Collections .emptySet () : Set .of (jar );
96+ }
97+ val results = new HashSet <File >();
98+ try (val stream = walk (MODS_DIRECTORY_PATH )) {
99+ results .addAll (stream .filter (mod ::isMatchingJar ).map (Path ::toFile ).toList ());
100+ } catch (Exception e ) {
101+ e .printStackTrace ();
102+ }
103+ for (URL url : Launch .classLoader .getURLs ()) {
104+ try {
105+ String file = url .getFile ();
106+ Path path = Paths .get (file );
107+ if (mod .isMatchingJar (path )) {
108+ results .add (path .toFile ());
109+ break ;
110+ }
111+ } catch (Exception ignored ) {
112+ }
113+ }
114+ return results ;
115+ }
116+
86117 @ StableAPI .Expose
87118 Logger getLogger ();
88119
@@ -92,6 +123,11 @@ static File findJarOf(final ITargetedMod mod) {
92123 @ StableAPI .Expose
93124 ITargetedMod [] getTargetedModEnumValues ();
94125
126+ @ StableAPI .Expose (since = "1.4.0" )
127+ default boolean useNewFindJar () {
128+ return false ;
129+ }
130+
95131 @ Override
96132 @ StableAPI .Expose (since = "__INTERNAL__" )
97133 default void onLoad (String mixinPackage ) {
@@ -126,8 +162,9 @@ default List<String> getMixins() {
126162 .filter (new Predicate <ITargetedMod >() {
127163 @ Override
128164 public boolean test (ITargetedMod mod ) {
165+ boolean loadJar = IMixinPlugin .this .loadJarOf (mod );
129166 return (mod .isLoadInDevelopment () && isDevelopmentEnvironment )
130- || IMixinPlugin . this . loadJarOf ( mod ) ;
167+ || loadJar ;
131168 }
132169 })
133170 .collect (Collectors .toList ());
@@ -153,24 +190,24 @@ public boolean test(ITargetedMod mod) {
153190
154191 @ StableAPI .Expose (since = "__INTERNAL__" )
155192 default boolean loadJarOf (final ITargetedMod mod ) {
156- boolean success = false ;
157193 try {
158- File jar = findJarOf ( mod );
159- if (jar == null ) {
160- getLogger ().info ("Jar not found for " + mod );
194+ val jars = findJarsOf ( this , mod );
195+ if (jars . isEmpty () ) {
196+ getLogger ().info ("Jar not found for {}" , mod );
161197 return false ;
162198 }
163- getLogger ().info ("Attempting to add " + jar + " to the URL Class Path" );
164- success = true ;
165- if (!jar .exists ()) {
166- success = false ;
167- throw new FileNotFoundException (jar .toString ());
199+ for (val jar : jars ) {
200+ getLogger ().info ("Attempting to add {} to the URL Class Path" , jar );
201+ try {
202+ MinecraftURLClassPath .addJar (jar );
203+ } catch (Throwable e ) {
204+ e .printStackTrace ();
205+ }
168206 }
169- MinecraftURLClassPath .addJar (jar );
170207 } catch (Throwable e ) {
171208 e .printStackTrace ();
172209 }
173- return success ;
210+ return true ;
174211 }
175212
176213 @ StableAPI .Expose (since = "__INTERNAL__" )
0 commit comments