Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
a3c342d
UScreen: create ConsumableInputHandler interface
Traben-0 Mar 5, 2026
6e0b76a
UScreen: add uSuperConsumableInputHandler() implementation
Traben-0 Mar 5, 2026
139666a
UScreen: implement ConsumableInputHandler forwarding
Traben-0 Mar 5, 2026
951e5a6
UScreen: block ISO Control characters from super.charTyped()
Traben-0 Mar 5, 2026
d8b45ce
API: update
Traben-0 Mar 5, 2026
838a66b
UScreen: revert diff to old behaviour
Traben-0 Mar 6, 2026
c20a4ba
UScreen: prevent control code characters in older minecraft events to…
Traben-0 Mar 6, 2026
1cc2422
Review:
Traben-0 Mar 10, 2026
73e8e28
missed preprocessor block changes
Traben-0 Mar 10, 2026
7b3d183
api changes
Traben-0 Mar 10, 2026
1b0bfa6
Merge remote-tracking branch 'origin/feature/em-1645-closing-uscreen-…
Traben-0 Mar 10, 2026
705f710
Review: protect field
Traben-0 Mar 10, 2026
b235141
api change
Traben-0 Mar 10, 2026
2097acf
Review: drop consumable prefix
Traben-0 Mar 18, 2026
db1fdc3
Review: pass scancode
Traben-0 Mar 18, 2026
eafc88b
Review: use codepoint
Traben-0 Mar 18, 2026
716576d
missed comment renames
Traben-0 Mar 18, 2026
970674e
Review: pass modifiers
Traben-0 Mar 18, 2026
b89c0f6
Review: revert original functions
Traben-0 Mar 18, 2026
cea00b8
Review: remove timeSinceLastClick and add x/y offsets in modern function
Traben-0 Mar 18, 2026
b3ab8f0
Review: only pass valid keycodes and chars
Traben-0 Mar 18, 2026
56ea5e7
Review: remove catches
Traben-0 Mar 18, 2026
c0cdcb0
Review: remove pre caught conditions
Traben-0 Mar 18, 2026
accfa3c
Review: remove nullable modifiers
Traben-0 Mar 18, 2026
77134dc
Review: parameter name nits
Traben-0 Mar 18, 2026
f2d52e3
Review: remove old code
Traben-0 Mar 18, 2026
74df627
Review: kdocs
Traben-0 Mar 18, 2026
c70ade6
Review: deprecation message
Traben-0 Mar 18, 2026
a0b8831
Merge branch 'master' into feature/em-1645-closing-uscreen-via-esc-on…
Traben-0 Mar 18, 2026
82b82a1
Review: new mouse scroll method
Traben-0 Mar 18, 2026
7fd377c
missing 26.1 block
Traben-0 Mar 18, 2026
c0e344c
api bump
Traben-0 Mar 18, 2026
5da550e
Review: drop char modifiers
Traben-0 Mar 19, 2026
b0a244f
Review: use 0 scancode
Traben-0 Mar 19, 2026
36f0f98
Review: fix renames in comments
Traben-0 Mar 19, 2026
200b317
Review: fix indent
Traben-0 Mar 19, 2026
8e699a3
Review: move supression
Traben-0 Mar 19, 2026
8404585
Review: remove dragged x and y params
Traben-0 Mar 19, 2026
c8a438c
remove params from preprocessor blocks
Traben-0 Mar 19, 2026
07ef250
Review: param name change
Traben-0 Mar 19, 2026
d1a5cd4
Review: Modifiers? -> Modifiers
Traben-0 Mar 19, 2026
53fb6c7
Review: @Suppress("unused")
Traben-0 Mar 19, 2026
250088c
API bump
Traben-0 Mar 19, 2026
16bab97
Review: spacing
Traben-0 Mar 23, 2026
43a7905
Review: var usage
Traben-0 Mar 23, 2026
3fd5319
Review: var name
Traben-0 Mar 23, 2026
5402cf7
Review: 1.21.9 case too
Traben-0 Mar 24, 2026
0c4c400
implement in standalone UScreen
Traben-0 Mar 24, 2026
27212ed
missing closing bracket
Traben-0 Mar 24, 2026
d9a1f6b
missing preprocessor block
Traben-0 Mar 24, 2026
6669e89
Review: fix indent
Traben-0 Mar 26, 2026
dd0bf25
Review: use an internal property
Traben-0 Mar 26, 2026
0fa2810
Review: pass fractional mouse pos in older mc
Traben-0 Apr 5, 2026
e3f9a1f
Review: block PUA characters
Traben-0 Apr 9, 2026
077b0f5
Merge remote-tracking branch 'origin/feature/em-1645-closing-uscreen-…
Traben-0 Apr 9, 2026
ba5403e
Review: restore fractional mouse without overriding the input positions
Traben-0 Apr 9, 2026
a9da605
Review from elementa: add super key to modifiers
Traben-0 Apr 26, 2026
0e948fd
Review from elementa: deprecation directing users to use provided key…
Traben-0 Apr 26, 2026
522acc4
fix non-final property name in preprocessed block
Traben-0 Apr 26, 2026
f3f15af
api changes
Traben-0 Apr 26, 2026
0a05061
change check and naming
Traben-0 Apr 26, 2026
c0a5cc5
further modifier options
Traben-0 Apr 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions api/UniversalCraft.api
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ public final class gg/essential/universal/UKeyboard {
public static final field KEY_Y I
public static final field KEY_Z I
public static final fun allowRepeatEvents (Z)V
public static final fun getKeyModifiers ()Lgg/essential/universal/UKeyboard$Modifiers;
public static final fun getKeyName (I)Ljava/lang/String;
public static final fun getKeyName (II)Ljava/lang/String;
@1.17.1-forge,1.18.1-forge,1.19.2-forge,1.19.3-forge,1.19.4-forge,1.20.1-forge,1.20.2-forge,1.20.4-forge,1.20.4-neoforge,1.20.6-forge,1.20.6-neoforge,1.21-forge,1.21-neoforge,1.21.3-forge,1.21.3-neoforge,1.21.4-forge,1.21.4-neoforge,1.21.5-forge,1.21.5-neoforge,1.21.7-forge,1.21.7-neoforge,26.1-fabric
Expand All @@ -541,6 +542,8 @@ public final class gg/essential/universal/UKeyboard {
public static final fun getKeyName (Lnet/minecraft/client/settings/KeyBinding;)Ljava/lang/String;
public static final fun getModifiers ()Lgg/essential/universal/UKeyboard$Modifiers;
public static final fun isAltKeyDown ()Z
public static final fun isCommandKeyDown ()Z
public static final fun isControlKeyDown ()Z
public static final fun isCtrlKeyDown ()Z
public static final fun isEnterKey (I)Z
public static final fun isKeyComboCtrlA (I)Z
Expand All @@ -551,21 +554,27 @@ public final class gg/essential/universal/UKeyboard {
public static final fun isKeyComboCtrlY (I)Z
public static final fun isKeyComboCtrlZ (I)Z
public static final fun isKeyDown (I)Z
public static final fun isOSModifierKeyDown ()Z
public static final fun isShiftKeyDown ()Z
}

public final class gg/essential/universal/UKeyboard$Modifiers {
public fun <init> (ZZZ)V
public fun <init> (ZZZZ)V
public final fun component1 ()Z
public final fun component2 ()Z
public final fun component3 ()Z
public final fun copy (ZZZ)Lgg/essential/universal/UKeyboard$Modifiers;
public static synthetic fun copy$default (Lgg/essential/universal/UKeyboard$Modifiers;ZZZILjava/lang/Object;)Lgg/essential/universal/UKeyboard$Modifiers;
public final fun component4 ()Z
public final fun copy (ZZZZ)Lgg/essential/universal/UKeyboard$Modifiers;
public static synthetic fun copy$default (Lgg/essential/universal/UKeyboard$Modifiers;ZZZZILjava/lang/Object;)Lgg/essential/universal/UKeyboard$Modifiers;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public final fun isAlt ()Z
public final fun isCtrl ()Z
public final fun isOnlyPlatformModifierActive ()Z
public final fun isPlatformModifierActive ()Z
public final fun isShift ()Z
public final fun isSuper ()Z
public fun toString ()Ljava/lang/String;
}

Expand Down Expand Up @@ -865,6 +874,7 @@ public abstract class gg/essential/universal/UScreen : net/minecraft/client/gui/
@26.1-fabric
public final fun extractRenderState (Lnet/minecraft/client/gui/GuiGraphicsExtractor;IIF)V
public static final fun getCurrentScreen ()Lnet/minecraft/client/gui/screens/Screen;
protected final fun getInputHandler ()Lgg/essential/universal/UScreen$InputHandler;
public fun getNewGuiScale ()I
public final fun getRestoreCurrentGuiOnClose ()Z
public fun getTitle ()Lnet/minecraft/network/chat/Component;
Expand Down Expand Up @@ -923,9 +933,11 @@ public abstract class gg/essential/universal/UScreen : net/minecraft/client/gui/
@1.17.1-forge,1.18.1-forge,1.19.2-forge,1.19.3-forge
public final fun renderBackground (Lcom/mojang/blaze3d/vertex/PoseStack;I)V
public final fun restorePreviousScreen ()V
protected final fun setInputHandler (Lgg/essential/universal/UScreen$InputHandler;)V
public fun setNewGuiScale (I)V
public fun setUnlocalizedName (Ljava/lang/String;)V
public final fun tick ()V
public final fun uSuperInputHandler ()Lgg/essential/universal/UScreen$InputHandler;
public fun updateGuiScale ()V
}

Expand All @@ -945,6 +957,7 @@ public abstract class gg/essential/universal/UScreen : net/minecraft/client/gui/
public final fun charTyped (CI)Z
public static final fun displayScreen (Lnet/minecraft/client/gui/screen/Screen;)V
public static final fun getCurrentScreen ()Lnet/minecraft/client/gui/screen/Screen;
protected final fun getInputHandler ()Lgg/essential/universal/UScreen$InputHandler;
public fun getNewGuiScale ()I
public final fun getRestoreCurrentGuiOnClose ()Z
@1.16.2-forge
Expand Down Expand Up @@ -1013,9 +1026,11 @@ public abstract class gg/essential/universal/UScreen : net/minecraft/client/gui/
@1.16.2-fabric,1.17.1-fabric,1.18.1-fabric,1.19-fabric,1.19.1-fabric,1.19.2-fabric,1.19.3-fabric
public final fun renderBackground (Lnet/minecraft/client/util/math/MatrixStack;I)V
public final fun restorePreviousScreen ()V
protected final fun setInputHandler (Lgg/essential/universal/UScreen$InputHandler;)V
public fun setNewGuiScale (I)V
public fun setUnlocalizedName (Ljava/lang/String;)V
public final fun tick ()V
public final fun uSuperInputHandler ()Lgg/essential/universal/UScreen$InputHandler;
public fun updateGuiScale ()V
}

Expand All @@ -1033,6 +1048,7 @@ public abstract class gg/essential/universal/UScreen : net/minecraft/client/gui/
public final fun drawScreen (IIF)V
public final fun drawWorldBackground (I)V
public static final fun getCurrentScreen ()Lnet/minecraft/client/gui/GuiScreen;
protected final fun getInputHandler ()Lgg/essential/universal/UScreen$InputHandler;
public fun getNewGuiScale ()I
public final fun getRestoreCurrentGuiOnClose ()Z
public fun getUnlocalizedName ()Ljava/lang/String;
Expand All @@ -1059,8 +1075,10 @@ public abstract class gg/essential/universal/UScreen : net/minecraft/client/gui/
public fun onScreenClose ()V
public fun onTick ()V
public final fun restorePreviousScreen ()V
protected final fun setInputHandler (Lgg/essential/universal/UScreen$InputHandler;)V
public fun setNewGuiScale (I)V
public fun setUnlocalizedName (Ljava/lang/String;)V
public final fun uSuperInputHandler ()Lgg/essential/universal/UScreen$InputHandler;
public fun updateGuiScale ()V
public final fun updateScreen ()V
}
Expand All @@ -1080,6 +1098,17 @@ public final class gg/essential/universal/UScreen$Companion {
public final fun getCurrentScreen ()Lnet/minecraft/client/gui/GuiScreen;
}

public abstract interface class gg/essential/universal/UScreen$InputHandler {
public fun uCharTyped (I)Z
public fun uKeyPressed (IILgg/essential/universal/UKeyboard$Modifiers;)Z
public fun uKeyReleased (IILgg/essential/universal/UKeyboard$Modifiers;)Z
public fun uMouseClicked (DDILgg/essential/universal/UKeyboard$Modifiers;)Z
public fun uMouseDragged (DDILgg/essential/universal/UKeyboard$Modifiers;)Z
public fun uMouseReleased (DDILgg/essential/universal/UKeyboard$Modifiers;)Z
public fun uMouseScrolled (DDDD)Z
public abstract fun uSuperInputHandler ()Lgg/essential/universal/UScreen$InputHandler;
}

public final class gg/essential/universal/USound {
public static final field INSTANCE Lgg/essential/universal/USound;
public final fun playButtonPress ()V
Expand Down
68 changes: 59 additions & 9 deletions src/main/kotlin/gg/essential/universal/UKeyboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -270,40 +270,69 @@ object UKeyboard {
//#endif
}

@Deprecated("Use isOSModifierKeyDown() instead if you want the platform-appropriate modifier key (Ctrl on Windows/Linux, Command on Mac). " +
"Alternatively use isControlKeyDown() or isCommandKeyDown() if you specifically want to check for Ctrl or Command respectively.")
@JvmStatic
fun isCtrlKeyDown(): Boolean = if (UMinecraft.isRunningOnMac) {
isKeyDown(KEY_LMETA) || isKeyDown(KEY_RMETA)
} else isKeyDown(KEY_LCONTROL) || isKeyDown(KEY_RCONTROL)

@Deprecated("If using from a key event, use the provided modifiers instead of calling this method.")
@JvmStatic
fun isOSModifierKeyDown(): Boolean =
if (UMinecraft.isRunningOnMac) isCommandKeyDown()
else isControlKeyDown()

@Deprecated("If using from a key event, use the provided modifiers instead of calling this method.")
@JvmStatic
fun isCommandKeyDown(): Boolean = isKeyDown(KEY_LMETA) || isKeyDown(KEY_RMETA)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Would call this isSuperKeyDown, for consistency with our Modifier.isSuper.

That, or isMetaKeyDown, since that's what we call our KEY_ constants. But I think staying consistent with the new stuff (and lwjgl3, which also calls them GLFW_KEY_LEFT/RIGHT_SUPER) is better here.

I don't think we're calling it Command anywhere else.


@Deprecated("If using from a key event, use the provided modifiers instead of calling this method.")
@JvmStatic
fun isControlKeyDown(): Boolean = isKeyDown(KEY_LCONTROL) || isKeyDown(KEY_RCONTROL)

@Deprecated("If using from a key event, use the provided modifiers instead of calling this method.")
@JvmStatic
fun isShiftKeyDown(): Boolean = isKeyDown(KEY_LSHIFT) || isKeyDown(KEY_RSHIFT)

@Deprecated("If using from a key event, use the provided modifiers instead of calling this method.")
@JvmStatic
fun isAltKeyDown(): Boolean = isKeyDown(KEY_LMENU) || isKeyDown(KEY_RMENU)

@Deprecated("Inconsistent ctrl modifier behaviour depending on OS and MC versions", replaceWith = ReplaceWith("getKeyModifiers()"))
@JvmStatic
fun getModifiers(): Modifiers = Modifiers(isCtrlKeyDown(), isShiftKeyDown(), isAltKeyDown())
fun getModifiers(): Modifiers = Modifiers(isCtrlKeyDown(), isShiftKeyDown(), isAltKeyDown(), isCommandKeyDown())

@JvmStatic
fun isKeyComboCtrlA(key: Int): Boolean = key == KEY_A && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown()
fun getKeyModifiers(): Modifiers = Modifiers(isControlKeyDown(), isShiftKeyDown(), isAltKeyDown(), isCommandKeyDown())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: Not sure we should even provide this new variant of the getModifiers method.

You usually shouldn't be using getModifiers anyway because it depends on global state. You should be using the Modifiers instance that comes with your mouseClick/etc. call.


@Deprecated("If using from a key event, use the provided modifiers instead of calling this method.")
@JvmStatic
fun isKeyComboCtrlC(key: Int): Boolean = key == KEY_C && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown()
fun isKeyComboCtrlA(key: Int): Boolean = key == KEY_A && isOSModifierKeyDown() && !isShiftKeyDown() && !isAltKeyDown()

@Deprecated("If using from a key event, use the provided modifiers instead of calling this method.")
@JvmStatic
fun isKeyComboCtrlV(key: Int): Boolean = key == KEY_V && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown()
fun isKeyComboCtrlC(key: Int): Boolean = key == KEY_C && isOSModifierKeyDown() && !isShiftKeyDown() && !isAltKeyDown()

@Deprecated("If using from a key event, use the provided modifiers instead of calling this method.")
@JvmStatic
fun isKeyComboCtrlX(key: Int): Boolean = key == KEY_X && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown()
fun isKeyComboCtrlV(key: Int): Boolean = key == KEY_V && isOSModifierKeyDown() && !isShiftKeyDown() && !isAltKeyDown()

@Deprecated("If using from a key event, use the provided modifiers instead of calling this method.")
@JvmStatic
fun isKeyComboCtrlY(key: Int): Boolean = key == KEY_Y && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown()
fun isKeyComboCtrlX(key: Int): Boolean = key == KEY_X && isOSModifierKeyDown() && !isShiftKeyDown() && !isAltKeyDown()

@Deprecated("If using from a key event, use the provided modifiers instead of calling this method.")
@JvmStatic
fun isKeyComboCtrlZ(key: Int): Boolean = key == KEY_Z && isCtrlKeyDown() && !isShiftKeyDown() && !isAltKeyDown()
fun isKeyComboCtrlY(key: Int): Boolean = key == KEY_Y && isOSModifierKeyDown() && !isShiftKeyDown() && !isAltKeyDown()

@Deprecated("If using from a key event, use the provided modifiers instead of calling this method.")
@JvmStatic
fun isKeyComboCtrlShiftZ(key: Int): Boolean = key == KEY_Z && isCtrlKeyDown() && isShiftKeyDown() && !isAltKeyDown()
fun isKeyComboCtrlZ(key: Int): Boolean = key == KEY_Z && isOSModifierKeyDown() && !isShiftKeyDown() && !isAltKeyDown()

@Deprecated("If using from a key event, use the provided modifiers instead of calling this method.")
@JvmStatic
fun isKeyComboCtrlShiftZ(key: Int): Boolean = key == KEY_Z && isOSModifierKeyDown() && isShiftKeyDown() && !isAltKeyDown()

//#if STANDALONE
//$$ internal val keysDown = mutableSetOf<Int>()
Expand Down Expand Up @@ -390,19 +419,40 @@ object UKeyboard {
@JvmStatic
fun getKeyName(keyCode: Int): String? = getKeyName(keyCode, -1)

data class Modifiers(val isCtrl: Boolean, val isShift: Boolean, val isAlt: Boolean)
data class Modifiers(
val isCtrl: Boolean,
val isShift: Boolean,
val isAlt: Boolean,
val isSuper: Boolean,
) {
Comment on lines -393 to +427

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Breaking change. Also need to supply a three-args copy method. See the red lines in the .api file diff.

@Deprecated("Old constructor")
constructor(isCtrl: Boolean, isShift: Boolean, isAlt: Boolean) :
this(isCtrl, isShift, isAlt, isSuper = isCommandKeyDown())

/**
* Checks that only the OS specific modifier key is active (Ctrl on Windows/Linux, Command (super) on Mac).
*/
fun isPlatformModifierActive() = if (UMinecraft.isRunningOnMac) isSuper else isCtrl

fun isOnlyPlatformModifierActive() =
if (UMinecraft.isRunningOnMac) isSuper && !isShift && !isAlt && !isCtrl
else isCtrl && !isShift && !isAlt && !isSuper

}

//#if MC>=11502
//$$ internal fun Modifiers?.toInt() = listOf(
//$$ this?.isCtrl to GLFW.GLFW_MOD_CONTROL,
//$$ this?.isShift to GLFW.GLFW_MOD_SHIFT,
//$$ this?.isAlt to GLFW.GLFW_MOD_ALT,
//$$ this?.isSuper to GLFW.GLFW_MOD_SUPER,
//$$ ).sumOf { (modifier, value) -> if (modifier == true) value else 0 }
//$$
//$$ internal fun Int.toModifiers() = Modifiers(
//$$ isCtrl = (this and GLFW.GLFW_MOD_CONTROL) != 0,
//$$ isShift = (this and GLFW.GLFW_MOD_SHIFT) != 0,
//$$ isAlt = (this and GLFW.GLFW_MOD_ALT) != 0,
//$$ isSuper = (this and GLFW.GLFW_MOD_SUPER) != 0,
//$$ )
//#endif
}
Loading
Loading