Skip to content

Commit

Permalink
SimpleOptionMixin Update and fix Random Sneaking issue (MeteorDevelop…
Browse files Browse the repository at this point in the history
  • Loading branch information
hexadecimal233 authored Jan 16, 2023
1 parent 52d2d4a commit 3365571
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 34 deletions.
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

0 comments on commit 3365571

Please sign in to comment.