-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: pull in NeoForge PR as overwrite mixin to fix key bind modifiers
Thanks, I hate it.
- Loading branch information
Showing
3 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
src/main/java/com/lovetropics/extras/mixin/fix/KeyMappingLookupMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.lovetropics.extras.mixin.fix; | ||
|
||
import com.mojang.blaze3d.platform.InputConstants; | ||
import net.minecraft.client.KeyMapping; | ||
import net.minecraftforge.client.settings.KeyMappingLookup; | ||
import net.minecraftforge.client.settings.KeyModifier; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import java.util.*; | ||
|
||
@Mixin(value = KeyMappingLookup.class, remap = false) | ||
public class KeyMappingLookupMixin { | ||
@Shadow(remap = false) | ||
@Final | ||
private static EnumMap<KeyModifier, Map<InputConstants.Key, Collection<KeyMapping>>> map; | ||
|
||
/** | ||
* @author Su5eD | ||
* @reason https://github.com/neoforged/NeoForge/pull/171 | ||
*/ | ||
@Overwrite(remap = false) | ||
public List<KeyMapping> getAll(final InputConstants.Key keyCode) { | ||
final List<KeyMapping> matchingBindings = new ArrayList<>(); | ||
final KeyModifier activeModifier = KeyModifier.getActiveModifier(); | ||
// Apply active modifier only if the pressed key is not the modifier itself | ||
// Otherwise, look for key bindings without modifiers | ||
if (activeModifier == KeyModifier.NONE || activeModifier.matches(keyCode) || !matchingBindings.addAll(findKeybinds(keyCode, activeModifier))) { | ||
matchingBindings.addAll(findKeybinds(keyCode, KeyModifier.NONE)); | ||
} | ||
return matchingBindings; | ||
} | ||
|
||
private List<KeyMapping> findKeybinds(final InputConstants.Key keyCode, final KeyModifier modifier) { | ||
final Collection<KeyMapping> modifierBindings = map.get(modifier).get(keyCode); | ||
if (modifierBindings != null) { | ||
return modifierBindings.stream().filter(binding -> binding.isActiveAndMatches(keyCode)).toList(); | ||
} | ||
return List.of(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...cs/extras/mixin/SignableCommandMixin.java → ...xtras/mixin/fix/SignableCommandMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters