net.fabricmc.loader.launch.knot.Knot Java Examples

The following examples show how to use net.fabricmc.loader.launch.knot.Knot. 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: TestingExtension.java    From multiconnect with MIT License 6 votes vote down vote up
private static void setup() {
    if (isSetup.getAndSet(true)) {
        while (isSettingUp.get()) {
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
        }
        Thread.currentThread().setContextClassLoader(knotClassLoader);
        return;
    }
    System.setProperty("fabric.development", "true");
    System.setProperty("fabric.loader.entrypoint", "net.earthcomputer.multiconnect.TestingDummyMain");
    Knot knot = new Knot(EnvType.CLIENT, null);
    knot.init(new String[0]);
    knotClassLoader = knot.getClassLoader();
    ((KnotClassLoaderInterface) knotClassLoader).addClassLoaderExclusion("net.earthcomputer.multiconnect.TestingExtension");
    isSettingUp.set(false);
}
 
Example #2
Source File: OptifineSetup.java    From OptiFabric with Mozilla Public License 2.0 6 votes vote down vote up
Path getMinecraftJar() throws FileNotFoundException {
	Optional<Path> entrypointResult = findFirstClass(Knot.class.getClassLoader(), Collections.singletonList("net.minecraft.client.main.Main"));
	if (!entrypointResult.isPresent()) {
		throw new RuntimeException("Failed to find minecraft jar");
	}
	if (!Files.exists(entrypointResult.get())) {
		throw new RuntimeException("Failed to locate minecraft jar");
	}
	if (fabricLauncher.isDevelopment()) {
		Path path = entrypointResult.get().getParent();
		Path minecraftJar = path.resolve(String.format("minecraft-%s-client.jar", OptifineVersion.minecraftVersion)); //Lets hope you are using loom in dev
		if (!Files.exists(minecraftJar)) {
			return getNewMinecraftDevJar();
		}
		return minecraftJar;
	}
	return entrypointResult.get();
}
 
Example #3
Source File: EntrypointPatchFML125.java    From fabric-loader with Apache License 2.0 6 votes vote down vote up
@Override
public void process(FabricLauncher launcher, Consumer<ClassNode> classEmitter) {
	if (classExists(launcher, TO)
		&& !classExists(launcher, "cpw.mods.fml.relauncher.FMLRelauncher")) {

		if (!(launcher instanceof Knot)) {
			throw new RuntimeException("1.2.5 FML patch only supported on Knot!");
		}

		debug("Detected 1.2.5 FML - Knotifying ModClassLoader...");
		try {
			ClassNode patchedClassLoader = loadClass(launcher, FROM);
			ClassNode remappedClassLoader = new ClassNode();

			patchedClassLoader.accept(new ClassRemapper(remappedClassLoader, new Remapper() {
				@Override
				public String map(String internalName) {
					return FROM_INTERNAL.equals(internalName) ? TO_INTERNAL : internalName;
				}
			}));

			classEmitter.accept(remappedClassLoader);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}
 
Example #4
Source File: OptifineSetup.java    From OptiFabric with Mozilla Public License 2.0 5 votes vote down vote up
Path getNewMinecraftDevJar() throws FileNotFoundException {
	Optional<Path> entrypointResult = getSource(Knot.class.getClassLoader(), "mappings/mappings.tiny");

	if (entrypointResult.isPresent()) {
		Path path = entrypointResult.get().getParent();
		Path minecraftJar = path.resolve(String.format("minecraft-%s-client.jar", OptifineVersion.minecraftVersion)); //Lets hope you are using loom in dev
		if (Files.exists(minecraftJar)) {
			return minecraftJar;
		}
	}

	throw new FileNotFoundException("Could not find minecraft jar!");
}
 
Example #5
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);
	}
}