Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleOptionMixin Update and fix Random Sneaking issue #3145

Merged
merged 3 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
@Shadow T value;
public class SimpleOptionMixin implements ISimpleOption {
@Shadow Object value;
@Shadow @Final private Consumer<Object> changeCallback;

@Shadow @Final
private Consumer<T> 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<Codec<T>> info) {
GameOptions options = MinecraftClient.getInstance().options;
if (options == null) return;

if ((Object) this == options.getGamma()) {
info.setReturnValue((Codec<T>) Codec.DOUBLE);
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,7 +21,7 @@ public FOVCommand() {
@Override
public void build(LiteralArgumentBuilder<CommandSource> 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;
}));
}
Expand Down