Java Code Examples for net.fabricmc.loader.launch.common.FabricLauncherBase#getLauncher()

The following examples show how to use net.fabricmc.loader.launch.common.FabricLauncherBase#getLauncher() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MixinServiceKnot.java    From fabric-loader with Apache License 2.0 4 votes vote down vote up
@Override
public String getName() {
	return FabricLauncherBase.getLauncher() instanceof Knot ? "Knot/Fabric" : "Launchwrapper/Fabric";
}
 
Example 2
Source File: FabricLoader.java    From fabric-loader with Apache License 2.0 4 votes vote down vote up
public void prepareModInit(File newRunDir, Object gameInstance) {
	if (!frozen) {
		throw new RuntimeException("Cannot instantiate mods when not frozen!");
	}

	if (gameInstance != null && FabricLauncherBase.getLauncher() instanceof Knot) {
		ClassLoader gameClassLoader = gameInstance.getClass().getClassLoader();
		ClassLoader targetClassLoader = FabricLauncherBase.getLauncher().getTargetClassLoader();
		boolean matchesKnot = (gameClassLoader == targetClassLoader);
		boolean containsKnot = false;

		if (matchesKnot) {
			containsKnot = true;
		} else {
			gameClassLoader = gameClassLoader.getParent();
			while (gameClassLoader != null && gameClassLoader.getParent() != gameClassLoader) {
				if (gameClassLoader == targetClassLoader) {
					containsKnot = true;
				}
				gameClassLoader = gameClassLoader.getParent();
			}
		}

		if (!matchesKnot) {
			if (containsKnot) {
				getLogger().info("Environment: Target class loader is parent of game class loader.");
			} else {
				getLogger().warn("\n\n* CLASS LOADER MISMATCH! THIS IS VERY BAD AND WILL PROBABLY CAUSE WEIRD ISSUES! *\n"
					+ " - Expected game class loader: " + FabricLauncherBase.getLauncher().getTargetClassLoader() + "\n"
					+ " - Actual game class loader: " + gameClassLoader + "\n"
					+ "Could not find the expected class loader in game class loader parents!\n");
			}
		}
	}

	this.gameInstance = gameInstance;

	if (gameDir != null) {
		try {
			if (!gameDir.getCanonicalFile().equals(newRunDir.getCanonicalFile())) {
				getLogger().warn("Inconsistent game execution directories: engine says " + newRunDir.getAbsolutePath() + ", while initializer says " + gameDir.getAbsolutePath() + "...");
				setGameDir(newRunDir);
			}
		} catch (IOException e) {
			getLogger().warn("Exception while checking game execution directory consistency!", e);
		}
	} else {
		setGameDir(newRunDir);
	}
}