-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathFabricLoaderMod.java
More file actions
73 lines (62 loc) · 2.32 KB
/
FabricLoaderMod.java
File metadata and controls
73 lines (62 loc) · 2.32 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package i18nupdatemod.fabricloader;
import i18nupdatemod.I18nUpdateMod;
import i18nupdatemod.util.Log;
import i18nupdatemod.util.Reflection;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Map;
//1.14-latest
public class FabricLoaderMod implements ClientModInitializer {
@Override
public void onInitializeClient() {
Path gameDir = FabricLoader.getInstance().getGameDir();
Log.setMinecraftLogFile(gameDir);
String mcVersion = getMcVersion();
if (mcVersion == null) {
Log.warning("Minecraft version not found");
return;
}
I18nUpdateMod.init(gameDir, mcVersion, "Fabric", getMods());
}
private String getMcVersion() {
try {
// Fabric
return (String) Reflection.clazz("net.fabricmc.loader.impl.FabricLoaderImpl")
.get("INSTANCE")
.get("getGameProvider()")
.get("getNormalizedGameVersion()").get();
} catch (Exception ignored) {
}
try {
// Quilt
return (String) Reflection.clazz("org.quiltmc.loader.impl.QuiltLoaderImpl")
.get("INSTANCE")
.get("getGameProvider()")
.get("getNormalizedGameVersion()").get();
} catch (Exception ignored) {
}
return null;
}
private HashSet<String> getMods() {
HashSet<String> modList = new HashSet<>();
try {
// Fabric
@SuppressWarnings("unchecked") final Map<String, Object> instance = (Map<String, Object>) Reflection.clazz("net.fabricmc.loader.impl.FabricLoaderImpl")
.get("INSTANCE")
.get("modMap").get();
modList = new HashSet<>(instance.keySet());
} catch (Exception ignored) {
}
try {
// Quilt
@SuppressWarnings("unchecked") final Map<String, Object> instance = (Map<String, Object>) Reflection.clazz("org.quiltmc.loader.impl.QuiltLoaderImpl")
.get("INSTANCE")
.get("modMap").get();
modList = new HashSet<>(instance.keySet());
} catch (Exception ignored) {
}
return modList;
}
}