2022-06-07 22:19:58 +02:00
|
|
|
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) {
|
2023-03-14 19:31:01 +01:00
|
|
|
value.ifPresent(realValue -> {
|
2022-06-07 22:19:58 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|