mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-19 03:49:14 +00:00
163 lines
6.2 KiB
Diff
163 lines
6.2 KiB
Diff
--- ../src-base/minecraft/net/minecraft/client/settings/KeyBinding.java
|
|
+++ ../src-work/minecraft/net/minecraft/client/settings/KeyBinding.java
|
|
@@ -14,7 +14,7 @@
|
|
public class KeyBinding implements Comparable<KeyBinding>
|
|
{
|
|
private static final List<KeyBinding> field_74516_a = Lists.<KeyBinding>newArrayList();
|
|
- private static final IntHashMap<KeyBinding> field_74514_b = new IntHashMap();
|
|
+ private static final net.minecraftforge.client.settings.KeyBindingMap field_74514_b = new net.minecraftforge.client.settings.KeyBindingMap();
|
|
private static final Set<String> field_151473_c = Sets.<String>newHashSet();
|
|
private final String field_74515_c;
|
|
private final int field_151472_e;
|
|
@@ -27,7 +27,7 @@
|
|
{
|
|
if (p_74507_0_ != 0)
|
|
{
|
|
- KeyBinding keybinding = (KeyBinding)field_74514_b.func_76041_a(p_74507_0_);
|
|
+ KeyBinding keybinding = field_74514_b.lookupActive(p_74507_0_);
|
|
|
|
if (keybinding != null)
|
|
{
|
|
@@ -40,7 +40,7 @@
|
|
{
|
|
if (p_74510_0_ != 0)
|
|
{
|
|
- KeyBinding keybinding = (KeyBinding)field_74514_b.func_76041_a(p_74510_0_);
|
|
+ for (KeyBinding keybinding : field_74514_b.lookupAll(p_74510_0_))
|
|
|
|
if (keybinding != null)
|
|
{
|
|
@@ -74,11 +74,11 @@
|
|
|
|
public static void func_74508_b()
|
|
{
|
|
- field_74514_b.func_76046_c();
|
|
+ field_74514_b.clearMap();
|
|
|
|
for (KeyBinding keybinding : field_74516_a)
|
|
{
|
|
- field_74514_b.func_76038_a(keybinding.field_74512_d, keybinding);
|
|
+ field_74514_b.addKey(keybinding.field_74512_d, keybinding);
|
|
}
|
|
}
|
|
|
|
@@ -94,13 +94,13 @@
|
|
this.field_151472_e = p_i45001_2_;
|
|
this.field_151471_f = p_i45001_3_;
|
|
field_74516_a.add(this);
|
|
- field_74514_b.func_76038_a(p_i45001_2_, this);
|
|
+ field_74514_b.addKey(p_i45001_2_, this);
|
|
field_151473_c.add(p_i45001_3_);
|
|
}
|
|
|
|
public boolean func_151470_d()
|
|
{
|
|
- return this.field_74513_e;
|
|
+ return this.field_74513_e && getKeyConflictContext().isActive() && (!allowsKeyModifiers || getKeyModifier().isActive());
|
|
}
|
|
|
|
public String func_151466_e()
|
|
@@ -158,4 +158,102 @@
|
|
|
|
return i;
|
|
}
|
|
+
|
|
+ /****************** Forge Start *****************************/
|
|
+ private net.minecraftforge.client.settings.KeyModifier keyModifierDefault = net.minecraftforge.client.settings.KeyModifier.NONE;
|
|
+ private net.minecraftforge.client.settings.KeyModifier keyModifier = net.minecraftforge.client.settings.KeyModifier.NONE;
|
|
+ private net.minecraftforge.client.settings.IKeyConflictContext keyConflictContext = net.minecraftforge.client.settings.KeyConflictContext.UNIVERSAL;
|
|
+ private boolean allowsKeyModifiers = false;
|
|
+
|
|
+ /**
|
|
+ * Convenience constructor for creating KeyBindings with keyConflictContext set.
|
|
+ */
|
|
+ public KeyBinding(String description, net.minecraftforge.client.settings.IKeyConflictContext keyConflictContext, int keyCode, String category)
|
|
+ {
|
|
+ this(description, keyConflictContext, net.minecraftforge.client.settings.KeyModifier.NONE, keyCode, category);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Convenience constructor for creating KeyBindings with keyConflictContext and keyModifier set.
|
|
+ */
|
|
+ public KeyBinding(String description, net.minecraftforge.client.settings.IKeyConflictContext keyConflictContext, net.minecraftforge.client.settings.KeyModifier keyModifier, int keyCode, String category)
|
|
+ {
|
|
+ this.field_74515_c = description;
|
|
+ this.field_74512_d = keyCode;
|
|
+ this.field_151472_e = keyCode;
|
|
+ this.field_151471_f = category;
|
|
+ this.keyConflictContext = keyConflictContext;
|
|
+ this.keyModifier = keyModifier;
|
|
+ this.keyModifierDefault = keyModifier;
|
|
+ if (keyModifier != net.minecraftforge.client.settings.KeyModifier.NONE)
|
|
+ setAllowsKeyModifiers();
|
|
+ field_74516_a.add(this);
|
|
+ field_74514_b.addKey(keyCode, this);
|
|
+ field_151473_c.add(category);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Call this method to let Forge know that your KeyBinding and code can handle players setting modifiers.
|
|
+ * Handling modifiers is made easy by using {@link KeyBinding#isActiveAndMatches(int)} or {@link KeyBinding#isPressed()}
|
|
+ * Vanilla code does not handle modifiers, so vanilla keyBinds do not have this set.
|
|
+ */
|
|
+ public void setAllowsKeyModifiers()
|
|
+ {
|
|
+ this.allowsKeyModifiers = true;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Checks that the key conflict context and modifier are active, and that the keyCode matches this binding.
|
|
+ */
|
|
+ public boolean isActiveAndMatches(int keyCode)
|
|
+ {
|
|
+ return keyCode == this.func_151463_i() && getKeyConflictContext().isActive() && (!allowsKeyModifiers || getKeyModifier().isActive());
|
|
+ }
|
|
+
|
|
+ public void setKeyConflictContext(net.minecraftforge.client.settings.IKeyConflictContext keyConflictContext)
|
|
+ {
|
|
+ this.keyConflictContext = keyConflictContext;
|
|
+ }
|
|
+
|
|
+ public net.minecraftforge.client.settings.IKeyConflictContext getKeyConflictContext()
|
|
+ {
|
|
+ return keyConflictContext;
|
|
+ }
|
|
+
|
|
+ public net.minecraftforge.client.settings.KeyModifier getKeyModifierDefault()
|
|
+ {
|
|
+ return keyModifierDefault;
|
|
+ }
|
|
+
|
|
+ public net.minecraftforge.client.settings.KeyModifier getKeyModifier()
|
|
+ {
|
|
+ if (allowsKeyModifiers)
|
|
+ {
|
|
+ return keyModifier;
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ return net.minecraftforge.client.settings.KeyModifier.NONE;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public void setKeyModifier(net.minecraftforge.client.settings.KeyModifier keyModifier)
|
|
+ {
|
|
+ field_74514_b.removeKey(this);
|
|
+ this.keyModifier = keyModifier;
|
|
+ field_74514_b.addKey(field_74512_d, this);
|
|
+ }
|
|
+
|
|
+ public boolean conflicts(KeyBinding other)
|
|
+ {
|
|
+ if (getKeyConflictContext().conflicts(other.getKeyConflictContext()) || other.getKeyConflictContext().conflicts(getKeyConflictContext()))
|
|
+ {
|
|
+ if (!allowsKeyModifiers || !other.allowsKeyModifiers || getKeyModifier() == other.getKeyModifier())
|
|
+ {
|
|
+ return func_151463_i() == other.func_151463_i();
|
|
+ }
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+ /****************** Forge End *****************************/
|
|
}
|