net.minecraft.client.settings.KeyBinding Java Examples

The following examples show how to use net.minecraft.client.settings.KeyBinding. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GuiButtonInputBinding.java    From Better-Sprinting with Mozilla Public License 2.0 6 votes vote down vote up
public void updateKeyBindingText(){
	boolean hasConflict = false;
	boolean hasOnlyModifierConflict = true;
	
	if (!binding.isInvalid()){
		for(KeyBinding other:settings.keyBindings){
			if (binding != other && binding.conflicts(other)){
				hasConflict = true;
				hasOnlyModifierConflict &= binding.hasKeyCodeModifierConflict(other);
			}
		}
	}
	
	if (isSelected){
		setMessage(TextFormatting.WHITE + "> " + TextFormatting.YELLOW + binding.getLocalizedName() + TextFormatting.WHITE + " <");
	}
	else if (hasConflict){
		setMessage((hasOnlyModifierConflict ? TextFormatting.GOLD : TextFormatting.RED) + binding.getLocalizedName());
	}
	else{
		setMessage(binding.getLocalizedName());
	}
}
 
Example #2
Source File: KeyManager.java    From malmo with MIT License 6 votes vote down vote up
/** Call this to finalise any additional key bindings we want to create in the mod.
 * @param settings Minecraft's original GameSettings object which we are appending to.
 */
private void fixAdditionalKeyBindings(GameSettings settings)
{
    if (this.additionalKeys == null)
    {
        return; // No extra keybindings to add.
    }

    // The keybindings are stored in GameSettings as a java built-in array.
    // There is no way to append to such arrays, so instead we create a new
    // array of the correct
    // length, copy across the current keybindings, add our own ones, and
    // set the new array back
    // into the GameSettings:
    KeyBinding[] bindings = (KeyBinding[]) ArrayUtils.addAll(settings.keyBindings, this.additionalKeys.toArray());
    settings.keyBindings = bindings;
}
 
Example #3
Source File: ClientProxy.java    From Better-Sprinting with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void onLoaded(FMLLoadCompleteEvent e){
	Minecraft mc = Minecraft.getInstance();
	
	mc.execute(() -> {
		GameSettings settings = mc.gameSettings;
		
		settings.keyBindings = ArrayUtils.addAll(settings.keyBindings,
			ClientModManager.keyBindSprintToggle,
			ClientModManager.keyBindSneakToggle,
			ClientModManager.keyBindOptionsMenu
		);
		
		if (BetterSprintingMod.config.isNew()){
			ClientSettings.firstTimeSetup();
		}
		
		// this should work whether it's called before or after Forge's post-load GameSettings.loadOptions call
		ClientSettings.keyInfoSprintHold.writeInto(ClientModManager.keyBindSprintHold);
		ClientSettings.keyInfoSprintToggle.writeInto(ClientModManager.keyBindSprintToggle);
		ClientSettings.keyInfoSneakToggle.writeInto(ClientModManager.keyBindSneakToggle);
		ClientSettings.keyInfoOptionsMenu.writeInto(ClientModManager.keyBindOptionsMenu);
		KeyBinding.resetKeyBindingArrayAndHash();
	});
}
 
Example #4
Source File: GuiSprint.java    From Better-Sprinting with Mozilla Public License 2.0 6 votes vote down vote up
private void updateButtonState(){
	for(Widget button:buttons){
		if (button instanceof GuiButtonInputBinding){
			KeyBinding binding = ((GuiButtonInputBinding)button).binding;
			
			if (binding == ClientModManager.keyBindSprintToggle || binding == ClientModManager.keyBindSneakToggle){
				button.active = !ClientModManager.isModDisabled();
			}
		}
	}
	
	btnSprintMode.active = !ClientModManager.isModDisabled();
	btnDoubleTap.active = !ClientModManager.isModDisabled();
	btnAllDirs.active = Feature.RUN_IN_ALL_DIRS.isAvailable();
	btnFlyBoost.active = Feature.FLY_BOOST.isAvailable();
	btnFlyOnGround.active = Feature.FLY_ON_GROUND.isAvailable();
	btnDisableMod.active = ClientModManager.canManuallyEnableMod();
}
 
Example #5
Source File: GuiSprint.java    From Better-Sprinting with Mozilla Public License 2.0 6 votes vote down vote up
private void onSelectedBindingUpdated(){
	if (!selectedBinding.isSelected()){
		selectedBinding = null;
	}
	
	for(Widget button:buttons){
		if (button instanceof GuiButtonInputBinding){
			((GuiButtonInputBinding)button).updateKeyBindingText();
		}
	}
	
	ClientSettings.keyInfoSprintHold.readFrom(ClientModManager.keyBindSprintHold);
	ClientSettings.keyInfoSprintToggle.readFrom(ClientModManager.keyBindSprintToggle);
	ClientSettings.keyInfoSneakToggle.readFrom(ClientModManager.keyBindSneakToggle);
	ClientSettings.keyInfoOptionsMenu.readFrom(ClientModManager.keyBindOptionsMenu);
	KeyBinding.resetKeyBindingArrayAndHash();
	
	mc.gameSettings.saveOptions();
	BetterSprintingMod.config.save();
}
 
Example #6
Source File: HUDHandler.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onKeyPress(KeyBinding key){
    Minecraft mc = FMLClientHandler.instance().getClient();
    if(mc.inGameHasFocus) {
        if(key == KeyHandler.getInstance().keybindOpenOptions) {
            ItemStack helmetStack = mc.thePlayer.inventory.armorInventory[3];
            if(helmetStack != null && helmetStack.getItem() == Itemss.pneumaticHelmet) {
                FMLCommonHandler.instance().showGuiScreen(GuiHelmetMainScreen.getInstance());
            }
        } else if(key == KeyHandler.getInstance().keybindHack && HackUpgradeRenderHandler.enabledForPlayer(mc.thePlayer)) {
            getSpecificRenderer(BlockTrackUpgradeHandler.class).hack();
            getSpecificRenderer(EntityTrackUpgradeHandler.class).hack();
        } else if(key == KeyHandler.getInstance().keybindDebuggingDrone && DroneDebugUpgradeHandler.enabledForPlayer(PneumaticCraft.proxy.getPlayer())) {
            getSpecificRenderer(EntityTrackUpgradeHandler.class).selectAsDebuggingTarget();
        }
    }
}
 
Example #7
Source File: ClientProxy.java    From IGW-mod with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void preInit(FMLPreInitializationEvent event){
    MinecraftForge.EVENT_BUS.register(new TickHandler());

    MinecraftForge.EVENT_BUS.register(new TooltipOverlayHandler());

    //Not being used, as it doesn't really add anything...
    // MinecraftForge.EVENT_BUS.register(new HighlightHandler());

    openInterfaceKey = new KeyBinding("igwmod.keys.wiki", Constants.DEFAULT_KEYBIND_OPEN_GUI, "igwmod.keys.category");//TODO blend keybinding category in normal
    ClientRegistry.registerKeyBinding(openInterfaceKey);
    MinecraftForge.EVENT_BUS.register(this);//subscribe to key events.

    ConfigHandler.init(event.getSuggestedConfigurationFile());

    WikiRegistry.registerWikiTab(new IGWWikiTab());
    WikiRegistry.registerWikiTab(new BlockAndItemWikiTab());
    WikiRegistry.registerWikiTab(new EntityWikiTab());

    WikiRegistry.registerRecipeIntegrator(new IntegratorImage());
    WikiRegistry.registerRecipeIntegrator(new IntegratorCraftingRecipe());
    WikiRegistry.registerRecipeIntegrator(new IntegratorFurnace());
    WikiRegistry.registerRecipeIntegrator(new IntegratorStack());
    WikiRegistry.registerRecipeIntegrator(new IntegratorComment());
}
 
Example #8
Source File: KeybindManager.java    From MediaMod with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fired when you want to register keybinds
 *
 * @see MediaMod#preInit(FMLPreInitializationEvent)
 */
public void register() {
    // Initialize and declare keybinds
    INSTANCE.disableKeybind = new KeyBinding("key.disableKeybind", Keyboard.KEY_P, "key.categories.mediamod");
    INSTANCE.menuKeybind = new KeyBinding("key.menuKeybind", Keyboard.KEY_M, "key.categories.mediamod");
    INSTANCE.skipKeybind = new KeyBinding("key.skipKeybind", Keyboard.KEY_F, "key.categories.mediamod");
    INSTANCE.pausePlayKeybind = new KeyBinding("key.pausePlayKeybind", Keyboard.KEY_N, "key.categories.mediamod");

    ClientRegistry.registerKeyBinding(disableKeybind);
    ClientRegistry.registerKeyBinding(menuKeybind);
    ClientRegistry.registerKeyBinding(skipKeybind);
    ClientRegistry.registerKeyBinding(pausePlayKeybind);
}
 
Example #9
Source File: TunnellerHack.java    From ForgeWurst with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onUpdate(WUpdateEvent event)
{
	HackList hax = wurst.getHax();
	Hack[] incompatibleHax = {hax.autoToolHack, hax.autoWalkHack,
		hax.blinkHack, hax.flightHack, hax.nukerHack, hax.sneakHack};
	for(Hack hack : incompatibleHax)
		hack.setEnabled(false);
	
	if(hax.freecamHack.isEnabled())
		return;
	
	GameSettings gs = mc.gameSettings;
	KeyBinding[] bindings = {gs.keyBindForward, gs.keyBindBack,
		gs.keyBindLeft, gs.keyBindRight, gs.keyBindJump, gs.keyBindSneak};
	for(KeyBinding binding : bindings)
		KeyBindingUtils.setPressed(binding, false);
	
	for(Task task : tasks)
	{
		if(!task.canRun())
			continue;
		
		task.run();
		break;
	}
}
 
Example #10
Source File: SkyblockAddons.java    From SkyblockAddons with MIT License 5 votes vote down vote up
public void addKeybinds(SkyblockKeyBinding... keybinds) {
    for (SkyblockKeyBinding skyblockKeyBinding : keybinds) {
        KeyBinding keyBinding = new KeyBinding("key.skyblockaddons."+ skyblockKeyBinding.getName(), skyblockKeyBinding.getDefaultKey(), MOD_NAME);
        ClientRegistry.registerKeyBinding(keyBinding);
        skyblockKeyBinding.setKeyBinding(keyBinding);

        keyBindings.add(skyblockKeyBinding);
    }
}
 
Example #11
Source File: HyperiumBind.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void detectConflicts() {
    conflicted = false;

    int currentKeyCode = key;

    // Allow multiple binds to be set to NONE.
    if (currentKeyCode == 0 || conflictExempt) return;

    List<HyperiumBind> otherBinds = new ArrayList<>(Hyperium.INSTANCE.getHandlers().getKeybindHandler().getKeybinds().values());
    otherBinds.remove(this);

    // Check for conflicts with Minecraft binds.
    for (KeyBinding keyBinding : Minecraft.getMinecraft().gameSettings.keyBindings) {
        int code = keyBinding.getKeyCode();
        if (currentKeyCode == code) {
            // There is a conflict!
            conflicted = true;
        }
    }

    // Check for conflicts with other Hyperium binds.
    for (HyperiumBind hyperiumBind : otherBinds) {
        if (!hyperiumBind.conflictExempt) {
            int keyCode = hyperiumBind.key;
            if (currentKeyCode == keyCode) {
                // There is a conflict!
                conflicted = true;
                break;
            }
        }
    }
}
 
Example #12
Source File: GuiMoveModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void onUpdate(EventPlayerUpdate event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        final Minecraft mc = Minecraft.getMinecraft();

        if (mc.currentScreen instanceof GuiChat || mc.currentScreen == null) {
            return;
        }

        final int[] keys = new int[]{mc.gameSettings.keyBindForward.getKeyCode(), mc.gameSettings.keyBindLeft.getKeyCode(), mc.gameSettings.keyBindRight.getKeyCode(), mc.gameSettings.keyBindBack.getKeyCode()};

        for (int keyCode : keys) {
            if (Keyboard.isKeyDown(keyCode)) {
                KeyBinding.setKeyBindState(keyCode, true);
            } else {
                KeyBinding.setKeyBindState(keyCode, false);
            }
        }

        if (Keyboard.isKeyDown(mc.gameSettings.keyBindJump.getKeyCode())) {
            if (mc.player.isInLava() || mc.player.isInWater()) {
                mc.player.motionY += 0.039f;
            } else {
                if (mc.player.onGround) {
                    mc.player.jump();
                }
            }
        }

        if (Mouse.isButtonDown(2)) {
            Mouse.setGrabbed(true);
            mc.inGameHasFocus = true;
        } else {
            Mouse.setGrabbed(false);
            mc.inGameHasFocus = false;
        }
    }
}
 
Example #13
Source File: VanillaEnhancementsHud.java    From Hyperium with GNU Lesser General Public License v3.0 5 votes vote down vote up
private int[] getHotbarKeys() {
    int[] result = new int[9];
    KeyBinding[] hotbarBindings = mc.gameSettings.keyBindsHotbar;
    int bound = Math.min(result.length, hotbarBindings.length);
    for (int i = 0; i < bound; i++) {
        result[i] = hotbarBindings[i].getKeyCode();
    }
    return result;
}
 
Example #14
Source File: FreecamHack.java    From ForgeWurst with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onEnable()
{
	MinecraftForge.EVENT_BUS.register(this);
	fakePlayer = new EntityFakePlayer();
	
	GameSettings gs = mc.gameSettings;
	KeyBinding[] bindings = {gs.keyBindForward, gs.keyBindBack,
		gs.keyBindLeft, gs.keyBindRight, gs.keyBindJump, gs.keyBindSneak};
	for(KeyBinding binding : bindings)
		KeyBindingUtils.resetPressed(binding);
}
 
Example #15
Source File: KeyBindingPressedEvent.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Called with the passed keyBinding and modifiers.
 * Subscribe to this event so activate a keybinding when triggered.
 *
 * @param keyBinding The KeyBinding being triggered. Stores the key's description and keycode
 * @param modifiers  The modifiers (SHIFT, CTRL, ALT) that determine when a compatible key is pressed
 */
public KeyBindingPressedEvent(KeyBinding keyBinding, boolean[] modifiers, boolean isPressed) {
	this.keyBinding = keyBinding;
	this.shiftRequired = modifiers[0];
	this.ctrlRequired = modifiers[1];
	this.altRequired = modifiers[2];
	this.isKeyBindingPressed = isPressed;
}
 
Example #16
Source File: MacroCommand.java    From ForgeHax with MIT License 5 votes vote down vote up
private void removeMacro(MacroEntry macro) {
  MACROS.remove(macro);
  
  if (macro.name.isPresent()) {
    MC.gameSettings.keyBindings =
      ArrayUtils.remove(
        MC.gameSettings.keyBindings,
        ArrayUtils.indexOf(MC.gameSettings.keyBindings, macro.getBind()));
  }
  // remove the category if there are no named macros to prevent crash
  // TODO: fix crash when a category is empty
  if (MACROS.stream().noneMatch(entry -> !entry.isAnonymous())) {
    KeyBinding.getKeybinds().remove("Macros");
  }
}
 
Example #17
Source File: Bindings.java    From ForgeHax with MIT License 5 votes vote down vote up
@Nullable
private static List<KeyBindingHandler> getAllKeys() {
  Field[] fields = GameSettings.class.getFields();
  return Arrays.stream(fields)
      .filter(f -> f.getType() == KeyBinding.class)
      .map(Bindings::getBinding)
      .filter(Objects::nonNull)
      .map(KeyBindingHandler::new)
      .collect(toList());
}
 
Example #18
Source File: Bindings.java    From ForgeHax with MIT License 5 votes vote down vote up
private static KeyBinding getBinding(Field field) {
  try {
    return (KeyBinding) field.get(MC.gameSettings);
  } catch (IllegalAccessException e) {
    e.printStackTrace();
    return null;
  }
}
 
Example #19
Source File: CommandStub.java    From ForgeHax with MIT License 5 votes vote down vote up
@Override
public void bind(int keyCode) {
  if (bind != null) {
    bind.setKeyCode(keyCode);
    KeyBinding.resetKeyBindingArrayAndHash();
  }
}
 
Example #20
Source File: CommandForKey.java    From malmo with MIT License 5 votes vote down vote up
/** Helper function to create a KeyHook object for a given KeyBinding object.
 * @param key the Minecraft KeyBinding object we are wrapping
 * @return an ExternalAIKey object to replace the original Minecraft KeyBinding object
 */
private KeyHook create(KeyBinding key)
{
    if (key != null && key instanceof KeyHook)
    {
        return (KeyHook)key; // Don't create a KeyHook to replace this KeyBinding, since that has already been done at some point.
        // (Minecraft keeps a pointer to every KeyBinding that gets created, and they never get destroyed - so we don't want to create
        // any more than necessary.)
    }
    return new KeyHook(key.getKeyDescription(), key.getKeyCode(), key.getKeyCategory());
}
 
Example #21
Source File: KeyHandler.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
/**
 * This will only subscribe when NotEnoughKeys is not installed.
 * @param event
 */
@SubscribeEvent
public void onKey(KeyInputEvent event){
    if(!nekLoaded()) {
        for(KeyBinding key : keys) {
            if(key.isPressed()) {
                onKey(key);
            }
        }
    }
}
 
Example #22
Source File: ClientEventHandler.java    From HoloInventory with MIT License 5 votes vote down vote up
public static void init()
{
    if (instance != null) MinecraftForge.EVENT_BUS.unregister(instance);
    instance = new ClientEventHandler();
    MinecraftForge.EVENT_BUS.register(new ClientEventHandler());

    keyHold = new KeyBinding("Hold to show", KeyConflictContext.IN_GAME, Keyboard.KEY_H, HoloInventory.MODID);
    keyToggle = new KeyBinding("Toggle to show", KeyConflictContext.IN_GAME, 0, HoloInventory.MODID);
    ClientRegistry.registerKeyBinding(keyHold);
    ClientRegistry.registerKeyBinding(keyToggle);
}
 
Example #23
Source File: KeyBindings.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public static KeyBinding get(String string) {
    KeyBinding keyBinding = keyBindings.get(string);
    if (keyBinding == null) {
        throw new IllegalArgumentException("There is no key binding for " + string);
    }
    return keyBinding;
}
 
Example #24
Source File: ClientSettings.java    From Better-Sprinting with Mozilla Public License 2.0 5 votes vote down vote up
private static KeyModifier getVanillaKeyModifier(KeyBinding binding){
	if (binding.getKeyModifier() != KeyModifier.NONE || binding.getKey().getType() != InputMappings.Type.KEYSYM){
		return KeyModifier.NONE;
	}
	
	switch(binding.getKey().getKeyCode()){
		case GLFW.GLFW_KEY_LEFT_CONTROL: return KeyModifier.CONTROL;
		case GLFW.GLFW_KEY_LEFT_SHIFT: return KeyModifier.SHIFT;
		case GLFW.GLFW_KEY_LEFT_ALT: return KeyModifier.ALT;
		default: return KeyModifier.NONE;
	}
}
 
Example #25
Source File: ClientProxy.java    From Levels with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void init()
{
	keyBindingL = new KeyBinding("key.gui.weapon_interface", Keyboard.KEY_L, "key.levels");
	
	ClientRegistry.registerKeyBinding(keyBindingL);
}
 
Example #26
Source File: EventInput.java    From Levels with GNU General Public License v2.0 5 votes vote down vote up
@SideOnly(Side.CLIENT)
@SubscribeEvent
public void onKeyPress(InputEvent.KeyInputEvent event)
{
	KeyBinding l = ClientProxy.keyBindingL;
	Minecraft mc = Minecraft.getMinecraft();
	EntityPlayer player = mc.player;
	
	if (player != null)
	{
		ItemStack stack = player.inventory.getCurrentItem();
		
		if (stack != null)
		{
			Item current = stack.getItem();
			
			if (current != null)
			{
				if (current instanceof ItemSword || current instanceof ItemTool || current instanceof ItemArmor || current instanceof ItemBow || current instanceof ItemShield)
				{
					if (l.isPressed())
					{
						player.openGui(Levels.instance, GuiHandler.ITEM_INFORMATION, player.getEntityWorld(), (int) player.posX, (int) player.posY, (int) player.posZ);
					}
				}
			}
		}
	}
}
 
Example #27
Source File: ClientProxy.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void uploadKeyBindingsToGame()
{
	GameSettings settings = Minecraft.getMinecraft().gameSettings;
	KeyBinding[] tfcKeyBindings = KeyBindings.gatherKeyBindings();
	KeyBinding[] allKeys = new KeyBinding[settings.keyBindings.length + tfcKeyBindings.length];
	System.arraycopy(settings.keyBindings, 0, allKeys, 0, settings.keyBindings.length);
	System.arraycopy(tfcKeyBindings, 0, allKeys, settings.keyBindings.length, tfcKeyBindings.length);
	settings.keyBindings = allKeys;
	settings.loadOptions();
}
 
Example #28
Source File: ClientProxy.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void registerKeyBindings()
{
    Keybindings.keyActivateUnselected = new KeyBinding( HotKeys.KEYBIND_NAME_ACTIVATE_UNSELECTED,
                                                        HotKeys.DEFAULT_KEYBIND_ACTIVATE_UNSELECTED,
                                                        HotKeys.KEYBIND_CATEGORY_ENDERUTILITIES);

    Keybindings.keyToggleMode = new KeyBinding(HotKeys.KEYBIND_NAME_TOGGLE_MODE,
                                               HotKeys.DEFAULT_KEYBIND_TOGGLE_MODE,
                                               HotKeys.KEYBIND_CATEGORY_ENDERUTILITIES);

    ClientRegistry.registerKeyBinding(Keybindings.keyActivateUnselected);
    ClientRegistry.registerKeyBinding(Keybindings.keyToggleMode);
}
 
Example #29
Source File: ArchimedesConfig.java    From archimedes-ships with MIT License 5 votes vote down vote up
@SideOnly(Side.CLIENT)
private void loadKeybindings()
{
	kbUp = new KeyBinding("key.archimedes.up", getKeyIndex(config, "key_ascent", Keyboard.KEY_X), "Archimedes");
	kbDown = new KeyBinding("key.archimedes.down", getKeyIndex(config, "key_descent", Keyboard.KEY_Z), "Archimedes");
	kbBrake = new KeyBinding("key.archimedes.brake", getKeyIndex(config, "key_brake", Keyboard.KEY_C), "Archimedes");
	kbAlign = new KeyBinding("key.archimedes.align", getKeyIndex(config, "key_align", Keyboard.CHAR_NONE), "Archimedes");
	kbDisassemble = new KeyBinding("key.archimedes.decompile", getKeyIndex(config, "key_decompile", Keyboard.KEY_BACKSLASH), "Archimedes");
	kbShipInv = new KeyBinding("key.archimedes.shipinv", getKeyIndex(config, "key_shipinv", Keyboard.KEY_K), "Archimedes");
	Minecraft mc = Minecraft.getMinecraft();
	mc.gameSettings.keyBindings = ArrayUtils.addAll(mc.gameSettings.keyBindings, kbUp, kbDown, kbBrake, kbAlign, kbDisassemble, kbShipInv);
}
 
Example #30
Source File: MoCKeyHandler.java    From mocreaturesdev with GNU General Public License v3.0 5 votes vote down vote up
public MoCKeyHandler()
{
    //the first value is an array of KeyBindings, the second is whether or not the call
    //keyDown should repeat as long as the key is down
    super(new KeyBinding[] { jumpBinding, dismountBinding, guiBinding }, new boolean[] { true, true, false });
    localScreen = MoCClientProxy.instance.MoCScreen;
}