Skip to content

Commit

Permalink
Add javadocs
Browse files Browse the repository at this point in the history
  • Loading branch information
MDLC01 committed Apr 23, 2023
1 parent 293b79e commit 6cb1a99
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,30 @@

@Mixin(KeyboardHandler.class)
public abstract class KeyboardHandlerMixin {
/**
* Remaps a chunk debug key.
* <p>
* Chunk debug keys are not accessible in vanilla, but can be activated through modifications.
*/
@ModifyVariable(method = "handleChunkDebugKeys", at = @At("HEAD"), argsOnly = true)
private int remapChunkDebugKey(int keyCode) {
return Utils.remapKeyCodeToQWERTY(keyCode);
}

/**
* Remaps a debug key.
* <p>
* The Toggle Narrator key is not remapped; see <a
* href="https://github.com/MDLC01/universal-shortcuts-mc/issues/3">issue #3</a>.
*/
@ModifyVariable(method = "handleDebugKeys", at = @At("HEAD"), argsOnly = true)
private int remapDebugKey(int keyCode) {
return Utils.remapKeyCodeToQWERTY(keyCode);
}

/**
* Remaps the debug key that crashes the game when held for 10 seconds.
*/
// We do not inject in InputConstants#isKeyDown because other mods might use it with an already remapped key code.
// This is also why this injector is so complicated. The @Slice is there to ensure we only match the right calls.
@ModifyArg(
Expand All @@ -31,7 +45,7 @@ private int remapDebugKey(int keyCode) {
to = @At(value = "FIELD", target = "Lnet/minecraft/client/KeyboardHandler;debugCrashKeyReportedCount:J", ordinal = 0)
)
)
private int remapIsKeyDownArgument(int keyCode) {
private int remapDebugCrashKey(int keyCode) {
return Utils.remapKeyCodeToQWERTY(keyCode);
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/mdlc/universalshortcuts/mixin/ScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

@Mixin(Screen.class)
public abstract class ScreenMixin extends AbstractContainerEventHandler {
/**
* Remaps the key that is used by the Select All shortcut to be <kbd>A</kbd> on all keyboards.
*/
@Inject(method = "isSelectAll", at = @At("HEAD"), cancellable = true)
private static void onIsSelectAll(int keyCode, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(
Expand All @@ -21,6 +24,9 @@ private static void onIsSelectAll(int keyCode, CallbackInfoReturnable<Boolean> c
);
}

/**
* Remaps the key that is used by the Copy shortcut to be <kbd>C</kbd> on all keyboards.
*/
@Inject(method = "isCopy", at = @At("HEAD"), cancellable = true)
private static void onIsCopy(int keyCode, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(
Expand All @@ -31,6 +37,9 @@ private static void onIsCopy(int keyCode, CallbackInfoReturnable<Boolean> cir) {
);
}

/**
* Remaps the key that is used by the Paste shortcut to be <kbd>V</kbd> on all keyboards.
*/
@Inject(method = "isPaste", at = @At("HEAD"), cancellable = true)
private static void onIsPaste(int keyCode, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(
Expand All @@ -41,6 +50,9 @@ private static void onIsPaste(int keyCode, CallbackInfoReturnable<Boolean> cir)
);
}

/**
* Remaps the key that is used by the Cut shortcut to be <kbd>X</kbd> on all keyboards.
*/
@Inject(method = "isCut", at = @At("HEAD"), cancellable = true)
private static void onIsCut(int keyCode, CallbackInfoReturnable<Boolean> cir) {
cir.setReturnValue(
Expand Down

0 comments on commit 6cb1a99

Please sign in to comment.