Java源码示例:net.minecraft.client.util.InputMappings

示例1
public static void firstTimeSetup(){
	GameSettings settings = Minecraft.getInstance().gameSettings;
	
	keyInfoSprintHold.readFrom(settings.keyBindSprint);
	
	KeyModifier sprintModifier = getVanillaKeyModifier(settings.keyBindSprint);
	KeyModifier sneakModifier = getVanillaKeyModifier(settings.keyBindSneak);
	
	if (sprintModifier != KeyModifier.NONE){
		keyInfoSprintToggle.set(sprintModifier, InputMappings.Type.KEYSYM.getOrMakeInput(GLFW.GLFW_KEY_G));
	}
	
	if (sneakModifier != KeyModifier.NONE){
		keyInfoSneakToggle.set(sneakModifier, InputMappings.Type.KEYSYM.getOrMakeInput(GLFW.GLFW_KEY_G));
	}
	
	BetterSprintingMod.config.save();
}
 
示例2
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers){
	if (selectedBinding != null){
		if (keyCode == GLFW.GLFW_KEY_ESCAPE){
			selectedBinding.setBinding(KeyModifier.NONE, InputMappings.INPUT_INVALID);
		}
		else{
			selectedBinding.setBinding(KeyModifier.getActiveModifier(), InputMappings.getInputByCode(keyCode, scanCode));
		}
		
		onSelectedBindingUpdated();
		return true;
	}
	else{
		return super.keyPressed(keyCode, scanCode, modifiers);
	}
}
 
示例3
@Override
public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) {
    InputMappings.Input mouseKey = InputMappings.getInputByCode(p_keyPressed_1_, p_keyPressed_2_);
    if (p_keyPressed_1_ == 256 || minecraft.gameSettings.keyBindInventory.isActiveAndMatches(mouseKey)) {
        onClose();
        return true;
    }

    return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_);
}
 
示例4
@Override
public boolean keyPressed(int p_keyPressed_1_, int p_keyPressed_2_, int p_keyPressed_3_) {
    InputMappings.Input mouseKey = InputMappings.getInputByCode(p_keyPressed_1_, p_keyPressed_2_);
    if (p_keyPressed_1_ == 256 || minecraft.gameSettings.keyBindInventory.isActiveAndMatches(mouseKey)) {
        onClose();
        return true;
    }

    return super.keyPressed(p_keyPressed_1_, p_keyPressed_2_, p_keyPressed_3_);
}
 
示例5
@Override
public void addInformation(ItemStack stack, @Nullable World world, List<ITextComponent> tooltip, ITooltipFlag flag) {
    super.addInformation(stack, world, tooltip, flag);

    List<Upgrade> upgrades = UpgradeTools.getUpgrades(stack);
    Minecraft mc = Minecraft.getInstance();

    if (!InputMappings.isKeyDown(mc.getMainWindow().getHandle(), mc.gameSettings.keyBindSneak.getKey().getKeyCode())) {
        tooltip.add(new TranslationTextComponent("mininggadgets.tooltip.item.show_upgrades",
                mc.gameSettings.keyBindSneak.getLocalizedName().toLowerCase())
                .applyTextStyle(TextFormatting.GRAY));
    } else {
        tooltip.add(new TranslationTextComponent("mininggadgets.tooltip.item.break_cost", getEnergyCost(stack)).applyTextStyle(TextFormatting.RED));
        if (!(upgrades.isEmpty())) {
            tooltip.add(new TranslationTextComponent("mininggadgets.tooltip.item.upgrades").applyTextStyle(TextFormatting.AQUA));
            for (Upgrade upgrade : upgrades) {
                tooltip.add(new StringTextComponent(" - " +
                        I18n.format(upgrade.getLocal())
                ).applyTextStyle(TextFormatting.GRAY));
            }
        }
    }

    stack.getCapability(CapabilityEnergy.ENERGY, null)
            .ifPresent(energy -> tooltip.add(
                    new TranslationTextComponent("mininggadgets.gadget.energy",
                            MagicHelpers.tidyValue(energy.getEnergyStored()),
                            MagicHelpers.tidyValue(energy.getMaxEnergyStored())).applyTextStyles(TextFormatting.GREEN)));
}
 
示例6
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;
	}
}
 
示例7
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button){
	if (super.mouseClicked(mouseX, mouseY, button)){
		return true;
	}
	else if (selectedBinding != null){
		selectedBinding.setBinding(InputMappings.Type.MOUSE.getOrMakeInput(button));
		onSelectedBindingUpdated();
		return true;
	}
	
	return false;
}
 
示例8
@Override
public boolean keyReleased(int keyCode, int scanCode, int modifiers){
	if (selectedBinding != null){
		selectedBinding.setBinding(KeyModifier.NONE, InputMappings.getInputByCode(keyCode, scanCode));
		onSelectedBindingUpdated();
		return true;
	}
	else{
		return super.keyReleased(keyCode, scanCode, modifiers);
	}
}
 
示例9
public static Key register(String description, String keyName) {
    InputMappings.Input input = InputMappings.getInputByName(keyName);
    CustomKeyBinding keyBinding = new CustomKeyBinding(description, input.getKeyCode());
    keyBindings.add(keyBinding);

    Key key = keyBinding.getKey();
    keys.add(key);
    return key;
}
 
示例10
private static void onKeyEvent(long windowHandle, int keyCode, int scanCode, int action, int modifiers) {
    boolean isPressed = action > 0;
    if (windowHandle == mainWindowHandle &&
            minecraft.currentScreen == null &&
            keyCode != -1 &&
            !InputMappings.isKeyDown(mainWindowHandle, 292) &&
            handleKeyEvent(keyCode, isPressed))
        return;
    minecraft.keyboardListener.onKeyEvent(windowHandle, keyCode, scanCode, action, modifiers);
}
 
示例11
public KeyBindingInfo(IntValue keyCode, EnumValue<KeyModifier> keyModifier, EnumValue<InputMappings.Type> keyType){
	this.keyCode = keyCode;
	this.keyModifier = keyModifier;
	this.keyType = keyType;
}
 
示例12
public void set(KeyModifier modifier, InputMappings.Input input){
	BetterSprintingMod.config.set(keyCode, input.getKeyCode());
	BetterSprintingMod.config.set(keyModifier, modifier);
	BetterSprintingMod.config.set(keyType, input.getType());
}
 
示例13
public void setBinding(InputMappings.Input input){
	binding.bind(input);
	isSelected = false;
}
 
示例14
public void setBinding(KeyModifier modifier, InputMappings.Input input){
	binding.setKeyModifierAndCode(modifier, input);
	isSelected &= KeyModifier.isKeyCodeModifier(input) && modifier != KeyModifier.NONE;
}
 
示例15
public Key register(String keyName) {
    InputMappings.Input input = InputMappings.getInputByName(keyName);
    Key key = new Key(input.getKeyCode());
    subKeys.add(key);
    return key;
}
 
示例16
@Override
public void bind(InputMappings.Input input) {
    super.bind(input);
    int keyCode = input.getKeyCode();
    key.updateKeyCode(keyCode);
}