-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathResourceUtils.java
More file actions
35 lines (29 loc) · 1.3 KB
/
Copy pathResourceUtils.java
File metadata and controls
35 lines (29 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.llamalad7.mixinextras.utils;
import com.llamalad7.mixinextras.service.MixinExtrasService;
import org.spongepowered.asm.service.MixinService;
import java.io.InputStream;
public class ResourceUtils {
static InputStream getResourceAsStream(String name) {
InputStream result = MixinService.getService().getResourceAsStream(name);
if (result != null) {
// Happy fast path
return result;
}
// MixinServiceModLauncher is very poorly designed and relies heavily on the current TCCL
// This might not be what we expect if we're running e.g. on a common worker thread
ClassLoader oldTccl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(MixinExtrasService.getInstance().getMixinConfigsFinder().getClassLoader());
try {
// See if we get a result with the transforming classloader
return MixinService.getService().getResourceAsStream(name);
} finally {
Thread.currentThread().setContextClassLoader(oldTccl);
}
}
public interface ConfigsFinder {
ClassLoader getClassLoader();
static ConfigsFinder defaultConfigsFinder() {
return ResourceUtils.class::getClassLoader;
}
}
}