/** * Check if the controller has the left direction pressed * * @param controller The index of the controller to check * @return True if the controller is pressed to the left */ public boolean isControllerLeft(int controller) { if (controller >= getControllerCount()) { return false; } if (controller == ANY_CONTROLLER) { for (int i=0;i<controllers.size();i++) { if (isControllerLeft(i)) { return true; } } return false; } return ((Controller) controllers.get(controller)).getXAxisValue() < -0.5f || ((Controller) controllers.get(controller)).getPovX() < -0.5f; }
/** * Check if the controller has the right direction pressed * * @param controller The index of the controller to check * @return True if the controller is pressed to the right */ public boolean isControllerRight(int controller) { if (controller >= getControllerCount()) { return false; } if (controller == ANY_CONTROLLER) { for (int i=0;i<controllers.size();i++) { if (isControllerRight(i)) { return true; } } return false; } return ((Controller) controllers.get(controller)).getXAxisValue() > 0.5f || ((Controller) controllers.get(controller)).getPovX() > 0.5f; }
/** * Check if the controller has the up direction pressed * * @param controller The index of the controller to check * @return True if the controller is pressed to the up */ public boolean isControllerUp(int controller) { if (controller >= getControllerCount()) { return false; } if (controller == ANY_CONTROLLER) { for (int i=0;i<controllers.size();i++) { if (isControllerUp(i)) { return true; } } return false; } return ((Controller) controllers.get(controller)).getYAxisValue() < -0.5f || ((Controller) controllers.get(controller)).getPovY() < -0.5f; }
/** * Check if the controller has the down direction pressed * * @param controller The index of the controller to check * @return True if the controller is pressed to the down */ public boolean isControllerDown(int controller) { if (controller >= getControllerCount()) { return false; } if (controller == ANY_CONTROLLER) { for (int i=0;i<controllers.size();i++) { if (isControllerDown(i)) { return true; } } return false; } return ((Controller) controllers.get(controller)).getYAxisValue() > 0.5f || ((Controller) controllers.get(controller)).getPovY() > 0.5f; }
/** * Check if controller button is pressed * * @param controller The index of the controller to check * @param index The index of the button to check * @return True if the button is pressed */ public boolean isButtonPressed(int index, int controller) { if (controller >= getControllerCount()) { return false; } if (controller == ANY_CONTROLLER) { for (int i=0;i<controllers.size();i++) { if (isButtonPressed(index, i)) { return true; } } return false; } return ((Controller) controllers.get(controller)).isButtonPressed(index); }
private static int[] getSpecialIds(Controller controller) { try { Class<?> targetClazz = Class.forName("org.lwjgl.input.JInputController"); if(targetClazz.isInstance(controller)) { int[] ret = new int[6]; ret[0] = getFieldValue(controller, "xaxis"); ret[1] = getFieldValue(controller, "yaxis"); ret[2] = getFieldValue(controller, "zaxis"); ret[3] = getFieldValue(controller, "rxaxis"); ret[4] = getFieldValue(controller, "ryaxis"); ret[5] = getFieldValue(controller, "rzaxis"); return ret; } } catch (Exception e) { Throwables.propagate(e); } return null; }
@Override public void updatePlayerMoveState(){ super.updatePlayerMoveState(); Controller controller = Config.INSTANCE.getController(); StickConfig cfg = Config.INSTANCE.getMapping().getStick(Usage.MOVEMENT); if(cfg == null)return; Pair<Float, Float> movement = cfg.getData(controller); if(this.sneak) { this.moveForward /= 0.3; this.moveStrafe /= 0.3; } this.moveForward = clamp(this.moveForward + movement.getRight(), -1.0F, 1.0F); this.moveStrafe = clamp(this.moveStrafe + movement.getLeft(), -1.0F, 1.0F); if(this.sneak) { this.moveForward *= 0.3; this.moveStrafe *= 0.3; } }
public static void loadSelectedController(Controller controller) { if(controller == null) { LOG.info("The user chose to use mouse and keyboard."); } else { controller.poll(); LOG.info(String.format("The user chose to use the following controller: '%s'", controller.getName())); } Config.INSTANCE.setController(controller); if(Config.INSTANCE.hasController()) { ControllerSupportMod.INSTANCE.handler.activate(); ControllerMapping mapping = ControllerMapping.loadFromConfig(); Config.INSTANCE.setMapping(mapping); Config.INSTANCE.save(); } else { ControllerSupportMod.INSTANCE.handler.deactivate(); } }
/** * */ private void logAllControllers() { for (int i = 0; i < Controllers.getControllerCount(); i++) { final Controller controller = Controllers.getController(i); Log.debug(controller.getName()); final int controllerAxisCount = controller.getAxisCount(); Log.debug("org.lwjgl.input.Controller#getAxisName"); for (int j = 0; j < controllerAxisCount; j++) { Log.debug(controller.getAxisName(j)); } final int controllerButtonCount = controller.getButtonCount(); Log.debug("org.lwjgl.input.Controller#getButtonCount"); Log.debug(String.valueOf(controllerButtonCount)); Log.debug("org.lwjgl.input.Controller#getButtonName"); for (int j = 0; j < controllerButtonCount; j++) { Log.debug(controller.getButtonName(j)); } final int controllerRumblerCount = controller.getRumblerCount(); Log.debug("org.lwjgl.input.Controller#getRumblerName"); for (int j = 0; j < controllerRumblerCount; j++) { Log.debug(controller.getRumblerName(j)); } controllers.add(controller); } }