-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change: Replace IrisApi using methodhandles
Previously, we transitioned from using reflection to the `IrisApi` interface for accessing Iris functionality. However, since `IrisApi` is not available separately and can only be used after the release day as a major version, we have decided to switch back to using reflection. Relying on the availability of `IrisApi` has introduced significant delays and dependencies on Iris. Until `IrisApi` becomes available separately, we will continue using reflection for accessing the required functionality. This commit reverts the changes made to utilize `IrisApi` and restores the original reflection-based approach. Please note that this revert will not be backported to previous versions.
- Loading branch information
1 parent
0f2692c
commit 5c288a4
Showing
4 changed files
with
69 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/me/flashyreese/mods/reeses_sodium_options/compat/IrisCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package me.flashyreese.mods.reeses_sodium_options.compat; | ||
|
||
import net.minecraft.client.gui.screen.Screen; | ||
|
||
import java.lang.invoke.MethodHandle; | ||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.MethodType; | ||
import java.lang.reflect.InvocationTargetException; | ||
|
||
public class IrisCompat { | ||
private static boolean irisPresent; | ||
private static MethodHandle handleScreen; | ||
private static MethodHandle handleTranslationKey; | ||
private static Object apiInstance; | ||
|
||
static { | ||
try { | ||
Class<?> api = Class.forName("net.irisshaders.iris.api.v0.IrisApi"); | ||
apiInstance = api.cast(api.getDeclaredMethod("getInstance").invoke(null)); | ||
handleScreen = MethodHandles.lookup().findVirtual(api, "openMainIrisScreenObj", MethodType.methodType(Object.class, Object.class)); | ||
handleTranslationKey = MethodHandles.lookup().findVirtual(api, "getMainScreenLanguageKey", MethodType.methodType(String.class)); | ||
irisPresent = true; | ||
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { | ||
irisPresent = false; | ||
} | ||
} | ||
|
||
public static Screen getIrisShaderPacksScreen(Screen parent) { | ||
if (irisPresent) { | ||
try { | ||
return (Screen) handleScreen.invokeWithArguments(apiInstance, parent); | ||
} catch (Throwable throwable) { | ||
throwable.printStackTrace(); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static String getIrisShaderPacksScreenLanguageKey() { | ||
if (irisPresent) { | ||
try { | ||
return (String) handleTranslationKey.invoke(apiInstance); | ||
} catch (Throwable throwable) { | ||
throwable.printStackTrace(); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public static boolean isIrisPresent() { | ||
return irisPresent; | ||
} | ||
} |