aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hype/bbsentials/mixins/SimpleOptionMixin.java
blob: 50cbac5d596b6b64c71920e394386c538b15e1cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package de.hype.bbsentials.mixins;

import de.hype.bbsentials.api.ISimpleOption;
import net.minecraft.client.MinecraftClient;
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 java.util.Objects;
import java.util.function.Consumer;

@Mixin(SimpleOption.class)
public class SimpleOptionMixin implements ISimpleOption {
    @Shadow
    Object value;
    @Shadow
    @Final
    private Consumer<Object> changeCallback;

    @Override
    public void set(Object value) {
        if (!MinecraftClient.getInstance().isRunning()) {
            this.value = value;
        }
        else {
            if (!Objects.equals(this.value, value)) {
                System.out.println("used mixin");
                this.value = value;
                this.changeCallback.accept(this.value);
            }
        }
    }
}