diff --git a/gradle.properties b/gradle.properties index 166941c..1216d12 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx1G # Mod Properties - mod_version = 1.2.0 + mod_version = 1.2.1 maven_group = net.boostedbrightness archives_base_name = boosted-brightness diff --git a/src/main/java/net/boostedbrightness/mixin/MixinMinecraftClient.java b/src/main/java/net/boostedbrightness/mixin/MixinMinecraftClient.java index 6be0403..93178b5 100644 --- a/src/main/java/net/boostedbrightness/mixin/MixinMinecraftClient.java +++ b/src/main/java/net/boostedbrightness/mixin/MixinMinecraftClient.java @@ -1,6 +1,8 @@ package net.boostedbrightness.mixin; +import net.boostedbrightness.BoostedBrightness; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.options.GameOptions; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -8,6 +10,9 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.lang.reflect.Field; +import java.util.List; + import static net.boostedbrightness.BoostedBrightness.prevGamma; @Mixin(MinecraftClient.class) @@ -22,4 +27,42 @@ private void close(CallbackInfo info) { if (prevGamma != null) options.gamma = prevGamma; } + + // manipulate the sodium mods custom options screen right when it gets opened but before it gets displayed + @Inject(at = @At("HEAD"), method = "openScreen") + private void openScreen(Screen screen, CallbackInfo info) + { + try + { + // screen -> pages -> 1st page (general) -> groups -> 1st group -> options -> 2nd option (gamma) -> control (slider) -> overwrite min and max + List optionPages = (List) get(screen, "me.jellysquid.mods.sodium.client.gui.SodiumOptionsGUI", "pages"); + List optionGroups = (List) get(optionPages.get(0), "me.jellysquid.mods.sodium.client.gui.options.OptionPage", "groups"); + List options = (List) get(optionGroups.get(0), "me.jellysquid.mods.sodium.client.gui.options.OptionGroup", "options"); + Object sliderControl = get(options.get(1), "me.jellysquid.mods.sodium.client.gui.options.OptionImpl", "control"); + Class sliderControlClass = Class.forName("me.jellysquid.mods.sodium.client.gui.options.control.SliderControl"); + setInt(sliderControl, sliderControlClass, "min", (int) (BoostedBrightness.MIN_BRIGHTNESS * 100)); + setInt(sliderControl, sliderControlClass, "max", (int) (BoostedBrightness.MAX_BRIGHTNESS * 100)); + } + catch (ClassNotFoundException ignored) { } // sodium mod not used + catch (Exception ex) + { + System.err.printf("[Boosted Brightness]: %s: %s\n", ex.getClass().getSimpleName(), ex.getLocalizedMessage()); + } + } + + // make a field accessible and get its value + private Object get(Object instance, String className, String name) throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException + { + Field f = Class.forName(className).getDeclaredField(name); + f.setAccessible(true); + return f.get(instance); + } + + // make an int field accessible and set its value + private void setInt(Object instance, Class clazz, String field, int value) throws NoSuchFieldException, IllegalAccessException + { + Field f = clazz.getDeclaredField(field); + f.setAccessible(true); + f.setInt(instance, value); + } } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index f47e753..98fc3e5 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -6,11 +6,11 @@ "name": "Boosted Brightness", "description": "Allows you to set your brightness beyond default levels.", "authors": [ - "supersmartypants" + "adamviola" ], "contact": { - "homepage": "https://github.com/supersmartypants/BoostedBrightness", - "sources": "https://github.com/supersmartypants/BoostedBrightness" + "homepage": "https://github.com/adamviola/BoostedBrightness", + "sources": "https://github.com/adamviola/BoostedBrightness" }, "license": "MIT",