コード例 #1
0
  // call this when there is a possibility of a key change
  public static void checkIfBindingsNeedUpdating() {
    if (joyNo < 0) return;

    for (Map.Entry<String, ControllerBinding> entry : joyBindingsMap.entrySet()) {
      if (entry.getValue().inputEvent.isValid()
          && entry.getValue().keyCodes != null
          && entry.getValue().keyCodes.length >= 1
          && !entry.getKey().contains("user.")) {
        KeyBinding kb = McKeyBindHelper.getMinecraftKeyBind(entry.getKey());
        if (kb == null && entry.getKey().contains("joy."))
          kb = McKeyBindHelper.getMinecraftKeyBind(entry.getKey().replace("joy.", "key."));
        if (kb != null) {
          int keyCode = McObfuscationHelper.keyCode(kb);
          if (entry.getValue().keyCodes[0] != keyCode) {
            entry.getValue().keyCodes = new int[] {keyCode};
            setControllerBinding(joyNo, entry.getKey(), entry.getValue());
          }
        }
      }
    }
  }
コード例 #2
0
  public static void setDefaultJoyBindingMap(int joyIndex, boolean updateWithConfigFile) {
    if (currentDisplayedMap == joyIndex) {
      LogHelper.Info(
          "Skipping setting up the joybinding map as it is already set up for this joypad");
      return;
    }

    currentDisplayedMap = joyIndex;

    GameSettings settings = Minecraft.getMinecraft().gameSettings;
    LogHelper.Info("Setting default joy binding map");

    joyBindingsMap.clear();

    int yAxisIndex = ControllerUtils.findYAxisIndex(joyIndex);
    int xAxisIndex = ControllerUtils.findXAxisIndex(joyIndex);

    joyBindingsMap.put(
        "joy.jump",
        new ControllerBinding(
            "joy.jump",
            "Jump",
            new ButtonInputEvent(joyIndex, 0, 1),
            new int[] {McObfuscationHelper.keyCode(settings.keyBindJump)},
            0,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_MOVEMENT)));

    joyBindingsMap.put(
        "joy.inventory",
        new ControllerBinding(
            "joy.inventory",
            "Open inventory",
            new ButtonInputEvent(joyIndex, 3, 1),
            new int[] {McObfuscationHelper.keyCode(settings.keyBindInventory)},
            100,
            EnumSet.of(BindingOptions.GAME_BINDING, BindingOptions.CATEGORY_INVENTORY)));

    joyBindingsMap.put(
        "joy.drop",
        new ControllerBinding(
            "joy.drop",
            "Drop",
            new ButtonInputEvent(joyIndex, 6, 1),
            new int[] {McObfuscationHelper.keyCode(settings.keyBindDrop)},
            0,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_GAMEPLAY)));

    joyBindingsMap.put(
        "joy.sneak",
        new ControllerBinding(
            "joy.sneak",
            "Sneak",
            new ButtonInputEvent(joyIndex, 8, 1),
            new int[] {McObfuscationHelper.keyCode(settings.keyBindSneak)},
            0,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_MOVEMENT)));

    joyBindingsMap.put(
        "joy.attack",
        new ControllerBinding(
            "joy.attack",
            "Attack",
            new AxisInputEvent(joyIndex, 4, defaultAxisThreshhold * -1, defaultAxisDeadZone),
            new int[] {-100},
            0,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_GAMEPLAY)));

    joyBindingsMap.put(
        "joy.use",
        new ControllerBinding(
            "joy.use",
            "Use",
            new AxisInputEvent(joyIndex, 4, defaultAxisThreshhold, defaultAxisDeadZone),
            new int[] {-99},
            0,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_GAMEPLAY)));

    joyBindingsMap.put(
        "joy.interact",
        new ControllerBinding(
            "joy.interact",
            "Interact",
            new ButtonInputEvent(joyIndex, 2, 1),
            new int[] {-99},
            0,
            EnumSet.of(BindingOptions.GAME_BINDING, BindingOptions.CATEGORY_GAMEPLAY)));

    joyBindingsMap.put(
        "joy.guiLeftClick",
        new ControllerBinding(
            "joy.guiLeftClick",
            "Left click",
            new ButtonInputEvent(joyIndex, 0, 1),
            new int[] {-100},
            0,
            EnumSet.of(BindingOptions.MENU_BINDING, BindingOptions.CATEGORY_UI)));

    joyBindingsMap.put(
        "joy.guiRightClick",
        new ControllerBinding(
            "joy.guiRightClick",
            "Right click",
            new ButtonInputEvent(joyIndex, 2, 1),
            new int[] {-99},
            0,
            EnumSet.of(BindingOptions.MENU_BINDING, BindingOptions.CATEGORY_UI)));

    joyBindingsMap.put(
        "joy.prevItem",
        new ControllerBinding(
            "joy.prevItem",
            "Previous item",
            new ButtonInputEvent(joyIndex, 4, 1),
            new int[] {-199},
            0,
            EnumSet.of(BindingOptions.GAME_BINDING, BindingOptions.CATEGORY_GAMEPLAY)));

    joyBindingsMap.put(
        "joy.nextItem",
        new ControllerBinding(
            "joy.nextItem",
            "Next item",
            new ButtonInputEvent(joyIndex, 5, 1),
            new int[] {-201},
            0,
            EnumSet.of(BindingOptions.GAME_BINDING, BindingOptions.CATEGORY_GAMEPLAY)));

    joyBindingsMap.put(
        "joy.sprint",
        new ControllerBinding(
            "joy.sprint",
            "Sprint",
            new ButtonInputEvent(joyIndex, 9, 1),
            new int[] {Keyboard.KEY_LCONTROL},
            0,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_GAMEPLAY)));

    joyBindingsMap.put(
        "joy.menu",
        new ControllerBinding(
            "joy.menu",
            "Open menu",
            new ButtonInputEvent(joyIndex, 7, 1),
            new int[] {Keyboard.KEY_ESCAPE},
            0,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.MENU_BINDING,
                BindingOptions.CATEGORY_MISC)));

    joyBindingsMap.put(
        "joy.shiftClick",
        new ControllerBinding(
            "joy.shiftClick",
            "Shift-click",
            new ButtonInputEvent(joyIndex, 1, 1),
            new int[] {Keyboard.KEY_LSHIFT, -100},
            0,
            EnumSet.of(
                BindingOptions.MENU_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_INVENTORY)));

    joyBindingsMap.put(
        "joy.cameraX+",
        new ControllerBinding(
            "joy.cameraX+",
            "Look right",
            new AxisInputEvent(
                joyIndex, xAxisIndex + 2, defaultAxisThreshhold, defaultAxisDeadZone),
            null,
            0,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_GAMEPLAY)));

    joyBindingsMap.put(
        "joy.cameraX-",
        new ControllerBinding(
            "joy.cameraX-",
            "Look left",
            new AxisInputEvent(
                joyIndex, xAxisIndex + 2, defaultAxisThreshhold * -1, defaultAxisDeadZone),
            null,
            0,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_GAMEPLAY)));

    joyBindingsMap.put(
        "joy.cameraY-",
        new ControllerBinding(
            "joy.cameraY-",
            "Look up",
            new AxisInputEvent(
                joyIndex, xAxisIndex + 1, defaultAxisThreshhold * -1, defaultAxisDeadZone),
            null,
            0,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_GAMEPLAY)));

    joyBindingsMap.put(
        "joy.cameraY+",
        new ControllerBinding(
            "joy.cameraY+",
            "Look down",
            new AxisInputEvent(
                joyIndex, xAxisIndex + 1, defaultAxisThreshhold, defaultAxisDeadZone),
            null,
            0,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_GAMEPLAY)));

    joyBindingsMap.put(
        "joy.right",
        new ControllerBinding(
            "joy.right",
            "Strafe right",
            new AxisInputEvent(joyIndex, xAxisIndex, defaultAxisThreshhold, defaultAxisDeadZone),
            new int[] {McObfuscationHelper.keyCode(settings.keyBindRight)},
            0,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_MOVEMENT)));

    joyBindingsMap.put(
        "joy.left",
        new ControllerBinding(
            "joy.left",
            "Strafe left",
            new AxisInputEvent(
                joyIndex, xAxisIndex, defaultAxisThreshhold * -1, defaultAxisDeadZone),
            new int[] {McObfuscationHelper.keyCode(settings.keyBindLeft)},
            0,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_MOVEMENT)));

    joyBindingsMap.put(
        "joy.back",
        new ControllerBinding(
            "joy.back",
            "Move backward",
            new AxisInputEvent(joyIndex, yAxisIndex, defaultAxisThreshhold, defaultAxisDeadZone),
            new int[] {McObfuscationHelper.keyCode(settings.keyBindBack)},
            yAxisIndex,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_MOVEMENT)));

    joyBindingsMap.put(
        "joy.forward",
        new ControllerBinding(
            "joy.forward",
            "Move forward",
            new AxisInputEvent(
                joyIndex, yAxisIndex, defaultAxisThreshhold * -1, defaultAxisDeadZone),
            new int[] {McObfuscationHelper.keyCode(settings.keyBindForward)},
            0,
            EnumSet.of(
                BindingOptions.GAME_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_MOVEMENT)));

    joyBindingsMap.put(
        "joy.guiX+",
        new ControllerBinding(
            "joy.guiX+",
            "GUI right",
            new AxisInputEvent(joyIndex, xAxisIndex, defaultAxisThreshhold, defaultAxisDeadZone),
            null,
            0,
            EnumSet.of(
                BindingOptions.MENU_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_UI)));

    joyBindingsMap.put(
        "joy.guiX-",
        new ControllerBinding(
            "joy.guiX-",
            "GUI left",
            new AxisInputEvent(
                joyIndex, xAxisIndex, defaultAxisThreshhold * -1, defaultAxisDeadZone),
            null,
            0,
            EnumSet.of(
                BindingOptions.MENU_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_UI)));

    joyBindingsMap.put(
        "joy.guiY+",
        new ControllerBinding(
            "joy.guiY+",
            "GUI down",
            new AxisInputEvent(joyIndex, yAxisIndex, defaultAxisThreshhold, defaultAxisDeadZone),
            null,
            0,
            EnumSet.of(
                BindingOptions.MENU_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_UI)));

    joyBindingsMap.put(
        "joy.guiY-",
        new ControllerBinding(
            "joy.guiY-",
            "GUI up",
            new AxisInputEvent(
                joyIndex, yAxisIndex, defaultAxisThreshhold * -1, defaultAxisDeadZone),
            null,
            0,
            EnumSet.of(
                BindingOptions.MENU_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.CATEGORY_UI)));

    joyBindingsMap.put(
        "joy.closeInventory",
        new ControllerBinding(
            "joy.closeInventory",
            "Close container",
            new ButtonInputEvent(joyIndex, 3, 1),
            new int[] {McObfuscationHelper.keyCode(settings.keyBindInventory)},
            100,
            EnumSet.of(BindingOptions.MENU_BINDING, BindingOptions.CATEGORY_INVENTORY)));

    joyBindingsMap.put(
        "joy.scrollDown",
        new ControllerBinding(
            "joy.scrollDown",
            "Scroll down",
            new ButtonInputEvent(joyIndex, 5, 1),
            new int[] {-201},
            scrollDelay,
            EnumSet.of(
                BindingOptions.MENU_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.RENDER_TICK,
                BindingOptions.CATEGORY_UI)));

    joyBindingsMap.put(
        "joy.scrollUp",
        new ControllerBinding(
            "joy.scrollUp",
            "Scroll up",
            new ButtonInputEvent(joyIndex, 4, 1),
            new int[] {-199},
            scrollDelay,
            EnumSet.of(
                BindingOptions.MENU_BINDING,
                BindingOptions.REPEAT_IF_HELD,
                BindingOptions.RENDER_TICK,
                BindingOptions.CATEGORY_UI)));

    if (updateWithConfigFile)
      config.getJoypadSavedBindings(joyIndex, Controllers.getController(joyIndex).getName());

    List<ControllerBinding> userBindings = config.getUserDefinedBindings(joyIndex);

    for (ControllerBinding b : userBindings) {
      joyBindingsMap.put(b.inputString, b);
    }
  }