Update for 1.19

This commit is contained in:
Johannes Frohnmeyer 2022-06-07 22:19:58 +02:00
parent 3b838996be
commit 078010a0ca
Signed by: Johannes
GPG Key ID: E76429612C2929F4
12 changed files with 106 additions and 47 deletions

View File

@ -1,3 +1,5 @@
Slyde allow setting values for options that were not intended by mojang (for example: ridiculous fov effects, gamma, render distance) Slyde allow setting values for options that were not intended by mojang (for example: ridiculous fov effects, gamma, render distance)
This will (obviously) break things if you are not careful (for example: changing the target resolution outside its slider will cause a crash) This will (obviously) break things if you are not careful (for example: changing the target resolution outside its slider will cause a crash)
To achieve this result, Slyde not only modifies the widgets, but also the relevant options code using a solution based on [FiveOneFourOneEight by apple502j](https://github.com/apple502j/FiveOneFourOneEight)

View File

@ -1,21 +1,21 @@
apply from: "https://jfmods.gitlab.io/scripts/jfmod.gradle" apply from: "https://jfmods.gitlab.io/scripts/jfmod.gradle"
loom {
accessWidenerPath = file("src/main/resources/slyde.accesswidener")
}
repositories { repositories {
maven { url 'https://api.modrinth.com/maven' } maven { url 'https://api.modrinth.com/maven' }
} }
dependencies { dependencies {
// For testing in dev environment // For testing in dev environment
modRuntimeOnly "net.fabricmc.fabric-api:fabric-api:0.47.8+1.18.2" modRuntimeOnly "net.fabricmc.fabric-api:fabric-api:0.55.1+1.19"
modRuntimeOnly modCompileOnly("maven.modrinth:sodium:mc1.18.2-0.4.1") modCompileOnly("maven.modrinth:sodium:mc1.19-0.4.2")
include modImplementation("io.gitlab.jfronny.libjf:libjf-config-v0:${project.jfapi_version}") modImplementation("io.gitlab.jfronny.libjf:libjf-config-v0:${project.jfapi_version}")
include("io.gitlab.jfronny.libjf:libjf-unsafe-v0:${project.jfapi_version}")
include("io.gitlab.jfronny.libjf:libjf-base:${project.jfapi_version}")
modRuntimeOnly("io.gitlab.jfronny.libjf:libjf-devutil-v0:${project.jfapi_version}") modRuntimeOnly("io.gitlab.jfronny.libjf:libjf-devutil-v0:${project.jfapi_version}")
modImplementation "com.terraformersmc:modmenu:3.1.0" modImplementation "com.terraformersmc:modmenu:4.0.0-beta.4"
include modRuntimeOnly('io.gitlab.jfronny:gson:2.9.0.2022.4.2.19.45.43') // Dependency of LibJF 2.7.0
} }

View File

@ -1,13 +1,15 @@
# https://fabricmc.net/develop/ # https://fabricmc.net/develop/
minecraft_version=1.18.2 minecraft_version=1.19
yarn_mappings=build.2 yarn_mappings=build.1
loader_version=0.13.3 loader_version=0.14.6
maven_group=io.gitlab.jfronny maven_group=io.gitlab.jfronny
archives_base_name=Slyde archives_base_name=Slyde
jfapi_version=2.7.1 jfapi_version=2.9.1
modrinth_id=diCZrsch modrinth_id=diCZrsch
modrinth_required_dependencies=WKwQAwke
modrinth_optional_dependencies=mOgUt4GM modrinth_optional_dependencies=mOgUt4GM
curseforge_id=411386 curseforge_id=411386
curseforge_required_dependencies=libjf
curseforge_optional_dependencies=modmenu curseforge_optional_dependencies=modmenu

View File

@ -1,24 +0,0 @@
package io.gitlab.jfronny.slyde.mixin;
import net.minecraft.client.option.DoubleOption;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(DoubleOption.class)
public class DoubleOptionMixin {
@Redirect(method = "getRatio(D)D", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(DDD)D"))
private double getRatioClamp(double value, double min, double max) {
return value;
}
@Redirect(method = "getValue(D)D", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(DDD)D"))
private double getValueClamp(double value, double min, double max) {
return value;
}
@Redirect(method = "adjust(D)D", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(DDD)D"))
private double adjustClamp(double value, double min, double max) {
return value;
}
}

View File

@ -0,0 +1,22 @@
package io.gitlab.jfronny.slyde.mixin;
import com.mojang.serialization.*;
import net.minecraft.client.option.*;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.*;
import java.util.*;
@Mixin(SimpleOption.DoubleSliderCallbacks.class)
public class DoubleSliderCallbacksMixin {
@Redirect(method = "codec", at = @At(value = "INVOKE", target = "Lcom/mojang/serialization/Codec;doubleRange(DD)Lcom/mojang/serialization/Codec;", remap = false))
private Codec<Double> slyde$returnRangelessCodec(double minInclusive, double maxInclusive) {
return Codec.DOUBLE;
}
@Inject(method = "validate(Ljava/lang/Double;)Ljava/util/Optional;", at = @At("HEAD"), cancellable = true)
private void slyde$skipValidate(Double double_, CallbackInfoReturnable<Optional<Double>> cir) {
cir.setReturnValue(Optional.of(double_));
}
}

View File

@ -0,0 +1,30 @@
package io.gitlab.jfronny.slyde.mixin;
import net.minecraft.client.*;
import net.minecraft.client.option.*;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;
import java.util.*;
import java.util.function.*;
@Mixin(targets = "net.minecraft.client.option.GameOptions$2")
public class GameOptionsMixin {
@Redirect(method = "accept", at = @At(value = "INVOKE", target = "Ljava/util/Optional;ifPresent(Ljava/util/function/Consumer;)V", ordinal = 1))
private <T> void slyde$replaceSetter(Optional<T> value, Consumer<T> originalSetter, String key, SimpleOption<T> option) {
value.ifPresent((realValue) -> {
if (option.getCallbacks() instanceof SimpleOption.SliderCallbacks) {
if (!MinecraftClient.getInstance().isRunning()) {
option.value = realValue;
return;
}
if (!Objects.equals(option.getValue(), realValue)) {
option.value = realValue;
option.changeCallback.accept(realValue);
}
return;
}
originalSetter.accept(realValue);
});
}
}

View File

@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(SliderWidget.class) @Mixin(SliderWidget.class)
public abstract class SliderWidgetMixin { public abstract class SliderWidgetMixin {
@Redirect(method = "setValue(D)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(DDD)D")) @Redirect(method = "setValue(D)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(DDD)D"))
private double adjustClamp(double value, double min, double max) { private double slyde$adjustClamp(double value, double min, double max) {
return Slyde.isActive() ? value : MathHelper.clamp(value, min, max); return Slyde.isActive() ? value : MathHelper.clamp(value, min, max);
} }
} }

View File

@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(targets = "me.jellysquid.mods.sodium.client.gui.options.control.SliderControl$Button") @Mixin(targets = "me.jellysquid.mods.sodium.client.gui.options.control.SliderControl$Button")
public abstract class SodiumSliderControlMixin { public abstract class SodiumSliderControlMixin {
@Redirect(method = "setValue(D)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(DDD)D")) @Redirect(method = "setValue(D)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/MathHelper;clamp(DDD)D"))
private double adjustClamp(double value, double min, double max) { private double slyde$adjustClamp(double value, double min, double max) {
return Slyde.isActive() ? value : MathHelper.clamp(value, min, max); return Slyde.isActive() ? value : MathHelper.clamp(value, min, max);
} }
} }

View File

@ -0,0 +1,22 @@
package io.gitlab.jfronny.slyde.mixin;
import com.mojang.serialization.*;
import net.minecraft.client.option.*;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.*;
import java.util.*;
@Mixin(SimpleOption.ValidatingIntSliderCallbacks.class)
public class ValidatingIntSliderCallbacksMixin {
@Inject(method = "codec()Lcom/mojang/serialization/Codec;", at = @At("HEAD"), cancellable = true)
private void slyde$returnRangelessCodec(CallbackInfoReturnable<Codec<Integer>> cir) {
cir.setReturnValue(Codec.INT);
}
@Inject(method = "validate(Ljava/lang/Integer;)Ljava/util/Optional;", at = @At("HEAD"), cancellable = true)
private void slyde$skipValidate(Integer integer, CallbackInfoReturnable<Optional<Integer>> cir) {
cir.setReturnValue(Optional.of(integer));
}
}

View File

@ -15,13 +15,12 @@
"license": "MIT", "license": "MIT",
"environment": "*", "environment": "*",
"entrypoints": { "entrypoints": {
"libjf:config": [ "libjf:config": ["io.gitlab.jfronny.slyde.Cfg"]
"io.gitlab.jfronny.slyde.Cfg"
]
}, },
"mixins": [ "mixins": [
"slyde.mixins.json" "slyde.mixins.json"
], ],
"accessWidener": "slyde.accesswidener",
"depends": { "depends": {
"fabricloader": ">=0.12.0", "fabricloader": ">=0.12.0",
"minecraft": "*", "minecraft": "*",

View File

@ -0,0 +1,6 @@
accessWidener v2 named
accessible class net/minecraft/client/option/SimpleOption$SliderCallbacks
accessible field net/minecraft/client/option/SimpleOption value Ljava/lang/Object;
accessible field net/minecraft/client/option/SimpleOption changeCallback Ljava/util/function/Consumer;

View File

@ -2,14 +2,14 @@
"required": true, "required": true,
"minVersion": "0.8", "minVersion": "0.8",
"package": "io.gitlab.jfronny.slyde.mixin", "package": "io.gitlab.jfronny.slyde.mixin",
"compatibilityLevel": "JAVA_14", "compatibilityLevel": "JAVA_17",
"plugin": "io.gitlab.jfronny.slyde.Plugin", "plugin": "io.gitlab.jfronny.slyde.Plugin",
"mixins": [
],
"client": [ "client": [
"DoubleOptionMixin", "DoubleSliderCallbacksMixin",
"GameOptionsMixin",
"SliderWidgetMixin", "SliderWidgetMixin",
"SodiumSliderControlMixin" "SodiumSliderControlMixin",
"ValidatingIntSliderCallbacksMixin"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1