mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 04:09:51 +00:00
Fix remaining issues preventing compilation, launching, and loading worlds (#5156)
Fix duplicate ID for ingredient serializers Fix KeyBinding compile errors. No GuiKeyBindingList patches yet. Implement controls GUI and WorldServer patches
This commit is contained in:
1 parent
c191851ec0
commit
d08f8e1a78
15 files changed
+645
-75
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package net.minecraftforge.client.extensions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraftforge.client.settings.IKeyConflictContext;
|
||||
import net.minecraftforge.client.settings.KeyModifier;
|
||||
|
||||
public interface IForgeKeybinding
|
||||
{
|
||||
default KeyBinding getKeyBinding() { return (KeyBinding) this; }
|
||||
|
||||
@Nonnull InputMappings.Input getKey();
|
||||
|
||||
/**
|
||||
* Checks that the key conflict context and modifier are active, and that the keyCode matches this binding.
|
||||
*/
|
||||
default boolean isActiveAndMatches(InputMappings.Input keyCode)
|
||||
{
|
||||
return keyCode.func_197937_c() != 0 && keyCode.equals(getKey()) && getKeyConflictContext().isActive() && getKeyModifier().isActive(getKeyConflictContext());
|
||||
}
|
||||
|
||||
default void setToDefault()
|
||||
{
|
||||
setKeyModifierAndCode(getKeyModifierDefault(), getKeyBinding().func_197977_i());
|
||||
}
|
||||
|
||||
void setKeyConflictContext(IKeyConflictContext keyConflictContext);
|
||||
|
||||
IKeyConflictContext getKeyConflictContext();
|
||||
|
||||
KeyModifier getKeyModifierDefault();
|
||||
|
||||
KeyModifier getKeyModifier();
|
||||
|
||||
void setKeyModifierAndCode(KeyModifier keyModifier, InputMappings.Input keyCode);
|
||||
|
||||
/**
|
||||
* Returns true when one of the bindings' key codes conflicts with the other's modifier.
|
||||
*/
|
||||
default boolean hasKeyCodeModifierConflict(KeyBinding other)
|
||||
{
|
||||
if (getKeyConflictContext().conflicts(other.getKeyConflictContext()) || other.getKeyConflictContext().conflicts(getKeyConflictContext()))
|
||||
{
|
||||
if (getKeyModifier().matches(other.getKey()) || other.getKeyModifier().matches(getKey()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -20,27 +20,30 @@
|
||||
package net.minecraftforge.client.settings;
|
||||
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
import net.minecraft.util.IntHashMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class KeyBindingMap
|
||||
{
|
||||
private static final EnumMap<KeyModifier, IntHashMap<Collection<KeyBinding>>> map = new java.util.EnumMap<KeyModifier, IntHashMap<Collection<KeyBinding>>>(KeyModifier.class);
|
||||
private static final EnumMap<KeyModifier, Map<InputMappings.Input, Collection<KeyBinding>>> map = new EnumMap<>(KeyModifier.class);
|
||||
static
|
||||
{
|
||||
for (KeyModifier modifier : KeyModifier.values())
|
||||
{
|
||||
map.put(modifier, new IntHashMap<Collection<KeyBinding>>());
|
||||
map.put(modifier, new HashMap<>());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public KeyBinding lookupActive(int keyCode)
|
||||
public KeyBinding lookupActive(InputMappings.Input keyCode)
|
||||
{
|
||||
KeyModifier activeModifier = KeyModifier.getActiveModifier();
|
||||
if (!activeModifier.matches(keyCode))
|
||||
@@ -55,9 +58,9 @@ public class KeyBindingMap
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private KeyBinding getBinding(int keyCode, KeyModifier keyModifier)
|
||||
private KeyBinding getBinding(InputMappings.Input keyCode, KeyModifier keyModifier)
|
||||
{
|
||||
Collection<KeyBinding> bindings = map.get(keyModifier).lookup(keyCode);
|
||||
Collection<KeyBinding> bindings = map.get(keyModifier).get(keyCode);
|
||||
if (bindings != null)
|
||||
{
|
||||
for (KeyBinding binding : bindings)
|
||||
@@ -71,12 +74,12 @@ public class KeyBindingMap
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<KeyBinding> lookupAll(int keyCode)
|
||||
public List<KeyBinding> lookupAll(InputMappings.Input keyCode)
|
||||
{
|
||||
List<KeyBinding> matchingBindings = new ArrayList<KeyBinding>();
|
||||
for (IntHashMap<Collection<KeyBinding>> bindingsMap : map.values())
|
||||
for (Map<InputMappings.Input, Collection<KeyBinding>> bindingsMap : map.values())
|
||||
{
|
||||
Collection<KeyBinding> bindings = bindingsMap.lookup(keyCode);
|
||||
Collection<KeyBinding> bindings = bindingsMap.get(keyCode);
|
||||
if (bindings != null)
|
||||
{
|
||||
matchingBindings.addAll(bindings);
|
||||
@@ -85,15 +88,15 @@ public class KeyBindingMap
|
||||
return matchingBindings;
|
||||
}
|
||||
|
||||
public void addKey(int keyCode, KeyBinding keyBinding)
|
||||
public void addKey(InputMappings.Input keyCode, KeyBinding keyBinding)
|
||||
{
|
||||
KeyModifier keyModifier = keyBinding.getKeyModifier();
|
||||
IntHashMap<Collection<KeyBinding>> bindingsMap = map.get(keyModifier);
|
||||
Collection<KeyBinding> bindingsForKey = bindingsMap.lookup(keyCode);
|
||||
Map<InputMappings.Input, Collection<KeyBinding>> bindingsMap = map.get(keyModifier);
|
||||
Collection<KeyBinding> bindingsForKey = bindingsMap.get(keyCode);
|
||||
if (bindingsForKey == null)
|
||||
{
|
||||
bindingsForKey = new ArrayList<KeyBinding>();
|
||||
bindingsMap.addKey(keyCode, bindingsForKey);
|
||||
bindingsMap.put(keyCode, bindingsForKey);
|
||||
}
|
||||
bindingsForKey.add(keyBinding);
|
||||
}
|
||||
@@ -101,24 +104,24 @@ public class KeyBindingMap
|
||||
public void removeKey(KeyBinding keyBinding)
|
||||
{
|
||||
KeyModifier keyModifier = keyBinding.getKeyModifier();
|
||||
int keyCode = keyBinding.getKeyCode();
|
||||
IntHashMap<Collection<KeyBinding>> bindingsMap = map.get(keyModifier);
|
||||
Collection<KeyBinding> bindingsForKey = bindingsMap.lookup(keyCode);
|
||||
InputMappings.Input keyCode = keyBinding.getKey();
|
||||
Map<InputMappings.Input, Collection<KeyBinding>> bindingsMap = map.get(keyModifier);
|
||||
Collection<KeyBinding> bindingsForKey = bindingsMap.get(keyCode);
|
||||
if (bindingsForKey != null)
|
||||
{
|
||||
bindingsForKey.remove(keyBinding);
|
||||
if (bindingsForKey.isEmpty())
|
||||
{
|
||||
bindingsMap.removeObject(keyCode);
|
||||
bindingsMap.remove(keyCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearMap()
|
||||
{
|
||||
for (IntHashMap<Collection<KeyBinding>> bindings : map.values())
|
||||
for (Map<InputMappings.Input, Collection<KeyBinding>> bindings : map.values())
|
||||
{
|
||||
bindings.clearMap();
|
||||
bindings.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,18 +21,19 @@ package net.minecraftforge.client.settings;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.GameSettings;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.util.InputMappings;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
public enum KeyModifier {
|
||||
CONTROL {
|
||||
@Override
|
||||
public boolean matches(int keyCode)
|
||||
public boolean matches(InputMappings.Input key)
|
||||
{
|
||||
int keyCode = key.func_197937_c();
|
||||
if (Minecraft.IS_RUNNING_ON_MAC)
|
||||
{
|
||||
return keyCode == GLFW.GLFW_KEY_LEFT_ALT || keyCode == GLFW.GLFW_KEY_RIGHT_ALT;
|
||||
@@ -56,18 +57,18 @@ public enum KeyModifier {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedComboName(int keyCode)
|
||||
public String getLocalizedComboName(InputMappings.Input key)
|
||||
{
|
||||
String keyName = GLFW.glfwGetKeyName(keyCode, 0);
|
||||
String keyName = key.func_197936_a();
|
||||
String localizationFormatKey = Minecraft.IS_RUNNING_ON_MAC ? "forge.controlsgui.control.mac" : "forge.controlsgui.control";
|
||||
return I18n.format(localizationFormatKey, keyName);
|
||||
}
|
||||
},
|
||||
SHIFT {
|
||||
@Override
|
||||
public boolean matches(int keyCode)
|
||||
public boolean matches(InputMappings.Input key)
|
||||
{
|
||||
return keyCode == GLFW.GLFW_KEY_LEFT_SHIFT || keyCode == GLFW.GLFW_KEY_RIGHT_SHIFT;
|
||||
return key.func_197937_c() == GLFW.GLFW_KEY_LEFT_SHIFT || key.func_197937_c() == GLFW.GLFW_KEY_RIGHT_SHIFT;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,17 +84,16 @@ public enum KeyModifier {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedComboName(int keyCode)
|
||||
public String getLocalizedComboName(InputMappings.Input key)
|
||||
{
|
||||
String keyName = GLFW.glfwGetKeyName(keyCode, 0);
|
||||
return I18n.format("forge.controlsgui.shift", keyName);
|
||||
return I18n.format("forge.controlsgui.shift", key.func_197936_a());
|
||||
}
|
||||
},
|
||||
ALT {
|
||||
@Override
|
||||
public boolean matches(int keyCode)
|
||||
public boolean matches(InputMappings.Input key)
|
||||
{
|
||||
return keyCode == GLFW.GLFW_KEY_LEFT_ALT || keyCode == GLFW.GLFW_KEY_RIGHT_ALT;
|
||||
return key.func_197937_c() == GLFW.GLFW_KEY_LEFT_ALT || key.func_197937_c() == GLFW.GLFW_KEY_RIGHT_ALT;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,15 +109,14 @@ public enum KeyModifier {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedComboName(int keyCode)
|
||||
public String getLocalizedComboName(InputMappings.Input keyCode)
|
||||
{
|
||||
String keyName = GLFW.glfwGetKeyName(keyCode, 0);
|
||||
return I18n.format("forge.controlsgui.alt", keyName);
|
||||
return I18n.format("forge.controlsgui.alt", keyCode.func_197936_a());
|
||||
}
|
||||
},
|
||||
NONE {
|
||||
@Override
|
||||
public boolean matches(int keyCode)
|
||||
public boolean matches(InputMappings.Input key)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -145,9 +144,9 @@ public enum KeyModifier {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedComboName(int keyCode)
|
||||
public String getLocalizedComboName(InputMappings.Input key)
|
||||
{
|
||||
return GLFW.glfwGetKeyName(keyCode, 0);
|
||||
return key.func_197936_a();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -165,11 +164,11 @@ public enum KeyModifier {
|
||||
return NONE;
|
||||
}
|
||||
|
||||
public static boolean isKeyCodeModifier(int keyCode)
|
||||
public static boolean isKeyCodeModifier(InputMappings.Input key)
|
||||
{
|
||||
for (KeyModifier keyModifier : MODIFIER_VALUES)
|
||||
{
|
||||
if (keyModifier.matches(keyCode))
|
||||
if (keyModifier.matches(key))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -189,7 +188,7 @@ public enum KeyModifier {
|
||||
}
|
||||
}
|
||||
|
||||
public abstract boolean matches(int keyCode);
|
||||
public abstract boolean matches(InputMappings.Input key);
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #isActive(IKeyConflictContext)}
|
||||
@@ -199,5 +198,5 @@ public enum KeyModifier {
|
||||
|
||||
public abstract boolean isActive(@Nullable IKeyConflictContext conflictContext);
|
||||
|
||||
public abstract String getLocalizedComboName(int keyCode);
|
||||
public abstract String getLocalizedComboName(InputMappings.Input key);
|
||||
}
|
||||
Reference in new issue
Block a user