Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/657'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mumfrey committed Jan 21, 2024
2 parents 6948758 + 9e8af15 commit 41a6885
Showing 1 changed file with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.util.Collection;
import java.util.Optional;

import org.spongepowered.asm.launch.IClassProcessor;
import org.spongepowered.asm.launch.platform.container.ContainerHandleModLauncher;
Expand All @@ -46,7 +47,10 @@
import com.google.common.collect.ImmutableList;

import cpw.mods.modlauncher.Launcher;
import cpw.mods.modlauncher.api.IEnvironment;
import cpw.mods.modlauncher.api.ITransformationService;
import cpw.mods.modlauncher.api.TypesafeMap;
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 = MixinServiceModLauncher.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 = MixinServiceModLauncher.getModLauncherApiVersion();
if (apiVersion.compareTo(MixinServiceModLauncher.MODLAUNCHER_4_SPECIFICATION_VERSION) < 0) {
return false;
}
} catch (Throwable th) {
Expand Down Expand Up @@ -311,4 +314,16 @@ public Collection<IClassProcessor> getProcessors() {
);
}

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

// 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);
}

}

0 comments on commit 41a6885

Please sign in to comment.