Ejemplo n.º 1
0
  static void pollDevices() {
    // Poll the input devices while we're here
    if (Mouse.isCreated()) {
      Mouse.poll();
      Mouse.updateCursor();
    }

    if (Keyboard.isCreated()) {
      Keyboard.poll();
    }

    if (Controllers.isCreated()) {
      Controllers.poll();
    }
  }
  public static boolean setController(int controllerNo) {
    LogHelper.Info("Attempting to use controller " + controllerNo);
    try {
      if (!Controllers.isCreated()) Controllers.create();

      LogHelper.Info("Controllers.getControllerCount == " + Controllers.getControllerCount());

      if (controllerNo < 0 || controllerNo >= Controllers.getControllerCount()) {
        LogHelper.Error(
            "Attempting to set controller index "
                + controllerNo
                + " there are currently "
                + Controllers.getControllerCount()
                + " controllers detected.");
        return false;
      }

      ControllerSettings.setDefaultJoyBindingMap(controllerNo, true);
      joyNo = controllerNo;
      controllerUtils.printDeadZones(Controllers.getController(controllerNo));
      inputEnabled = true;

      applySavedDeadZones(joyNo);

      config.updatePreferedJoy(controllerNo, Controllers.getController(controllerNo).getName());

      Minecraft.getMinecraft().gameSettings.pauseOnLostFocus = false;
      JoypadMouse.AxisReader.centerCrosshairs();
      checkIfBindingsNeedUpdating();
      unpressAll();
      return true;
    } catch (Exception e) {
      LogHelper.Error("Couldn't initialize Controllers: " + e.toString());
      inputEnabled = false;
    }
    return false;
  }
  private int detectControllers() {
    validControllers.clear();
    inValidControllers.clear();

    try {
      if (!Controllers.isCreated()) Controllers.create();

      if (Controllers.getControllerCount() > 0) {
        LogHelper.Info("Found " + Controllers.getControllerCount() + " controller(s) in total.");
        for (int joyIndex = 0; joyIndex < Controllers.getControllerCount(); joyIndex++) {
          Controller thisController = Controllers.getController(joyIndex);

          logControllerInfo(thisController);

          if (controllerUtils.meetsInputRequirements(
              thisController, requiredButtonCount, requiredMinButtonCount, requiredAxisCount)) {
            LogHelper.Info(
                "Controller #"
                    + joyIndex
                    + " ( "
                    + thisController.getName()
                    + ") meets the input requirements");
            addControllerToList(validControllers, thisController.getName(), joyIndex);
          } else {
            LogHelper.Info("This controller does not meet the input requirements");
            addControllerToList(inValidControllers, thisController.getName(), joyIndex);
          }
          LogHelper.Info("---");
        }
      }
    } catch (org.lwjgl.LWJGLException e) {
      System.err.println("Couldn't initialize Controllers: " + e.getMessage());
    }

    LogHelper.Info("Found " + validControllers.size() + " valid controllers!");
    return validControllers.size();
  }