use of net.minecraft.client.settings.KeyBinding in project PneumaticCraft by MineMaarten.
the class GuiKeybindCheckBox method setOrAddKeybind.
/**
*
* @param keybindName
* @param keyCode when a value of <0 is parsed, this will function as a getter, with a chance of returning null.
* @return
*/
public static KeyBinding setOrAddKeybind(String keybindName, int keyCode) {
GameSettings gameSettings = FMLClientHandler.instance().getClient().gameSettings;
for (KeyBinding keyBinding : gameSettings.keyBindings) {
if (keyBinding != null && keyBinding.getKeyDescription().equals(keybindName)) {
if (keybindName.equals(keyBinding.getKeyDescription())) {
if (keyCode >= 0) {
keyBinding.setKeyCode(keyCode);
KeyBinding.resetKeyBindingArrayAndHash();
gameSettings.saveOptions();
}
return keyBinding;
}
}
}
//When the keybind wasn't added yet
if (keyCode < 0) {
if (((ClientProxy) PneumaticCraft.proxy).keybindToKeyCodes.containsKey(keybindName)) {
//If the keybind can be found in the options file
keyCode = ((ClientProxy) PneumaticCraft.proxy).keybindToKeyCodes.get(keybindName);
} else {
return null;
}
}
KeyBinding keyBinding = new KeyBinding(keybindName, keyCode, Names.PNEUMATIC_KEYBINDING_CATEGORY);
ClientRegistry.registerKeyBinding(keyBinding);
KeyBinding.resetKeyBindingArrayAndHash();
gameSettings.saveOptions();
return keyBinding;
}
use of net.minecraft.client.settings.KeyBinding in project Railcraft by Railcraft.
the class AuraKeyHandler method tick.
@SubscribeEvent
public void tick(TickEvent.ClientTickEvent event) {
if (Minecraft.getMinecraft().currentScreen instanceof GuiChat)
return;
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
for (Map.Entry<GoggleAura, KeyBinding> keyBinding : keyBindings.entrySet()) {
if (keyBinding.getValue().isPressed()) {
GoggleAura aura = keyBinding.getKey();
if (isAuraEnabled(aura)) {
activeAuras.remove(aura);
ChatPlugin.sendLocalizedChat(player, "gui.railcraft.aura.disable", "§5" + aura + "§7");
} else {
activeAuras.add(aura);
ChatPlugin.sendLocalizedChat(player, "gui.railcraft.aura.enable", "§5" + aura + "§7");
}
}
}
}
use of net.minecraft.client.settings.KeyBinding in project ImmersiveEngineering by BluSunrize.
the class IEManualInstance method formatText.
@Override
public String formatText(String s) {
if (//if it contains spaces, it's probably already translated.
!s.contains(" ")) {
s = ManualUtils.attemptStringTranslation("ie.manual.entry.%s", s);
// String translKey = + s;
// String translated = I18n.format(translKey);
// if(!translKey.equals(translated))
// s = translated;
}
String splitKey = ";";
s = s.replaceAll("<br>", "\n");
int start;
int overflow = 0;
while ((start = s.indexOf("<config")) >= 0 && overflow < 50) {
overflow++;
int end = s.indexOf(">", start);
String rep = s.substring(start, end + 1);
String[] segment = rep.substring(0, rep.length() - 1).split(splitKey);
if (segment.length < 3)
break;
String result = "";
if (segment[1].equalsIgnoreCase("b")) {
if (segment.length > 3)
result = (Config.manual_bool.get(segment[2]) ? segment[3] : segment.length > 4 ? segment[4] : "");
else
result = "" + Config.manual_bool.get(segment[2]);
} else if (segment[1].equalsIgnoreCase("i"))
result = "" + Config.manual_int.get(segment[2]);
else if (segment[1].equalsIgnoreCase("iA")) {
int[] iA = Config.manual_intA.get(segment[2]);
if (segment.length > 3)
try {
if (segment[3].startsWith("l")) {
int limiter = Integer.parseInt(segment[3].substring(1));
for (int i = 0; i < limiter; i++) result += (i > 0 ? ", " : "") + iA[i];
} else {
int idx = Integer.parseInt(segment[3]);
result = "" + iA[idx];
}
} catch (Exception ex) {
break;
}
else
for (int i = 0; i < iA.length; i++) result += (i > 0 ? ", " : "") + iA[i];
} else if (segment[1].equalsIgnoreCase("d"))
result = "" + Config.manual_double.get(segment[2]);
else if (segment[1].equalsIgnoreCase("dA")) {
double[] iD = Config.manual_doubleA.get(segment[2]);
if (segment.length > 3)
try {
int idx = Integer.parseInt(segment[3]);
result = "" + Utils.formatDouble(iD[idx], "##0.0##");
} catch (Exception ex) {
break;
}
else
for (int i = 0; i < iD.length; i++) result += (i > 0 ? ", " : "") + Utils.formatDouble(iD[i], "##0.0##");
}
s = s.replaceFirst(rep, result);
}
overflow = 0;
while ((start = s.indexOf("<dim")) >= 0 && overflow < 50) {
overflow++;
int end = s.indexOf(">", start);
String rep = s.substring(start, end + 1);
String[] segment = rep.substring(0, rep.length() - 1).split(splitKey);
if (segment.length < 2)
break;
String result = "";
try {
int dim = Integer.parseInt(segment[1]);
World world = DimensionManager.getWorld(dim);
if (world != null && world.provider != null) {
String name = world.provider.getDimensionType().getName();
if (name.toLowerCase(Locale.ENGLISH).startsWith("the "))
name = name.substring(4);
result = name;
} else
result = "Dimension " + dim;
} catch (Exception ex) {
ex.printStackTrace();
}
s = s.replaceFirst(rep, result);
}
overflow = 0;
while ((start = s.indexOf("<keybind")) >= 0 && overflow < 50) {
overflow++;
int end = s.indexOf(">", start);
String rep = s.substring(start, end + 1);
String[] segment = rep.substring(0, rep.length() - 1).split(splitKey);
if (segment.length < 2)
break;
String result = "";
for (KeyBinding kb : ClientUtils.mc().gameSettings.keyBindings) if (segment[1].equalsIgnoreCase(kb.getKeyDescription())) {
result = Keyboard.getKeyName(kb.getKeyCode());
break;
}
s = s.replaceFirst(rep, result);
}
if (improveReadability()) {
overflow = 0;
int end = 0;
while ((start = s.indexOf(TextFormatting.RESET.toString(), end)) >= 0 && overflow < 50) {
overflow++;
end = start + TextFormatting.RESET.toString().length();
s = s.substring(0, end) + TextFormatting.BOLD.toString() + s.substring(end);
}
s = TextFormatting.BOLD + s;
}
return s;
}
use of net.minecraft.client.settings.KeyBinding in project SecurityCraft by Geforce132.
the class KeyBindings method init.
public static void init() {
cameraZoomIn = new KeyBinding("key.cameraZoomIn", Keyboard.KEY_EQUALS, "key.categories.securitycraft");
cameraZoomOut = new KeyBinding("key.cameraZoomOut", Keyboard.KEY_MINUS, "key.categories.securitycraft");
cameraEmitRedstone = new KeyBinding("key.cameraEmitRedstone", Keyboard.KEY_R, "key.categories.securitycraft");
cameraActivateNightVision = new KeyBinding("key.cameraActivateNightVision", Keyboard.KEY_N, "key.categories.securitycraft");
ClientRegistry.registerKeyBinding(cameraZoomIn);
ClientRegistry.registerKeyBinding(cameraZoomOut);
ClientRegistry.registerKeyBinding(cameraEmitRedstone);
ClientRegistry.registerKeyBinding(cameraActivateNightVision);
}
use of net.minecraft.client.settings.KeyBinding in project Engine by VoltzEngine-Project.
the class PlayerKeyHandler method keyTick.
private void keyTick(boolean tickEnd) {
for (int i = 0; i < Minecraft.getMinecraft().gameSettings.keyBindings.length; i++) {
KeyBinding keyBinding = Minecraft.getMinecraft().gameSettings.keyBindings[i];
int keyCode = keyBinding.getKeyCode();
boolean state = (keyCode < 0 ? Mouse.isButtonDown(keyCode + 100) : Keyboard.isKeyDown(keyCode));
if (state) {
//PacketManagerKeyEvent.sendPacket(this.channel, keyCode);
}
}
}
Aggregations