Skip to content

Commit

Permalink
port to 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlll08 committed Jun 10, 2022
1 parent 643a06a commit ff7d340
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 106 deletions.
1 change: 1 addition & 0 deletions Common/build.gradle.kts
Expand Up @@ -21,6 +21,7 @@ base {

minecraft {
version(minecraftVersion)
accessWideners(project.file("src/main/resources/${modId}.accesswidener"))
runs {
client("vanilla_client") {
workingDirectory(project.file("run"))
Expand Down
@@ -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 Common/src/main/java/com/blamejared/tipthescales/ScaleHelper.java

This file was deleted.

@@ -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);

}
@@ -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) -> {
}));
}

}
@@ -1,5 +1,7 @@
package com.blamejared.tipthescales.mixin;

import com.mojang.math.Vector3d;
import com.mojang.math.Vector3f;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
Expand Down
@@ -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) {}


}

This file was deleted.

This file was deleted.

5 changes: 5 additions & 0 deletions Common/src/main/resources/tipthescales.accesswidener
@@ -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

10 changes: 6 additions & 4 deletions Common/src/main/resources/tipthescales.mixins.json
Expand Up @@ -5,12 +5,14 @@
"compatibilityLevel": "JAVA_17",
"plugin": "com.blamejared.tipthescales.mixin.MixinPlugin",
"client": [
"MixinVideoSettingsScreen",
"OptionAccessor",
"VideoSettingsScreenAccessor"
"MixinMinecraft",
"MixinVideoSettingsScreen"
],
"injectors": {
"defaultRequire": 1
},
"refmap": "${refmap_target}refmap.json"
"refmap": "${refmap_target}refmap.json",
"mixins": [
"AccessOptions"
]
}
3 changes: 2 additions & 1 deletion Fabric/build.gradle.kts
Expand Up @@ -4,7 +4,7 @@ import net.darkhax.curseforgegradle.Constants as CFG_Constants

plugins {
`maven-publish`
id("fabric-loom") version "0.10-SNAPSHOT"
id("fabric-loom") version "0.12-SNAPSHOT"
id("com.blamejared.modtemplate")
id("net.darkhax.curseforgegradle") version ("1.0.8")
}
Expand Down Expand Up @@ -37,6 +37,7 @@ dependencies {
}

loom {
accessWidenerPath.set(project(":Common").file("src/main/resources/${modId}.accesswidener"))
runs {
named("client") {
client()
Expand Down
@@ -1,5 +1,5 @@
package com.blamejared.tipthescales;

public class TipTheScalesFabric {

}
6 changes: 4 additions & 2 deletions Fabric/src/main/resources/fabric.mod.json
Expand Up @@ -11,15 +11,17 @@
"homepage": "https://minecraft.curseforge.com/projects/tiptthescales",
"sources": "https://github.com/jaredlll08/tipthescales"
},
"entrypoints": {
},
"license": "MIT",
"icon": "assets/tipthescales/icon.png",
"environment": "*",
"mixins": [
"tipthescales.mixins.json"
],
"depends": {
"fabricloader": ">=0.13",
"minecraft": "1.18.x",
"fabricloader": ">=0.14",
"minecraft": "1.19.x",
"java": ">=17"
}
}
2 changes: 1 addition & 1 deletion Forge/build.gradle.kts
Expand Up @@ -45,7 +45,7 @@ mixin {

minecraft {
mappings("official", minecraftVersion)

accessTransformer(file("src/main/resources/META-INF/accesstransformer.cfg"))
runs {
create("client") {
workingDirectory(project.file("run"))
Expand Down
3 changes: 3 additions & 0 deletions Forge/src/main/resources/META-INF/accesstransformer.cfg
@@ -0,0 +1,3 @@
public net.minecraft.client.OptionInstance$ValueSet
public net.minecraft.client.OptionInstance$IntRangeBase
public net.minecraft.client.OptionInstance$SliderableOrCyclableValueSet
2 changes: 1 addition & 1 deletion Forge/src/main/resources/META-INF/mods.toml
Expand Up @@ -7,7 +7,7 @@ version = "${file.jarVersion}"
displayName = "TipTheScales"
authors = "Jaredlll08"
logoFile="icon.png"
updateJSONURL = "https://updates.blamejared.com/get?n=TipTheScales&gv=1.18.2"
updateJSONURL = "https://updates.blamejared.com/get?n=TipTheScales&gv=1.19"
description = '''
Allows for more control when adjusting the GUI size.
'''
8 changes: 4 additions & 4 deletions gradle.properties
@@ -1,16 +1,16 @@
# Project
modVersion=5.0
modVersion=6.0
group=com.blamejared.tipthescales
modJavaVersion=17

# Common
minecraftVersion=1.18.2
minecraftVersion=1.19

# Forge
forgeVersion=40.0.1
forgeVersion=41.0.1

# Fabric
fabricLoaderVersion=0.13.3
fabricLoaderVersion=0.14.7

# Mod options
modName=TipTheScales
Expand Down

0 comments on commit ff7d340

Please sign in to comment.