net.minecraft.util.ChatComponentTranslation#net.minecraft.client.settings.KeyBinding源码实例Demo

下面列出了net.minecraft.util.ChatComponentTranslation#net.minecraft.client.settings.KeyBinding 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: malmo   文件: KeyManager.java
/** 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;
}
 
源代码2 项目: Better-Sprinting   文件: ClientProxy.java
@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();
	});
}
 
源代码3 项目: Better-Sprinting   文件: GuiSprint.java
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();
}
 
源代码4 项目: Better-Sprinting   文件: GuiSprint.java
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();
}
 
源代码5 项目: Better-Sprinting   文件: GuiButtonInputBinding.java
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());
	}
}
 
源代码6 项目: PneumaticCraft   文件: HUDHandler.java
@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();
        }
    }
}
 
源代码7 项目: IGW-mod   文件: ClientProxy.java
@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());
}
 
源代码8 项目: mapwriter   文件: MwKeyHandler.java
@SubscribeEvent
public void onKeyPress(InputEvent.KeyInputEvent event){
    if(keyMapGui.getIsKeyPressed()){
        KeyBinding.setKeyBindState(keyMapGui.getKeyCode(), false);
        Mw.instance.onKeyDown(keyMapGui);
    }
    if(keyNewMarker.getIsKeyPressed()){
        KeyBinding.setKeyBindState(keyNewMarker.getKeyCode(), false);
        Mw.instance.onKeyDown(keyNewMarker);
    }
    if(keyMapMode.getIsKeyPressed()){
        KeyBinding.setKeyBindState(keyMapMode.getKeyCode(), false);
        Mw.instance.onKeyDown(keyMapMode);
    }
    if(keyNextGroup.getIsKeyPressed()){
        KeyBinding.setKeyBindState(keyNextGroup.getKeyCode(), false);
        Mw.instance.onKeyDown(keyNextGroup);
    }
    if(keyTeleport.getIsKeyPressed()){
        KeyBinding.setKeyBindState(keyTeleport.getKeyCode(), false);
        Mw.instance.onKeyDown(keyTeleport);
    }
    if(keyZoomIn.getIsKeyPressed()){
        KeyBinding.setKeyBindState(keyZoomIn.getKeyCode(), false);
        Mw.instance.onKeyDown(keyZoomIn);
    }
    if(keyZoomOut.getIsKeyPressed()){
        KeyBinding.setKeyBindState(keyZoomOut.getKeyCode(), false);
        Mw.instance.onKeyDown(keyZoomOut);
    }
    if(keyUndergroundMode.getIsKeyPressed()){
        KeyBinding.setKeyBindState(keyUndergroundMode.getKeyCode(), false);
        Mw.instance.onKeyDown(keyUndergroundMode);
    }
}
 
源代码9 项目: SkyblockAddons   文件: SkyblockAddons.java
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);
    }
}
 
源代码10 项目: MediaMod   文件: KeybindManager.java
/**
 * 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);
}
 
源代码11 项目: seppuku   文件: GuiMoveModule.java
@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;
        }
    }
}
 
源代码12 项目: Hyperium   文件: HyperiumBind.java
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;
            }
        }
    }
}
 
源代码13 项目: Hyperium   文件: VanillaEnhancementsHud.java
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;
}
 
源代码14 项目: ForgeWurst   文件: FreecamHack.java
@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);
}
 
源代码15 项目: ForgeWurst   文件: TunnellerHack.java
@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;
	}
}
 
源代码16 项目: ForgeWurst   文件: TunnellerHack.java
@Override
public void run()
{
	BlockPos player = new BlockPos(WMinecraft.getPlayer());
	KeyBinding forward = mc.gameSettings.keyBindForward;
	
	Vec3d diffVec = new Vec3d(player.subtract(start));
	Vec3d dirVec = new Vec3d(direction.getDirectionVec());
	double dotProduct = diffVec.dotProduct(dirVec);
	
	BlockPos pos1 = start.offset(direction, (int)dotProduct);
	if(!player.equals(pos1))
	{
		RotationUtils.faceVectorForWalking(toVec3d(pos1));
		KeyBindingUtils.setPressed(forward, true);
		return;
	}
	
	BlockPos pos2 = start.offset(direction, Math.max(0, length - 10));
	if(!player.equals(pos2))
	{
		RotationUtils.faceVectorForWalking(toVec3d(pos2));
		KeyBindingUtils.setPressed(forward, true);
		WMinecraft.getPlayer().setSprinting(true);
		return;
	}
	
	BlockPos pos3 = start.offset(direction, length + 1);
	RotationUtils.faceVectorForWalking(toVec3d(pos3));
	KeyBindingUtils.setPressed(forward, false);
	WMinecraft.getPlayer().setSprinting(false);
	
	if(disableTimer > 0)
	{
		disableTimer--;
		return;
	}
	
	setEnabled(false);
}
 
源代码17 项目: HexxitGear   文件: HGKeyHandler.java
@Override
public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat) {
    EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;

    if (player == null || tickEnd)
        return;

    if (kb.equals(activateHexxitArmor)) {
        if (ArmorSet.getPlayerArmorSet(player.username) != null) {
            Object[] data = new Object[] { player.username };
            PacketDispatcher.sendPacketToServer(PacketWrapper.createPacket(HexxitGear.modNetworkChannel, Packets.armorAbility, data));
            //ArmorSet.readArmorPacket(player.username);
        }
    }
}
 
源代码18 项目: ForgeHax   文件: MacroCommand.java
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");
  }
}
 
源代码19 项目: ForgeHax   文件: Bindings.java
@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());
}
 
源代码20 项目: ForgeHax   文件: Bindings.java
private static KeyBinding getBinding(Field field) {
  try {
    return (KeyBinding) field.get(MC.gameSettings);
  } catch (IllegalAccessException e) {
    e.printStackTrace();
    return null;
  }
}
 
源代码21 项目: ForgeHax   文件: CommandStub.java
@Override
public void bind(int keyCode) {
  if (bind != null) {
    bind.setKeyCode(keyCode);
    KeyBinding.resetKeyBindingArrayAndHash();
  }
}
 
源代码22 项目: malmo   文件: CommandForKey.java
/** 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());
}
 
源代码23 项目: PneumaticCraft   文件: KeyHandler.java
/**
 * 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);
            }
        }
    }
}
 
源代码24 项目: HoloInventory   文件: ClientEventHandler.java
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);
}
 
源代码25 项目: NotEnoughItems   文件: KeyBindings.java
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;
}
 
源代码26 项目: Better-Sprinting   文件: ClientSettings.java
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;
	}
}
 
源代码27 项目: Levels   文件: ClientProxy.java
@Override
public void init()
{
	keyBindingL = new KeyBinding("key.gui.weapon_interface", Keyboard.KEY_L, "key.levels");
	
	ClientRegistry.registerKeyBinding(keyBindingL);
}
 
源代码28 项目: Levels   文件: EventInput.java
@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);
					}
				}
			}
		}
	}
}
 
源代码29 项目: TFC2   文件: ClientProxy.java
@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();
}
 
源代码30 项目: enderutilities   文件: ClientProxy.java
@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);
}