From 3365571776dde9e90c1a129633eb9fd89d2c26e3 Mon Sep 17 00:00:00 2001 From: Soda5601 <62250232+ThebestkillerTBK@users.noreply.github.com> Date: Tue, 17 Jan 2023 02:16:35 +0800 Subject: [PATCH] SimpleOptionMixin Update and fix Random Sneaking issue (#3145) --- .../meteorclient/mixin/SimpleOptionMixin.java | 45 +++++-------------- .../mixininterface/ISimpleOption.java | 10 +++++ .../systems/commands/commands/FOVCommand.java | 3 +- 3 files changed, 24 insertions(+), 34 deletions(-) create mode 100644 src/main/java/meteordevelopment/meteorclient/mixininterface/ISimpleOption.java diff --git a/src/main/java/meteordevelopment/meteorclient/mixin/SimpleOptionMixin.java b/src/main/java/meteordevelopment/meteorclient/mixin/SimpleOptionMixin.java index 8579431bd4..ee22308152 100644 --- a/src/main/java/meteordevelopment/meteorclient/mixin/SimpleOptionMixin.java +++ b/src/main/java/meteordevelopment/meteorclient/mixin/SimpleOptionMixin.java @@ -5,51 +5,30 @@ package meteordevelopment.meteorclient.mixin; -import com.mojang.serialization.Codec; +import meteordevelopment.meteorclient.mixininterface.ISimpleOption; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.option.GameOptions; import net.minecraft.client.option.SimpleOption; 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; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.Objects; import java.util.function.Consumer; @Mixin(SimpleOption.class) -public class SimpleOptionMixin { - @Shadow T value; +public class SimpleOptionMixin implements ISimpleOption { + @Shadow Object value; + @Shadow @Final private Consumer changeCallback; - @Shadow @Final - private Consumer changeCallback; - - @Inject(method = "setValue", at = @At("HEAD"), cancellable = true) - private void onSetValue(T value, CallbackInfo info) { - GameOptions options = MinecraftClient.getInstance().options; - if (options == null) return; - - if ((Object) this == options.getGamma() || (Object) this == options.getFov()) { + @Override + public void set(Object value) { + if (!MinecraftClient.getInstance().isRunning()) { this.value = value; - - if (MinecraftClient.getInstance().isRunning()) { - changeCallback.accept(value); + } else { + if (!Objects.equals(this.value, value)) { + this.value = value; + this.changeCallback.accept(this.value); } - - info.cancel(); - } - } - - @SuppressWarnings("unchecked") - @Inject(method = "getCodec", at = @At("HEAD"), cancellable = true) - public void onGetCodec(CallbackInfoReturnable> info) { - GameOptions options = MinecraftClient.getInstance().options; - if (options == null) return; - - if ((Object) this == options.getGamma()) { - info.setReturnValue((Codec) Codec.DOUBLE); } } } diff --git a/src/main/java/meteordevelopment/meteorclient/mixininterface/ISimpleOption.java b/src/main/java/meteordevelopment/meteorclient/mixininterface/ISimpleOption.java new file mode 100644 index 0000000000..12ebbebd21 --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/mixininterface/ISimpleOption.java @@ -0,0 +1,10 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.mixininterface; + +public interface ISimpleOption { + void set(Object value); +} diff --git a/src/main/java/meteordevelopment/meteorclient/systems/commands/commands/FOVCommand.java b/src/main/java/meteordevelopment/meteorclient/systems/commands/commands/FOVCommand.java index 1ed59250fe..0d7e9aeaae 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/commands/commands/FOVCommand.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/commands/commands/FOVCommand.java @@ -7,6 +7,7 @@ import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import meteordevelopment.meteorclient.mixininterface.ISimpleOption; import meteordevelopment.meteorclient.systems.commands.Command; import net.minecraft.command.CommandSource; @@ -20,7 +21,7 @@ public FOVCommand() { @Override public void build(LiteralArgumentBuilder builder) { builder.then(argument("fov", IntegerArgumentType.integer(0, 180)).executes(context -> { - mc.options.getFov().setValue(context.getArgument("fov", Integer.class)); + ((ISimpleOption) (Object) mc.options.getFov()).set(context.getArgument("fov", Integer.class)); return SINGLE_SUCCESS; })); }