Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModLauncher Integration: Remove reliance on Package Specification Version #143

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.Collection;
import java.util.Optional;

import cpw.mods.modlauncher.api.IEnvironment;
import cpw.mods.modlauncher.api.TypesafeMap;
import org.spongepowered.asm.launch.IClassProcessor;
import org.spongepowered.asm.launch.platform.container.ContainerHandleModLauncher;
import org.spongepowered.asm.logging.ILogger;
Expand All @@ -47,6 +50,7 @@

import cpw.mods.modlauncher.Launcher;
import cpw.mods.modlauncher.api.ITransformationService;
import org.spongepowered.asm.util.VersionNumber;

/**
* Mixin service for ModLauncher
Expand All @@ -56,7 +60,7 @@ public class MixinServiceModLauncher extends MixinServiceAbstract {
/**
* Specification version to check for at startup
*/
private static final String MODLAUNCHER_4_SPECIFICATION_VERSION = "4.0";
private static final VersionNumber MODLAUNCHER_4_SPECIFICATION_VERSION = VersionNumber.parse("4.0");

/**
* Specification version for ModLauncher versions >= 9.0.4, yes this is
Expand All @@ -65,8 +69,8 @@ public class MixinServiceModLauncher extends MixinServiceAbstract {
* version 5.0 for example, and ML7 and ML8 both had specification version
* 7.0).
*/
private static final String MODLAUNCHER_9_SPECIFICATION_VERSION = "8.0";
private static final VersionNumber MODLAUNCHER_9_SPECIFICATION_VERSION = VersionNumber.parse("8.0");

private static final String CONTAINER_PACKAGE = MixinServiceAbstract.LAUNCH_PACKAGE + "platform.container.";
private static final String MODLAUNCHER_4_ROOT_CONTAINER_CLASS = MixinServiceModLauncher.CONTAINER_PACKAGE + "ContainerHandleModLauncher";
private static final String MODLAUNCHER_9_ROOT_CONTAINER_CLASS = MixinServiceModLauncher.CONTAINER_PACKAGE + "ContainerHandleModLauncherEx";
Expand Down Expand Up @@ -117,15 +121,15 @@ public class MixinServiceModLauncher extends MixinServiceAbstract {
private CompatibilityLevel minCompatibilityLevel = CompatibilityLevel.JAVA_8;

public MixinServiceModLauncher() {
final Package pkg = ITransformationService.class.getPackage();
if (pkg.isCompatibleWith(MixinServiceModLauncher.MODLAUNCHER_9_SPECIFICATION_VERSION)) {
VersionNumber apiVersion = getModLauncherApiVersion();
if (apiVersion.compareTo(MODLAUNCHER_9_SPECIFICATION_VERSION) >= 0) {
this.createRootContainer(MixinServiceModLauncher.MODLAUNCHER_9_ROOT_CONTAINER_CLASS);
this.minCompatibilityLevel = CompatibilityLevel.JAVA_16;
} else {
this.createRootContainer(MixinServiceModLauncher.MODLAUNCHER_4_ROOT_CONTAINER_CLASS);
}
}

/**
* Begin init
*
Expand Down Expand Up @@ -200,9 +204,8 @@ protected ILogger createLogger(String name) {
@Override
public boolean isValid() {
try {
Launcher.INSTANCE.hashCode();
final Package pkg = ITransformationService.class.getPackage();
if (!pkg.isCompatibleWith(MixinServiceModLauncher.MODLAUNCHER_4_SPECIFICATION_VERSION)) {
VersionNumber apiVersion = getModLauncherApiVersion();
if (apiVersion.compareTo(MixinServiceModLauncher.MODLAUNCHER_4_SPECIFICATION_VERSION) < 0) {
return false;
}
} catch (Throwable th) {
Expand Down Expand Up @@ -311,4 +314,20 @@ public Collection<IClassProcessor> getProcessors() {
);
}

private static VersionNumber getModLauncherApiVersion() {
Optional<String> version = Optional.empty();
try {
TypesafeMap.Key<String> versionProperty = IEnvironment.Keys.MLSPEC_VERSION.get();
version = Launcher.INSTANCE.environment().getProperty(versionProperty);
} catch (Exception ignored) {
}

// Fall back to the package information (this is not present when loaded as a module)
if (!version.isPresent()) {
version = Optional.ofNullable(ITransformationService.class.getPackage().getSpecificationVersion());
}

return version.map(VersionNumber::parse).orElse(VersionNumber.NONE);
}

}
Loading