Skip to content

Commit 6bdb1ac

Browse files
committed
rewrite load customize libraries
1 parent d6d225e commit 6bdb1ac

3 files changed

Lines changed: 31 additions & 26 deletions

File tree

settings.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
rootProject.name = 'Cleanroom'
1+
rootProject.name = 'CatRoomEF'
22

33
include ':mcp'
44
include ':minecraft'
@@ -7,4 +7,3 @@ include ':cleanroom'
77
project(":mcp").projectDir = file("projects/mcp")
88
project(":minecraft").projectDir = file("projects/minecraft")
99
project(":cleanroom").projectDir = file("projects/cleanroom")
10-

src/main/java/catserver/server/remapper/target/CatClassLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public final Class<?> defineClassRemap(String name, byte[] b, int off, int len,
5656
}
5757

5858
private Class<?> remappedFindClass(String name, byte[] stream, ProtectionDomain protectionDomain) throws ClassFormatError {
59-
Class<?> result = null;
59+
Class<?> result;
6060

6161
try {
6262
byte[] bytecode = remapper.remapClassFile(stream, RuntimeRepo.getInstance());

src/main/java/net/minecraftforge/fml/common/ModClassLoader.java

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,52 +44,59 @@ public class ModClassLoader extends URLClassLoader
4444
{
4545
private static final List<String> STANDARD_LIBRARIES = ImmutableList.of("jinput.jar", "lwjgl.jar", "lwjgl_util.jar", "rt.jar");
4646
private LaunchClassLoader mainClassLoader;
47-
private List<File> sources;
47+
private final List<File> sources;
48+
private List<URL> parentURLs = null;
4849

4950
public ModClassLoader(ClassLoader parent) {
5051
super(new URL[0], null);
5152
this.sources = Lists.newArrayList();
5253

5354
if (parent instanceof LaunchClassLoader) {
5455
this.mainClassLoader = (LaunchClassLoader)parent;
55-
File customLibFolder = new File("./libraries/customize_libraries");
56+
57+
File customLibFolder = new File("./customize_libraries");
5658
if (!customLibFolder.exists()) customLibFolder.mkdir();
59+
this.loadCustomizeLibraries(customLibFolder);
60+
}
61+
}
5762

58-
if (customLibFolder.isDirectory()) {
59-
File[] files = customLibFolder.listFiles();
60-
if (files != null) {
61-
for (File file : files) {
62-
if (file.isFile() && file.getName().endsWith(".jar")) {
63-
try {
64-
this.addFile(file);
65-
FMLLog.log.info("Loaded custom library {}", file.getName());
66-
} catch (MalformedURLException e) {
67-
FMLLog.log.error("Unable to add custom mod file {} to the mod classloader", file.getAbsolutePath(), e);
68-
}
69-
}
70-
}
63+
private void loadCustomizeLibraries(File file) {
64+
if (file.isDirectory()) {
65+
File[] files = file.listFiles();
66+
if (files != null) {
67+
for (File f : files) {
68+
this.loadCustomizeLibraries(f);
69+
}
70+
}
71+
} else {
72+
if (file.isFile() && file.getName().endsWith(".jar")) {
73+
try {
74+
this.addFile(file);
75+
FMLLog.log.info("Loaded custom library {}", file.getName());
76+
} catch (MalformedURLException e) {
77+
FMLLog.log.error("Unable to add custom lib file {} to the mod classloader", file.getAbsolutePath(), e);
7178
}
7279
}
7380
}
7481
}
7582

7683
public void addFile(File modFile) throws MalformedURLException
7784
{
78-
mainClassLoader.addURL(modFile.getAbsoluteFile().toURI().toURL());
85+
this.mainClassLoader.addURL(modFile.getAbsoluteFile().toURI().toURL());
7986
this.sources.add(modFile);
8087
}
8188

8289
@Override
8390
public Class<?> loadClass(String name) throws ClassNotFoundException
8491
{
85-
return mainClassLoader.loadClass(name);
92+
return this.mainClassLoader.loadClass(name);
8693
}
8794

8895
public File[] getParentSources() {
8996
try
9097
{
9198
List<File> files=new ArrayList<File>();
92-
for(URL url : mainClassLoader.getSources())
99+
for(URL url : this.mainClassLoader.getSources())
93100
{
94101
URI uri = url.toURI();
95102
if(uri.getScheme().equals("file"))
@@ -178,7 +185,7 @@ public boolean isDefaultLibrary(File file)
178185

179186
public void clearNegativeCacheFor(Set<String> classList)
180187
{
181-
mainClassLoader.clearNegativeEntries(classList);
188+
this.mainClassLoader.clearNegativeEntries(classList);
182189
}
183190

184191
public ModAPITransformer addModAPITransformer(ASMDataTable dataTable)
@@ -189,15 +196,14 @@ public ModAPITransformer addModAPITransformer(ASMDataTable dataTable)
189196
return modAPI;
190197
}
191198

192-
List<URL> parentURLs = null;
193199
public boolean containsSource(File source)
194200
{
195-
if (parentURLs == null) {
196-
parentURLs = Arrays.asList(mainClassLoader.getURLs());
201+
if (this.parentURLs == null) {
202+
this.parentURLs = Arrays.asList(this.mainClassLoader.getURLs());
197203
}
198204
try
199205
{
200-
return parentURLs.contains(source.toURI().toURL());
206+
return this.parentURLs.contains(source.toURI().toURL());
201207
} catch (MalformedURLException e)
202208
{
203209
// shouldn't happen

0 commit comments

Comments
 (0)