Skip to content

Commit

Permalink
Updated to 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
adamviola committed Jun 14, 2022
1 parent 18532a2 commit 6d3ccb9
Show file tree
Hide file tree
Showing 15 changed files with 156 additions and 103 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ processResources {
// }
}

loom {
accessWidenerPath = file("src/main/resources/boostedbrightness.accesswidener")
}

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
Expand Down
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.2
loader_version=0.13.3
minecraft_version=1.19
yarn_mappings=1.19+build.2
loader_version=0.14.7

# Mod Properties
mod_version = 2.1.1
mod_version = 2.1.2
maven_group = net.boostedbrightness
archives_base_name = boosted-brightness

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.47.10+1.18.2
modmenu_version=3.1.0
sodium_version=mc1.18.2-0.4.1
fabric_version=0.55.3+1.19
modmenu_version=4.0.0
sodium_version=mc1.19-0.4.2
8 changes: 4 additions & 4 deletions src/main/java/net/boostedbrightness/BoostedBrightness.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.google.gson.*;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;

import net.fabricmc.api.ClientModInitializer;
Expand Down Expand Up @@ -92,7 +92,7 @@ public static int getBrightnessIndex() {

public static void setBrightnessIndex(int index) {
brightnessIndex = index;
client.options.gamma = getBrightness();
client.options.getGamma().setValue(getBrightness());
}

public static double getBrightness() {
Expand All @@ -105,7 +105,7 @@ public static double getBrightness(int index) {

public static void changeBrightness(double brightness) {
brightnesses.set(getBrightnessIndex(), brightness);
client.options.gamma = getBrightness();
client.options.getGamma().setValue(getBrightness());
}

public static void changeBrightness(int index, double brightness) {
Expand Down Expand Up @@ -190,7 +190,7 @@ private void asInt(JsonElement element, IntConsumer onSuccess) {

private void showOverlay(MinecraftClient client) {
client.inGameHud.setOverlayMessage(
new TranslatableText(
Text.translatable(
"overlay.boosted-brightness.change",
new Object[]{
getBrightnessIndex() + 1,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package net.boostedbrightness.misc;
import java.util.Optional;

import com.mojang.serialization.Codec;

import net.boostedbrightness.BoostedBrightness;
import net.minecraft.client.option.SimpleOption.SliderCallbacks;
import com.mojang.datafixers.util.Either;

public enum BoostedSliderCallbacks implements SliderCallbacks<Double>
{
INSTANCE;

@Override
public Optional<Double> validate(Double double_) {
return double_ >= BoostedBrightness.minBrightness && double_ <= BoostedBrightness.maxBrightness ? Optional.of(double_) : Optional.empty();
}

@Override
public double toSliderProgress(Double double_) {
double range = BoostedBrightness.maxBrightness - BoostedBrightness.minBrightness;
double offset = BoostedBrightness.minBrightness;
return (double_ - offset) / range;
}

@Override
public Double toValue(double d) {
double range = BoostedBrightness.maxBrightness - BoostedBrightness.minBrightness;
double offset = BoostedBrightness.minBrightness;
return d * range + offset;
}

@Override
public Codec<Double> codec() {
return Codec.either(Codec.doubleRange(BoostedBrightness.minBrightness, BoostedBrightness.maxBrightness), Codec.BOOL).xmap(either -> either.map(value -> value, value -> value != false ? 1.0 : 0.0), Either::left);
}
}
68 changes: 0 additions & 68 deletions src/main/java/net/boostedbrightness/mixin/MixinDoubleOption.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.boostedbrightness.mixin;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.GameMenuScreen;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.OptionsScreen;
import net.minecraft.client.option.GameOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import me.jellysquid.mods.sodium.client.gui.options.binding.OptionBinding;
import me.jellysquid.mods.sodium.client.gui.options.control.Control;
import me.jellysquid.mods.sodium.client.gui.options.storage.OptionStorage;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.TranslatableTextContent;
import net.boostedbrightness.BoostedBrightness;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.*;
Expand Down Expand Up @@ -37,7 +37,7 @@ private void init(OptionStorage<S> storage,
boolean enabled,
CallbackInfo info) {

if (name instanceof TranslatableText translatable && translatable.getKey().equals("options.gamma")) {
if (name.getContent() instanceof TranslatableTextContent content && content.getKey().equals("options.gamma")) {
this.binding = new GenericBinding<S, T>((opt, val) -> BoostedBrightness.changeBrightness((Integer) val * 0.01D), binding::getValue);
}
}
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/net/boostedbrightness/mixin/MixinSimpleOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package net.boostedbrightness.mixin;

import net.boostedbrightness.BoostedBrightness;
import net.boostedbrightness.misc.BoostedSliderCallbacks;
import net.minecraft.text.Text;
import net.minecraft.text.TextContent;
import net.minecraft.text.TranslatableTextContent;
import net.minecraft.client.option.SimpleOption;
import net.minecraft.client.option.SimpleOption.Callbacks;

import java.util.function.Consumer;
import java.util.function.Function;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
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 com.mojang.serialization.Codec;

@Mixin(SimpleOption.class)
public class MixinSimpleOption {

@Shadow
@Final
Text text;

@Shadow
@Final
@Mutable
Function<Double, Text> textGetter;

@Shadow
@Final
@Mutable
Callbacks<Double> callbacks;

@Shadow
@Final
@Mutable
Codec<Double> codec;

@Shadow
@Final
@Mutable
Consumer<Double> changeCallback;

@Inject(at = @At("RETURN"), method = "<init>")
private void init(CallbackInfo info) throws Exception {
TextContent content = this.text.getContent();
if (!(content instanceof TranslatableTextContent))
return;

String key = ((TranslatableTextContent) content).getKey();
if (!key.equals("options.gamma"))
return;

this.textGetter = this::textGetter;
this.callbacks = BoostedSliderCallbacks.INSTANCE;
this.codec = this.callbacks.codec();
this.changeCallback = this::changeCallback;
}

private Text textGetter(Double gamma) {
long brightness = Math.round(gamma * 100);
return Text.translatable("options.gamma").append(": ").append(
brightness == 0 ? Text.translatable("options.gamma.min") :
brightness == 100 ? Text.translatable("options.gamma.max") :
Text.literal(String.valueOf(brightness)));
}

private void changeCallback(Double gamma) {
BoostedBrightness.changeBrightness(gamma);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import me.jellysquid.mods.sodium.client.gui.options.control.ControlValueFormatter;
import me.jellysquid.mods.sodium.client.gui.options.control.SliderControl;
import net.boostedbrightness.BoostedBrightness;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.TranslatableTextContent;

import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -30,7 +31,7 @@ public class MixinSliderControl {

@Inject(at = @At("RETURN"), method = "<init>")
private void init(Option<Integer> option, int min, int max, int interval, ControlValueFormatter mode, CallbackInfo info) {
if (option.getName() instanceof TranslatableText translatable && translatable.getKey().equals("options.gamma")) {
if (option.getName().getContent() instanceof TranslatableTextContent content && content.getKey().equals("options.gamma")) {
this.min = (int) (BoostedBrightness.minBrightness * 100);
this.max = (int) (BoostedBrightness.maxBrightness * 100);
this.interval = (int) (BoostedBrightness.brightnessSliderInterval * 100);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/boostedbrightness/ui/BrightnessListWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.ElementListWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;

public class BrightnessListWidget extends ElementListWidget<BrightnessListWidget.BrightnessEntry> {

public BrightnessListWidget(MinecraftClient client, int i, int j, int k, int l, int m) {
super(client, i, j, k, l, m);
this.setRenderSelection(true);

if (client.options.gamma != BoostedBrightness.getBrightness()) {
BoostedBrightness.changeBrightness(client.options.gamma);
if (client.options.getGamma().getValue() != BoostedBrightness.getBrightness()) {
BoostedBrightness.changeBrightness(client.options.getGamma().getValue());
}

for (int idx = 0; idx < BoostedBrightness.numBrightnesses(); idx++) {
Expand Down Expand Up @@ -117,10 +117,10 @@ public static BrightnessListWidget.BrightnessEntry create(int index, int width,
widgets.add(new BrightnessSliderWidget(index, width / 2 - 120, 0, 240, 20, BrightnessSliderWidget.sliderValue(BoostedBrightness.getBrightness(index))));

if (index >= 2)
widgets.add(new ButtonWidget(width / 2 + 120 + 5, 0, 20, 20, new LiteralText("X"), (buttonWidget) -> { listWidget.removeBrightness(index); }));
widgets.add(new ButtonWidget(width / 2 + 120 + 5, 0, 20, 20, Text.literal("X"), (buttonWidget) -> { listWidget.removeBrightness(index); }));
}
else
widgets.add(new ButtonWidget(width / 2 - 120, 0, 240, 20, new LiteralText("+"), (buttonWidget) -> { listWidget.addBrightness(); }));
widgets.add(new ButtonWidget(width / 2 - 120, 0, 240, 20, Text.literal("+"), (buttonWidget) -> { listWidget.addBrightness(); }));

return new BrightnessEntry(widgets, index, listWidget);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import net.boostedbrightness.BoostedBrightness;
import net.minecraft.client.gui.widget.SliderWidget;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;

public class BrightnessSliderWidget extends SliderWidget {
private final int index;

protected BrightnessSliderWidget(int index, int x, int y, int width, int height, double value) {
super(x, y, width, height, LiteralText.EMPTY, value);
super(x, y, width, height, Text.empty(), value);
this.index = index;

this.updateMessage();
Expand All @@ -37,12 +35,11 @@ protected void applyValue() {

@Override
protected void updateMessage() {
double brightness = brightness();
// double threshold = 0.025; // TODO find actual value (half of the gamma change for a one pixel change on the slider)
Text text = new TranslatableText("options.gamma").append(": ").append(
brightness == 0 ? new TranslatableText("options.gamma.min") :
brightness == 1 ? new TranslatableText("options.gamma.max") :
new LiteralText(Math.round(brightness * 100) + "%"));
long brightness = Math.round(brightness() * 100);
Text text = Text.translatable("options.gamma").append(": ").append(
brightness == 0 ? Text.translatable("options.gamma.min") :
brightness == 100 ? Text.translatable("options.gamma.max") :
Text.literal(String.valueOf(brightness)));

this.setMessage(text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import net.boostedbrightness.BoostedBrightness;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ScreenTexts;
import net.minecraft.client.gui.screen.option.GameOptionsScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.TranslatableText;
import net.minecraft.screen.ScreenTexts;
import net.minecraft.text.Text;

public class ModMenuIntegration implements ModMenuApi {
@Override
Expand All @@ -22,7 +22,7 @@ public class ModMenuOptionsScreen extends GameOptionsScreen {
private BrightnessListWidget list;

public ModMenuOptionsScreen(Screen parent) {
super(parent, MinecraftClient.getInstance().options, new TranslatableText("options.boosted-brightness.title"));
super(parent, MinecraftClient.getInstance().options, Text.translatable("options.boosted-brightness.title"));
}

protected void init() {
Expand Down
Loading

0 comments on commit 6d3ccb9

Please sign in to comment.