From 4f1bb0a3913ffb4813cc51f7e4bdaf603e15579c Mon Sep 17 00:00:00 2001 From: enbrain <69905075+enbrain@users.noreply.github.com> Date: Thu, 13 May 2021 15:10:36 +0900 Subject: [PATCH] Document KeyBinding.isPressed and KeyBinding.wasPressed (#2393) * Document KeyBinding.isPressed and KeyBinding.wasPressed * Apply suggestions from code review Co-authored-by: liach <7806504+liach@users.noreply.github.com> Co-authored-by: liach <7806504+liach@users.noreply.github.com> --- .../client/option/KeyBinding.mapping | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mappings/net/minecraft/client/option/KeyBinding.mapping b/mappings/net/minecraft/client/option/KeyBinding.mapping index 4dc1717ba8..38b85e2351 100644 --- a/mappings/net/minecraft/client/option/KeyBinding.mapping +++ b/mappings/net/minecraft/client/option/KeyBinding.mapping @@ -51,9 +51,33 @@ CLASS net/minecraft/class_304 net/minecraft/client/option/KeyBinding METHOD method_1433 matchesMouse (I)Z ARG 1 code METHOD method_1434 isPressed ()Z + COMMENT {@return if the key is being held down} + COMMENT + COMMENT

Note that if you are continuously calling this method (like every + COMMENT tick), it doesn't always catch all key presses. This is because the key + COMMENT can be pressed and released before the next check. + COMMENT + COMMENT @see #wasPressed() METHOD method_1435 equals (Lnet/minecraft/class_304;)Z ARG 1 other METHOD method_1436 wasPressed ()Z + COMMENT {@return if the key was pressed} + COMMENT + COMMENT

A key binding counts the number of times the key is pressed. This + COMMENT method "consumes" it and returns {@code true} as many times as the key + COMMENT is pressed. + COMMENT + COMMENT

To consume all remaining key presses, while-loop idiom can be used: + COMMENT

+		COMMENT {@code
+		COMMENT while(keyBinding.wasPressed()) {
+		COMMENT   // do your action
+		COMMENT }
+		COMMENT }
+		COMMENT 
+ COMMENT + COMMENT @see #isPressed() + COMMENT @see MC-118107 METHOD method_1437 unpressAll ()V METHOD method_16007 getBoundKeyLocalizedText ()Lnet/minecraft/class_2561; METHOD method_23481 setPressed (Z)V