|
| 1 | +package gg.essential.loader.stage1; |
| 2 | + |
| 3 | +import cpw.mods.modlauncher.Launcher; |
| 4 | +import cpw.mods.modlauncher.api.IEnvironment; |
| 5 | +import cpw.mods.modlauncher.api.TypesafeMap; |
| 6 | +import net.minecraftforge.fml.loading.FMLLoader; |
| 7 | + |
| 8 | +import java.nio.file.Path; |
| 9 | +import java.nio.file.Paths; |
| 10 | + |
| 11 | +@SuppressWarnings("unused") |
| 12 | +public class EssentialMixinPluginLoader { |
| 13 | + private static final String KEY_LOADED = "gg.essential.loader.stage1.loaded"; |
| 14 | + |
| 15 | + public EssentialMixinPluginLoader() throws Exception { |
| 16 | + // Check if another stage1 loader has already loaded stage2 (we do not want to load it twice) |
| 17 | + final TypesafeMap blackboard = Launcher.INSTANCE.blackboard(); |
| 18 | + final TypesafeMap.Key<Object> LOADED = |
| 19 | + TypesafeMap.Key.getOrCreate(blackboard, KEY_LOADED, Object.class); |
| 20 | + if (blackboard.get(LOADED).isPresent()) { |
| 21 | + return; |
| 22 | + } |
| 23 | + // We are doing it |
| 24 | + blackboard.computeIfAbsent(LOADED, __ -> this); |
| 25 | + |
| 26 | + final Path gameDir = Launcher.INSTANCE.environment() |
| 27 | + .getProperty(IEnvironment.Keys.GAMEDIR.get()) |
| 28 | + .orElse(Paths.get(".")); |
| 29 | + |
| 30 | + EssentialLoader loader = EssentialLoader.getInstance("modlauncher", "forge_" + FMLLoader.versionInfo().mcVersion()); |
| 31 | + loader.load(gameDir); |
| 32 | + |
| 33 | + loader.getStage2().getClass() |
| 34 | + .getMethod("loadFromMixin", Path.class) |
| 35 | + .invoke(loader.getStage2(), gameDir); |
| 36 | + } |
| 37 | +} |
0 commit comments