-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
156 additions
and
103 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
37 changes: 37 additions & 0 deletions
37
src/main/java/net/boostedbrightness/misc/BoostedSliderCallbacks.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,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
68
src/main/java/net/boostedbrightness/mixin/MixinDoubleOption.java
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
src/main/java/net/boostedbrightness/mixin/MixinMinecraftClient.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
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
78 changes: 78 additions & 0 deletions
78
src/main/java/net/boostedbrightness/mixin/MixinSimpleOption.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,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); | ||
} | ||
} |
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
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
Oops, something went wrong.