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(); }
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; }
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); } }