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
1 parent
643a06a
commit ff7d340
Showing
18 changed files
with
144 additions
and
106 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
49 changes: 49 additions & 0 deletions
49
Common/src/main/java/com/blamejared/tipthescales/ClampingLazyMaxIntRangeSlider.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,49 @@ | ||
package com.blamejared.tipthescales; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.DataResult; | ||
import net.minecraft.client.OptionInstance; | ||
import net.minecraft.client.gui.components.CycleButton; | ||
import net.minecraft.util.Mth; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import java.util.function.IntSupplier; | ||
import java.util.stream.IntStream; | ||
|
||
public record ClampingLazyMaxIntRangeSlider(int minInclusive, | ||
IntSupplier maxSupplier) implements OptionInstance.IntRangeBase, OptionInstance.SliderableOrCyclableValueSet<Integer> { | ||
|
||
public @NotNull Optional<Integer> validateValue(@NotNull Integer value) { | ||
|
||
return Optional.of(Mth.clamp(value, this.minInclusive(), this.maxInclusive())); | ||
} | ||
|
||
public int maxInclusive() { | ||
|
||
return this.maxSupplier.getAsInt(); | ||
} | ||
|
||
public @NotNull Codec<Integer> codec() { | ||
|
||
Function<Integer, DataResult<Integer>> func = (value) -> { | ||
int max = this.maxSupplier.getAsInt() + 1; | ||
return value.compareTo(this.minInclusive) >= 0 && value.compareTo(max) <= 0 ? DataResult.success(value) : DataResult.error("Value " + value + " outside of range [" + this.minInclusive + ":" + max + "]", value); | ||
}; | ||
return Codec.INT.flatXmap(func, func); | ||
} | ||
|
||
public boolean createCycleButton() { | ||
|
||
return false; | ||
} | ||
|
||
public CycleButton.@NotNull ValueListSupplier<Integer> valueListSupplier() { | ||
|
||
return CycleButton.ValueListSupplier.create(IntStream.range(this.minInclusive, this.maxInclusive() + 1) | ||
.boxed() | ||
.toList()); | ||
} | ||
|
||
} |
17 changes: 0 additions & 17 deletions
17
Common/src/main/java/com/blamejared/tipthescales/ScaleHelper.java
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
Common/src/main/java/com/blamejared/tipthescales/mixin/AccessOptions.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,16 @@ | ||
package com.blamejared.tipthescales.mixin; | ||
|
||
import net.minecraft.client.OptionInstance; | ||
import net.minecraft.client.Options; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(Options.class) | ||
public interface AccessOptions { | ||
|
||
@Mutable | ||
@Accessor("guiScale") | ||
void tipthescales$setGuiScale(OptionInstance<Integer> guiScale); | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
Common/src/main/java/com/blamejared/tipthescales/mixin/MixinMinecraft.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,36 @@ | ||
package com.blamejared.tipthescales.mixin; | ||
|
||
import com.blamejared.tipthescales.ClampingLazyMaxIntRangeSlider; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.OptionInstance; | ||
import net.minecraft.client.Options; | ||
import net.minecraft.client.main.GameConfig; | ||
import net.minecraft.network.chat.Component; | ||
import org.spongepowered.asm.mixin.Final; | ||
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; | ||
|
||
@Mixin(Minecraft.class) | ||
public class MixinMinecraft { | ||
|
||
@Shadow | ||
@Final | ||
public Options options; | ||
|
||
@Inject(method = "<init>", at = @At(value = "TAIL")) | ||
public void tipthescales$init(GameConfig $$0, CallbackInfo ci) { | ||
|
||
((AccessOptions) this.options).tipthescales$setGuiScale(new OptionInstance<>("options.guiScale", OptionInstance.noTooltip(), (caption, value) -> { | ||
Component current = value == 0 ? Component.translatable("options.guiScale.auto") : Component.literal(Integer.toString(value)); | ||
return Options.genericValueLabel(caption, current); | ||
}, new ClampingLazyMaxIntRangeSlider(0, () -> { | ||
Minecraft $$0x = Minecraft.getInstance(); | ||
return !$$0x.isRunning() ? 2147483646 : $$0x.getWindow().calculateScale(0, $$0x.isEnforceUnicode()); | ||
}), 0, (value) -> { | ||
})); | ||
} | ||
|
||
} |
2 changes: 2 additions & 0 deletions
2
Common/src/main/java/com/blamejared/tipthescales/mixin/MixinPlugin.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
57 changes: 13 additions & 44 deletions
57
Common/src/main/java/com/blamejared/tipthescales/mixin/MixinVideoSettingsScreen.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 |
---|---|---|
@@ -1,81 +1,50 @@ | ||
package com.blamejared.tipthescales.mixin; | ||
|
||
import com.blamejared.tipthescales.ScaleHelper; | ||
import net.minecraft.client.*; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.Options; | ||
import net.minecraft.client.gui.screens.OptionsSubScreen; | ||
import net.minecraft.client.gui.screens.Screen; | ||
import net.minecraft.client.gui.screens.VideoSettingsScreen; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.chat.TextComponent; | ||
import net.minecraft.network.chat.TranslatableComponent; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.Objects; | ||
|
||
@Mixin(VideoSettingsScreen.class) | ||
public class MixinVideoSettingsScreen extends OptionsSubScreen { | ||
|
||
public MixinVideoSettingsScreen(Screen param0, Options param1, Component param2) { | ||
|
||
super(param0, param1, param2); | ||
} | ||
@Unique | ||
public int tipthescales$cachedGuiScale; | ||
|
||
@Inject(method = "init", at = @At("HEAD")) | ||
public void tipTheScales$init(CallbackInfo ci) { | ||
public MixinVideoSettingsScreen(Screen parent, Options options, Component title) { | ||
|
||
Option[] options = VideoSettingsScreenAccessor.tipTheScales$getOPTIONS(); | ||
for(int i = 0; i < options.length; i++) { | ||
Option option = options[i]; | ||
if(option.equals(Option.GUI_SCALE)) { | ||
|
||
CycleOption<Integer> cycleOption = (CycleOption<Integer>) option; | ||
OptionAccessor accessOption = (OptionAccessor) cycleOption; | ||
|
||
String captionKey = accessOption.tipTheScales$getCaption().getContents(); | ||
if(accessOption.tipTheScales$getCaption() instanceof TranslatableComponent transComp) { | ||
captionKey = transComp.getKey(); | ||
} | ||
|
||
int maxScale = Minecraft.getInstance() | ||
.getWindow() | ||
.calculateScale(0, Minecraft.getInstance().isEnforceUnicode()); | ||
ProgressOption progressOption = new ProgressOption(captionKey, | ||
0, | ||
maxScale, | ||
1, | ||
options1 -> (double) options1.guiScale, | ||
(options1, aDouble) -> options1.guiScale = aDouble.intValue(), | ||
(options1, progressOption1) -> ScaleHelper.genericValueLabel(progressOption1, options1.guiScale == 0 ? new TranslatableComponent("options.guiScale.auto") : new TextComponent(options1.guiScale + ""))); | ||
options[i] = progressOption; | ||
} | ||
} | ||
super(parent, options, title); | ||
} | ||
|
||
@Inject(method = "mouseClicked", at = @At(value = "HEAD")) | ||
public void tipTheScales$mouseClickedHead(double mouseX, double mouseY, int button, CallbackInfoReturnable<Boolean> cir) { | ||
|
||
ScaleHelper.guiScale = this.options.guiScale; | ||
tipthescales$cachedGuiScale = this.options.guiScale().get(); | ||
} | ||
|
||
|
||
@Redirect(method = "mouseClicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;resizeDisplay()V")) | ||
public void tipTheScales$mouseClickedResize(Minecraft instance) {} | ||
|
||
|
||
@Inject(method = "mouseReleased", at = @At(value = "HEAD")) | ||
public void tipTheScales$mouseReleasedHead(double mouseX, double mouseY, int button, CallbackInfoReturnable<Boolean> cir) { | ||
|
||
if(this.options.guiScale != ScaleHelper.guiScale) { | ||
this.minecraft.resizeDisplay(); | ||
if(this.options.guiScale().get() != tipthescales$cachedGuiScale) { | ||
Objects.requireNonNull(this.minecraft).resizeDisplay(); | ||
} | ||
ScaleHelper.guiScale = this.options.guiScale; | ||
tipthescales$cachedGuiScale = this.options.guiScale().get(); | ||
} | ||
|
||
@Redirect(method = "mouseReleased", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/Minecraft;resizeDisplay()V")) | ||
public void tipTheScales$mouseReleasedResize(Minecraft instance) {} | ||
|
||
|
||
} |
14 changes: 0 additions & 14 deletions
14
Common/src/main/java/com/blamejared/tipthescales/mixin/OptionAccessor.java
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
Common/src/main/java/com/blamejared/tipthescales/mixin/VideoSettingsScreenAccessor.java
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
accessWidener v1 named | ||
accessible class net/minecraft/client/OptionInstance$ValueSet | ||
accessible class net/minecraft/client/OptionInstance$IntRangeBase | ||
accessible class net/minecraft/client/OptionInstance$SliderableOrCyclableValueSet | ||
|
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
2 changes: 1 addition & 1 deletion
2
Fabric/src/main/java/com/blamejared/tipthescales/TipTheScalesFabric.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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package com.blamejared.tipthescales; | ||
|
||
public class TipTheScalesFabric { | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
public net.minecraft.client.OptionInstance$ValueSet | ||
public net.minecraft.client.OptionInstance$IntRangeBase | ||
public net.minecraft.client.OptionInstance$SliderableOrCyclableValueSet |
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