public static void saveSensitivityValues() { LogHelper.Info("Saving game sensitivity value: " + ControllerSettings.inGameSensitivity); config.updateConfigFileSetting( ConfigFile.UserJoypadSettings.GameSensitivity, "" + ControllerSettings.inGameSensitivity); LogHelper.Info("Saving menu sensitivity value: " + ControllerSettings.inMenuSensitivity); config.updateConfigFileSetting( ConfigFile.UserJoypadSettings.GuiSensitivity, "" + ControllerSettings.inMenuSensitivity); }
public static void applySavedDeadZones(int joyId) { if (joyId < 0) return; LogHelper.Info("Applying configurated deadzones"); config.applySavedDeadZones(Controllers.getController(joyId)); }
public void init() { LogHelper.Info( "Minecraft Joypad (Controller) Mod v" + ModVersionHelper.VERSION + " by Ljubomir Simin & Andrew Hickey\n---"); if (config.preferedJoyName == "disabled") { LogHelper.Warn( "Controller input disabled due to joypad value 'preferedJoyName' set to disabled"); inputEnabled = false; ControllerSettings.modDisabled = true; return; } LogHelper.Info("Initializing Controllers"); // only set a controller as in use on init if they have previously gone // into controls to set it up // and it is detected as present int nControllers = detectControllers(); int selectedController = -1; if (nControllers > 0 && config.preferedJoyNo >= 0) { selectedController = checkForControllerAtIndex(config.preferedJoyName, config.preferedJoyNo); if (selectedController >= 0) { setController(selectedController); Controllers.clearEvents(); } else { LogHelper.Info("No joypad set up for this session. Must enter controller menu to enable"); } } if (selectedController < 0) { LogHelper.Warn( "No joypad set up for this session." + (nControllers > 0 ? " Must enter controller menu to enable." : "")); inputEnabled = false; } }
public static void saveDeadZones(int joyId) { Controller controller = Controllers.getController(joyId); DecimalFormat df = new DecimalFormat("#0.00"); for (int i = 0; i < controller.getAxisCount(); i++) { config.setConfigFileSetting( "-Deadzones-." + controller.getName(), controller.getAxisName(i), df.format(controller.getDeadZone(i))); } config.addComment( "-Deadzones-", "Deadzone values here will override values in individual bindings"); LogHelper.Info("Saved deadzones for " + controller.getName()); }
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(); }
public ControllerSettings(File configFile) { config = new ConfigFile(configFile); config.init(); controllerUtils = new ControllerUtils(); validControllers = new HashMap<String, List<Integer>>(); inValidControllers = new HashMap<String, List<Integer>>(); joyBindingsMap = new HashMap<String, ControllerBinding>(); userDefinedBindings = new ArrayList<ControllerBinding>(); grabMouse = ControllerSettings.getGameOption("-Global-.GrabMouse").equals("true"); try { Controllers.create(); } catch (Exception ex) { LogHelper.Error("Failed creating controller object. " + ex.toString()); } }
private void logControllerInfo(Controller controller) { LogHelper.Info("Found controller " + controller.getName() + " (" + controller.getIndex() + ")"); LogHelper.Info("It has " + controller.getButtonCount() + " buttons."); LogHelper.Info("It has " + controller.getAxisCount() + " axes."); }
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); } }