Skip to content

Commit

Permalink
Allowed the GameProvider to provide the namespace (#428)
Browse files Browse the repository at this point in the history
* Allowed the GameProvider to provide the namespace

* Removed the deprivation warning on the MappingConfiguration

* Removed process functions where the namespace isn't provided from being deprecated in the GamePatch

* Fixup of commit f71eda1 with AlexIIL's suggestions

* Allowed for no namespace to be provided when locating entrypoints
  • Loading branch information
coolGi69 authored May 25, 2024
1 parent e207307 commit 0a807e9
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.quiltmc.loader.impl.game.minecraft.patch.EntrypointPatch;
import org.quiltmc.loader.impl.game.minecraft.patch.TinyFDPatch;
import org.quiltmc.loader.impl.launch.common.QuiltLauncher;
import org.quiltmc.loader.impl.launch.common.QuiltLauncherBase;
import org.quiltmc.loader.impl.metadata.qmj.V1ModMetadataBuilder;
import org.quiltmc.loader.impl.util.Arguments;
import org.quiltmc.loader.impl.util.ExceptionUtil;
Expand Down Expand Up @@ -189,6 +190,11 @@ public boolean isObfuscated() {
return true; // generally yes...
}

@Override
public String getNamespace() {
return QuiltLauncherBase.getLauncher().isDevelopment() ? "named" : "intermediary";
}

@Override
public boolean requiresUrlClassLoader() {
return hasModLoader;
Expand Down Expand Up @@ -431,7 +437,7 @@ public void initialize(QuiltLauncher launcher) {

setupLogHandler(launcher, true);

transformer.locateEntrypoints(launcher, gameJars);
transformer.locateEntrypoints(launcher, getNamespace(), gameJars);
}

private void setupLogHandler(QuiltLauncher launcher, boolean useTargetCl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public final class BrandingPatch extends GamePatch {
@Override
public void process(QuiltLauncher launcher, GamePatchContext context) {
public void process(QuiltLauncher launcher, String namespace, GamePatchContext context) {
for (String brandClassName : new String[] {
"net.minecraft.client.ClientBrandRetriever",
"net.minecraft.server.MinecraftServer"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void finishEntrypoint(EnvType type, ListIterator<AbstractInsnNode> it) {
}

@Override
public void process(QuiltLauncher launcher, GamePatchContext context) {
public void process(QuiltLauncher launcher, String namespace, GamePatchContext context) {
EnvType type = launcher.getEnvironmentType();
String entrypoint = launcher.getEntrypoint();
Version gameVersion = getGameVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class TinyFDPatch extends GamePatch {
private static final String DIALOG_TITLE = "Select settings file (.json)";

@Override
public void process(QuiltLauncher launcher, GamePatchContext context) {
public void process(QuiltLauncher launcher, String namespace, GamePatchContext context) {
if (launcher.getEnvironmentType() != EnvType.CLIENT) {
// Fix should only be applied to clients.
return;
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/quiltmc/loader/impl/entrypoint/GamePatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.quiltmc.loader.impl.entrypoint;

import org.objectweb.asm.ClassReader;
import org.quiltmc.loader.impl.QuiltLoaderImpl;
import org.quiltmc.loader.impl.launch.common.QuiltLauncher;
import org.quiltmc.loader.impl.util.QuiltLoaderInternal;
import org.quiltmc.loader.impl.util.QuiltLoaderInternalType;
Expand Down Expand Up @@ -128,12 +129,18 @@ protected boolean isPublicInstance(int access) {
return ((access & 0x0F) == (Opcodes.ACC_PUBLIC | 0 /* non-static */));
}

public void process(QuiltLauncher launcher, Function<String, ClassReader> classSource, Consumer<ClassNode> classEmitter) {
public void process(QuiltLauncher launcher, String namespace, Function<String, ClassReader> classSource, Consumer<ClassNode> classEmitter) {
throw new AbstractMethodError(getClass() + " must override one of the 'process' methods!");
}
public void process(QuiltLauncher launcher, Function<String, ClassReader> classSource, Consumer<ClassNode> classEmitter) {
process(launcher, launcher.getTargetNamespace(), classSource, classEmitter);
}

public void process(QuiltLauncher launcher, String namespace, GamePatchContext context) {
process(launcher, namespace, context::getClassSourceReader, context::addPatchedClass);
}
public void process(QuiltLauncher launcher, GamePatchContext context) {
process(launcher, context::getClassSourceReader, context::addPatchedClass);
process(launcher, launcher.getTargetNamespace(), context);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ private void addPatchedClass(ClassNode node) {
}

public void locateEntrypoints(QuiltLauncher launcher, List<Path> gameJars) {
this.locateEntrypoints(launcher, null, gameJars);
}
public void locateEntrypoints(QuiltLauncher launcher, String namespace, List<Path> gameJars) {
if (entrypointsLocated) {
return;
}
Expand Down Expand Up @@ -129,7 +132,10 @@ public void addPatchedClass(ClassNode node) {
};

for (GamePatch patch : patches) {
patch.process(launcher, context);
if (namespace == null)
patch.process(launcher, context);
else
patch.process(launcher, namespace, context);
}

for (ClassNode node : addedClassNodes.values()) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/quiltmc/loader/impl/game/GameProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public interface GameProvider {
String getEntrypoint();
Path getLaunchDirectory();
boolean isObfuscated();
default String getNamespace() {
return isObfuscated()? "intermediary": "named";
};
boolean requiresUrlClassLoader();

boolean isEnabled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import net.fabricmc.mapping.tree.TinyMappingFactory;
import net.fabricmc.mapping.tree.TinyTree;

import org.quiltmc.loader.impl.QuiltLoaderImpl;
import org.quiltmc.loader.impl.game.GameProvider;
import org.quiltmc.loader.impl.util.ManifestUtil;
import org.quiltmc.loader.impl.util.QuiltLoaderInternal;
import org.quiltmc.loader.impl.util.QuiltLoaderInternalType;
Expand Down Expand Up @@ -78,6 +80,11 @@ public TinyTree getMappings() {
}

public String getTargetNamespace() {
GameProvider gameProvider = QuiltLoaderImpl.INSTANCE.tryGetGameProvider();
if (gameProvider != null)
return gameProvider.getNamespace();
// else
// If the game provider doesn't exist yet, use the development flag to set the namespace
return QuiltLauncherBase.getLauncher().isDevelopment() ? "named" : "intermediary";
}

Expand Down

0 comments on commit 0a807e9

Please sign in to comment.