Skip to content

Commit

Permalink
Only apply Fabric Mixin services on platforms that need them (#790)
Browse files Browse the repository at this point in the history
Mixin provides its own bundled implementations on some other platforms
(LaunchWrapper, ModLauncher) that can be used instead.
  • Loading branch information
Juuxel authored May 22, 2023
1 parent 3d26d17 commit 99c48ae
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,9 @@ private byte[] toByteArray(InputStream inputStream) throws IOException {
public boolean isDevelopment() {
return isDevelopment;
}

@Override
public boolean useFabricMixinServices() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ public interface FabricLauncher {
String getTargetNamespace();

List<Path> getClassPath();

// Mixin ships with its own for LaunchWrapper etc.,
// so we can skip our implementations on such platforms.
boolean useFabricMixinServices();
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
import net.fabricmc.loader.impl.launch.FabricLauncherBase;

public class FabricGlobalPropertyService implements IGlobalPropertyService {
public FabricGlobalPropertyService() {
if (!FabricLauncherBase.getLauncher().useFabricMixinServices()) {
// If an exception is thrown here, Mixin is designed to skip over this service.
// This also happens with its bundled LaunchWrapper and ModLauncher implementations.
throw new UnsupportedOperationException("FabricGlobalPropertyService is not supported on this launch platform.");
}
}

@Override
public IPropertyKey resolveKey(String name) {
return new MixinStringPropertyKey(name);
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/fabricmc/loader/impl/launch/knot/Knot.java
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ public String getEntrypoint() {
return provider.getEntrypoint();
}

@Override
public boolean useFabricMixinServices() {
return true;
}

public static void main(String[] args) {
new Knot(null).init(args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public String getName() {

@Override
public boolean isValid() {
return true;
return FabricLauncherBase.getLauncher().useFabricMixinServices();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@

import org.spongepowered.asm.service.IMixinServiceBootstrap;

import net.fabricmc.loader.impl.launch.FabricLauncherBase;

public class MixinServiceKnotBootstrap implements IMixinServiceBootstrap {
public MixinServiceKnotBootstrap() {
if (!FabricLauncherBase.getLauncher().useFabricMixinServices()) {
// If an exception is thrown here, Mixin is designed to skip over this service.
// This also happens with its bundled LaunchWrapper and ModLauncher implementations.
throw new UnsupportedOperationException("MixinServiceKnotBootstrap is not supported on this launch platform.");
}
}

@Override
public String getName() {
return "Knot";
Expand Down

0 comments on commit 99c48ae

Please # to comment.