Skip to content

Commit

Permalink
change: Replace IrisApi using methodhandles
Browse files Browse the repository at this point in the history
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
FlashyReese committed Jun 6, 2023
1 parent 0f2692c commit 5c288a4
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation "me.jellysquid.mods:sodium-fabric:0.4.10+build.214"
modImplementation "me.jellysquid.mods:sodium-fabric:0.4.10+build.219"
//modImplementation "maven.modrinth:sodium:${project.sodium_version}"
//modImplementation "maven.modrinth:iris:${project.iris_version}"

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=23w17a
yarn_mappings=23w17a+build.10
loader_version=0.14.19
minecraft_version=1.20-rc1
yarn_mappings=1.20-rc1+build.2
loader_version=0.14.21
# Mod Properties
mod_version=1.5.0
maven_group=me.flashyreese.mods
Expand All @@ -15,4 +15,4 @@ org.gradle.jvmargs=-Xmx1G
iris_version=1.5.2+1.19.4

#Fabric api
fabric_version=0.79.2+1.20
fabric_version=0.83.0+1.20
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.BasicFrame;
import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.tab.Tab;
import me.flashyreese.mods.reeses_sodium_options.client.gui.frame.tab.TabFrame;
import me.flashyreese.mods.reeses_sodium_options.compat.IrisCompat;
import me.jellysquid.mods.sodium.client.SodiumClientMod;
import me.jellysquid.mods.sodium.client.gui.SodiumGameOptions;
import me.jellysquid.mods.sodium.client.gui.options.Option;
Expand All @@ -12,6 +13,7 @@
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
import me.jellysquid.mods.sodium.client.gui.widgets.FlatButtonWidget;
import me.jellysquid.mods.sodium.client.util.Dim2i;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
Expand Down Expand Up @@ -88,17 +90,20 @@ protected BasicFrame.Builder parentFrameBuilder() {

basicFrameBuilder = this.parentBasicFrameBuilder(basicFrameDim, tabFrameDim);

/*if (FabricLoader.getInstance().isModLoaded("iris")) {
int size = this.client.textRenderer.getWidth(Text.translatable(IrisApi.getInstance().getMainScreenLanguageKey()));
if (IrisCompat.isIrisPresent()) { // FabricLoader.getInstance().isModLoaded("iris")) {
//int size = this.client.textRenderer.getWidth(Text.translatable(IrisApi.getInstance().getMainScreenLanguageKey()));
int size = this.client.textRenderer.getWidth(Text.translatable(IrisCompat.getIrisShaderPacksScreenLanguageKey()));
Dim2i shaderPackButtonDim;
if (!SodiumClientMod.options().notifications.hideDonationButton) {
shaderPackButtonDim = new Dim2i(donateButtonDim.x() - 12 - size, tabFrameDim.y() - 26, 10 + size, 20);
} else {
shaderPackButtonDim = new Dim2i(tabFrameDim.getLimitX() - size - 10, tabFrameDim.y() - 26, 10 + size, 20);
}
FlatButtonWidget shaderPackButton = new FlatButtonWidget(shaderPackButtonDim, Text.translatable(IrisApi.getInstance().getMainScreenLanguageKey()), () -> this.client.setScreen((Screen) IrisApi.getInstance().openMainIrisScreenObj(this)));

//FlatButtonWidget shaderPackButton = new FlatButtonWidget(shaderPackButtonDim, Text.translatable(IrisApi.getInstance().getMainScreenLanguageKey()), () -> this.client.setScreen((Screen) IrisApi.getInstance().openMainIrisScreenObj(this)));
FlatButtonWidget shaderPackButton = new FlatButtonWidget(shaderPackButtonDim, Text.translatable(IrisCompat.getIrisShaderPacksScreenLanguageKey()), () -> this.client.setScreen(IrisCompat.getIrisShaderPacksScreen(this)));
basicFrameBuilder.addChild(dim -> shaderPackButton);
}*/
}

return basicFrameBuilder;
}
Expand Down
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;
}
}

0 comments on commit 5c288a4

Please sign in to comment.