Skip to content

Commit

Permalink
Merge pull request #9 from Bstn1802/master
Browse files Browse the repository at this point in the history
Added Sodium support by using Reflection to manipulate the slider for the gamma setting
  • Loading branch information
adamviola authored Jan 1, 2021
2 parents 399ce25 + 26444ef commit ca78b6a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
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;
import org.spongepowered.asm.mixin.injection.At;
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)
Expand All @@ -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);
}
}
6 changes: 3 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ca78b6a

Please sign in to comment.