MixinControlsOptionsScreen.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package me.shedaniel.clothconfig2.mixin;
  2. import me.shedaniel.clothconfig2.api.FakeModifierKeyCodeAdder;
  3. import me.shedaniel.clothconfig2.impl.FakeKeyBindings;
  4. import me.shedaniel.clothconfig2.impl.GameOptionsHooks;
  5. import net.minecraft.client.gui.screen.Screen;
  6. import net.minecraft.client.gui.screen.options.ControlsOptionsScreen;
  7. import net.minecraft.client.gui.screen.options.GameOptionsScreen;
  8. import net.minecraft.client.options.GameOptions;
  9. import net.minecraft.client.options.KeyBinding;
  10. import net.minecraft.text.Text;
  11. import org.spongepowered.asm.mixin.Mixin;
  12. import org.spongepowered.asm.mixin.injection.At;
  13. import org.spongepowered.asm.mixin.injection.Inject;
  14. import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
  15. import java.util.ArrayList;
  16. import java.util.List;
  17. @Mixin(ControlsOptionsScreen.class)
  18. public class MixinControlsOptionsScreen extends GameOptionsScreen {
  19. public MixinControlsOptionsScreen(Screen screen_1, GameOptions gameOptions_1, Text text_1) {
  20. super(screen_1, gameOptions_1, text_1);
  21. }
  22. @Inject(method = "init()V", at = @At("HEAD"))
  23. private void initHead(CallbackInfo info) {
  24. List<KeyBinding> newKeysAll = new ArrayList<>();
  25. KeyBinding[] var3 = client.options.keysAll;
  26. for (KeyBinding binding : var3) {
  27. if (!(binding instanceof FakeKeyBindings)) {
  28. newKeysAll.add(binding);
  29. }
  30. }
  31. newKeysAll.addAll(FakeModifierKeyCodeAdder.INSTANCE.getFakeBindings());
  32. ((GameOptionsHooks) client.options).cloth_setKeysAll(newKeysAll.toArray(new KeyBinding[0]));
  33. }
  34. @Inject(method = "init()V", at = @At("RETURN"))
  35. private void initReturn(CallbackInfo info) {
  36. List<KeyBinding> newKeysAll = new ArrayList<>();
  37. KeyBinding[] var3 = client.options.keysAll;
  38. for (KeyBinding binding : var3) {
  39. if (!(binding instanceof FakeKeyBindings)) {
  40. newKeysAll.add(binding);
  41. }
  42. }
  43. ((GameOptionsHooks) client.options).cloth_setKeysAll(newKeysAll.toArray(new KeyBinding[0]));
  44. }
  45. }