-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
102 additions
and
58 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
Fabric/src/main/java/mezz/jei/fabric/input/AmecsHelper.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,38 @@ | ||
package mezz.jei.fabric.input; | ||
|
||
import de.siphalor.amecs.api.KeyModifier; | ||
import de.siphalor.amecs.api.KeyModifiers; | ||
import mezz.jei.common.input.keys.JeiKeyModifier; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class AmecsHelper { | ||
private AmecsHelper() {} | ||
|
||
public static KeyModifier getJeiModifier(JeiKeyModifier modifier) { | ||
return switch (modifier) { | ||
case CONTROL_OR_COMMAND -> KeyModifier.CONTROL; | ||
case SHIFT -> KeyModifier.SHIFT; | ||
case ALT -> KeyModifier.ALT; | ||
case NONE -> KeyModifier.NONE; | ||
}; | ||
} | ||
|
||
public static List<JeiKeyModifier> getJeiModifiers(KeyModifiers modifiers) { | ||
if (modifiers.isUnset()) { | ||
return List.of(JeiKeyModifier.NONE); | ||
} | ||
List<JeiKeyModifier> modifiersList = new ArrayList<>(); | ||
if (modifiers.getAlt()) { | ||
modifiersList.add(JeiKeyModifier.ALT); | ||
} | ||
if (modifiers.getControl()) { | ||
modifiersList.add(JeiKeyModifier.CONTROL_OR_COMMAND); | ||
} | ||
if (modifiers.getShift()) { | ||
modifiersList.add(JeiKeyModifier.SHIFT); | ||
} | ||
return modifiersList; | ||
} | ||
} |
37 changes: 15 additions & 22 deletions
37
Fabric/src/main/java/mezz/jei/fabric/input/AmecsJeiKeyMapping.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
26 changes: 7 additions & 19 deletions
26
Fabric/src/main/java/mezz/jei/fabric/input/AmecsJeiKeyMappingBuilder.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 |
---|---|---|
@@ -1,46 +1,34 @@ | ||
package mezz.jei.fabric.input; | ||
|
||
import de.siphalor.amecs.api.AmecsKeyBinding; | ||
import de.siphalor.amecs.api.KeyModifiers; | ||
import com.mojang.blaze3d.platform.InputConstants; | ||
import mezz.jei.common.input.keys.IJeiKeyMappingInternal; | ||
import de.siphalor.amecs.api.KeyModifiers; | ||
import mezz.jei.common.input.keys.IJeiKeyMappingBuilder; | ||
import mezz.jei.common.input.keys.IJeiKeyMappingInternal; | ||
import mezz.jei.common.input.keys.JeiKeyModifier; | ||
|
||
public class AmecsJeiKeyMappingBuilder extends FabricJeiKeyMappingBuilder { | ||
protected KeyModifiers modifier = new KeyModifiers(); | ||
private final KeyModifiers modifier = new KeyModifiers(); | ||
|
||
public AmecsJeiKeyMappingBuilder(String category, String description) { | ||
super(category, description); | ||
this.modifier = new KeyModifiers(); | ||
} | ||
|
||
@Override | ||
public IJeiKeyMappingBuilder setModifier(JeiKeyModifier modifier) { | ||
this.modifier.unset(); | ||
switch (modifier) { | ||
case CONTROL_OR_COMMAND: | ||
this.modifier.setControl(true); | ||
break; | ||
case SHIFT: | ||
this.modifier.setShift(true); | ||
break; | ||
case ALT: | ||
this.modifier.setAlt(true); | ||
break; | ||
} | ||
var amecsModifier = AmecsHelper.getJeiModifier(modifier); | ||
this.modifier.set(amecsModifier, true); | ||
return this; | ||
} | ||
|
||
@Override | ||
protected IJeiKeyMappingInternal buildMouse(int mouseButton) { | ||
AmecsKeyBinding keyMapping = new AmecsKeyBinding(description, InputConstants.Type.MOUSE, mouseButton, category, modifier); | ||
var keyMapping = new AmecsKeyBindingWithContext(description, InputConstants.Type.MOUSE, mouseButton, category, modifier, context); | ||
return new AmecsJeiKeyMapping(keyMapping, context); | ||
} | ||
|
||
@Override | ||
public IJeiKeyMappingInternal buildKeyboardKey(int key) { | ||
AmecsKeyBinding keyMapping = new AmecsKeyBinding(description, InputConstants.Type.KEYSYM, key, category, modifier); | ||
var keyMapping = new AmecsKeyBindingWithContext(description, InputConstants.Type.KEYSYM, key, category, modifier, context); | ||
return new AmecsJeiKeyMapping(keyMapping, context); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
Fabric/src/main/java/mezz/jei/fabric/input/AmecsKeyBindingWithContext.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,30 @@ | ||
package mezz.jei.fabric.input; | ||
|
||
import com.mojang.blaze3d.platform.InputConstants; | ||
import de.siphalor.amecs.api.AmecsKeyBinding; | ||
import de.siphalor.amecs.api.KeyModifiers; | ||
import mezz.jei.common.input.keys.JeiKeyConflictContext; | ||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; | ||
import net.minecraft.client.KeyMapping; | ||
|
||
public class AmecsKeyBindingWithContext extends AmecsKeyBinding { | ||
private final JeiKeyConflictContext context; | ||
|
||
public AmecsKeyBindingWithContext(String id, InputConstants.Type type, int code, String category, KeyModifiers defaultModifiers, JeiKeyConflictContext context) { | ||
super(id, type, code, category, defaultModifiers); | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
public boolean same(KeyMapping binding) { | ||
// Special implementation which is aware of the key conflict context. | ||
if (binding instanceof AmecsKeyBindingWithContext other) { | ||
return KeyBindingHelper.getBoundKeyOf(this).equals(KeyBindingHelper.getBoundKeyOf(other)) && | ||
(context.conflicts(other.context) || other.context.conflicts(context)); | ||
} else { | ||
// This ensures symmetry between conflicts, as regular keybinds see this one as | ||
// being unbound and not conflicting. | ||
return false; | ||
} | ||
} | ||
} |
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