Search in sources :

Example 1 with OptionsAccessor

use of com.wynntils.mc.mixin.accessors.OptionsAccessor in project Artemis by Wynntils.

the class KeyManager method registerKeybind.

public static void registerKeybind(KeyHolder toAdd) {
    if (hasName(toAdd.getName())) {
        throw new IllegalStateException("Can not add " + toAdd + " since the name already exists");
    }
    keyHolders.add(toAdd);
    Options options = Minecraft.getInstance().options;
    if (options == null) {
        // loaded later by a mixin
        return;
    }
    synchronized (options) {
        KeyMapping[] keyMappings = options.keyMappings;
        List<KeyMapping> newKeyMappings = Lists.newArrayList(keyMappings);
        newKeyMappings.add(toAdd.getKeybind());
        ((OptionsAccessor) options).setKeyBindMixins(newKeyMappings.toArray(new KeyMapping[0]));
    }
}
Also used : Options(net.minecraft.client.Options) KeyMapping(net.minecraft.client.KeyMapping) OptionsAccessor(com.wynntils.mc.mixin.accessors.OptionsAccessor)

Example 2 with OptionsAccessor

use of com.wynntils.mc.mixin.accessors.OptionsAccessor in project Artemis by Wynntils.

the class KeyManager method unregisterKeybind.

public static void unregisterKeybind(KeyHolder toAdd) {
    if (keyHolders.remove(toAdd)) {
        Options options = Minecraft.getInstance().options;
        synchronized (options) {
            KeyMapping[] keyMappings = options.keyMappings;
            List<KeyMapping> newKeyMappings = Lists.newArrayList(keyMappings);
            newKeyMappings.remove(toAdd.getKeybind());
            ((OptionsAccessor) options).setKeyBindMixins(newKeyMappings.toArray(new KeyMapping[0]));
        }
    }
}
Also used : Options(net.minecraft.client.Options) KeyMapping(net.minecraft.client.KeyMapping) OptionsAccessor(com.wynntils.mc.mixin.accessors.OptionsAccessor)

Aggregations

OptionsAccessor (com.wynntils.mc.mixin.accessors.OptionsAccessor)2 KeyMapping (net.minecraft.client.KeyMapping)2 Options (net.minecraft.client.Options)2