2323import net .minecraft .client .gui .Font ;
2424import net .minecraft .client .gui .components .EditBox ;
2525import net .minecraft .client .gui .components .Tooltip ;
26- import net .minecraft .client .gui .screens .Screen ;
26+ import net .minecraft .client .input .KeyEvent ;
27+ import net .minecraft .client .input .MouseButtonEvent ;
2728import net .minecraft .network .chat .Component ;
2829import net .minecraft .util .Mth ;
2930import org .jetbrains .annotations .NotNull ;
@@ -166,8 +167,8 @@ public void setTextColor(int color) {
166167 // Chained clicks and click-drag
167168
168169 @ Override
169- public boolean mouseClicked (double mouseX , double mouseY , int button ) {
170- if (super .mouseClicked (mouseX , mouseY , button )) {
170+ public boolean mouseClicked (MouseButtonEvent event , boolean doubleClick ) {
171+ if (super .mouseClicked (event , doubleClick )) {
171172 long time = Util .getMillis ();
172173 if (lastClickTime + CLICK_CHAIN_TIME > time ) {
173174 switch (++chainedClicks ) {
@@ -205,7 +206,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
205206 lastClickTime = time ;
206207
207208 // Reset drag origin
208- dragOriginX = mouseX ;
209+ dragOriginX = event . x () ;
209210 dragOriginPos = getCursorPosition ();
210211
211212 return true ;
@@ -214,27 +215,21 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
214215 }
215216
216217 @ Override
217- public boolean mouseDragged (
218- double mouseX ,
219- double mouseY ,
220- int button ,
221- double dragX ,
222- double dragY
223- ) {
224- if (button != 0 )
218+ public boolean mouseDragged (MouseButtonEvent event , double dragX , double dragY ) {
219+ if (event .button () != 0 )
225220 return false ;
226221 String str = getValue ();
227222
228- if (mouseX < dragOriginX ) { // Dragging left
223+ if (event . x () < dragOriginX ) { // Dragging left
229224 String subLeft = str .substring (0 , dragOriginPos );
230225 int offsetChars =
231- font .plainSubstrByWidth (subLeft , Mth .floor (dragOriginX - mouseX ), true )
226+ font .plainSubstrByWidth (subLeft , Mth .floor (dragOriginX - event . x () ), true )
232227 .length ();
233228 moveCursorTo (dragOriginPos - offsetChars , true );
234229 } else { // Dragging right
235230 String subRight = str .substring (dragOriginPos );
236231 int offsetChars =
237- font .plainSubstrByWidth (subRight , Mth .floor (mouseX - dragOriginX ), false )
232+ font .plainSubstrByWidth (subRight , Mth .floor (event . x () - dragOriginX ), false )
238233 .length ();
239234 moveCursorTo (dragOriginPos + offsetChars , true );
240235 }
@@ -258,12 +253,12 @@ private void updateHistory(String str) {
258253 }
259254
260255 @ Override
261- public boolean keyPressed (int keyCode , int scanCode , int modifiers ) {
262- if (!super .keyPressed (keyCode , scanCode , modifiers )) {
263- if (isUndo (keyCode )) {
256+ public boolean keyPressed (KeyEvent event ) {
257+ if (!super .keyPressed (event )) {
258+ if (isUndo (event )) {
264259 undo ();
265260 return true ;
266- } else if (isRedo (keyCode )) {
261+ } else if (isRedo (event )) {
267262 redo ();
268263 return true ;
269264 }
@@ -311,13 +306,17 @@ public Optional<Component> validate(String str) {
311306
312307 // Utility methods
313308
314- public static boolean isUndo (int keyCode ) {
315- return keyCode == InputConstants .KEY_Z && Screen .hasControlDown () && !Screen .hasShiftDown ()
316- && !Screen .hasAltDown ();
309+ public static boolean isUndo (KeyEvent event ) {
310+ return event .key () == InputConstants .KEY_Z
311+ && event .hasControlDown ()
312+ && !event .hasShiftDown ()
313+ && !event .hasAltDown ();
317314 }
318315
319- public static boolean isRedo (int keyCode ) {
320- return keyCode == InputConstants .KEY_Y && Screen .hasControlDown () && !Screen .hasShiftDown ()
321- && !Screen .hasAltDown ();
316+ public static boolean isRedo (KeyEvent event ) {
317+ return event .key () == InputConstants .KEY_Y
318+ && event .hasControlDown ()
319+ && !event .hasShiftDown ()
320+ && !event .hasAltDown ();
322321 }
323322}
0 commit comments