55import java .util .Collection ;
66import java .util .List ;
77import java .util .Optional ;
8+ import java .util .function .BiFunction ;
89import java .util .function .BooleanSupplier ;
9- import java .util .function .Function ;
1010import java .util .function .Supplier ;
1111import mekanism .api .text .ILangEntry ;
1212import mekanism .client .gui .element .GuiElement ;
@@ -194,7 +194,8 @@ public ItemStack getCarriedItem() {
194194 }
195195
196196 @ Nullable
197- private ComponentPath handleNavigationWithWindows (Function <ContainerEventHandler , @ Nullable ComponentPath > handleNavigation ) {
197+ private <NAVIGATION extends FocusNavigationEvent > ComponentPath handleNavigationWithWindows (NAVIGATION navigation ,
198+ BiFunction <ContainerEventHandler , NAVIGATION , @ Nullable ComponentPath > handleNavigation ) {
198199 GuiWindow topWindow = windows .head ();
199200 List <GuiEventListener > combinedChildren ;
200201 //Note: As allowContainer wise only allows interacting with slots, which we don't have navigation for, we check against allowAll.
@@ -239,7 +240,7 @@ public ScreenRectangle getRectangle() {
239240 return GuiMekanism .this .getRectangle ();
240241 }
241242 };
242- ComponentPath componentPath = handleNavigation .apply (handlerWithWindows );
243+ ComponentPath componentPath = handleNavigation .apply (handlerWithWindows , navigation );
243244 if (componentPath == null ) {
244245 return null ;
245246 } else if (componentPath instanceof ComponentPath .Path path ) {
@@ -259,7 +260,7 @@ public ComponentPath handleTabNavigation(@NotNull FocusNavigationEvent.TabNaviga
259260 if (windows .isEmpty ()) {
260261 return super .handleTabNavigation (navigation );
261262 }
262- return handleNavigationWithWindows (handlerWithWindows -> handlerWithWindows . handleTabNavigation ( navigation ) );
263+ return handleNavigationWithWindows (navigation , ContainerEventHandler :: handleTabNavigation );
263264 }
264265
265266 @ Nullable
@@ -268,7 +269,7 @@ public ComponentPath handleArrowNavigation(@NotNull FocusNavigationEvent.ArrowNa
268269 if (windows .isEmpty ()) {
269270 return super .handleArrowNavigation (navigation );
270271 }
271- return handleNavigationWithWindows (handlerWithWindows -> handlerWithWindows . handleArrowNavigation ( navigation ) );
272+ return handleNavigationWithWindows (navigation , ContainerEventHandler :: handleArrowNavigation );
272273 }
273274
274275 @ Override
@@ -376,7 +377,7 @@ protected void renderLabels(@NotNull GuiGraphics guiGraphics, int mouseX, int mo
376377 // then render tooltips, translating above max z offset to prevent clashing
377378 GuiElement tooltipElement = getWindowHovering (mouseX , mouseY );
378379 if (tooltipElement == null ) {
379- tooltipElement = (GuiElement ) GuiUtils .findChild (children (), child -> child instanceof GuiElement && child .isMouseOver (mouseX , mouseY ));
380+ tooltipElement = (GuiElement ) GuiUtils .findChild (children (), mouseX , mouseY , ( child , x , y ) -> child instanceof GuiElement && child .isMouseOver (x , y ));
380381 }
381382
382383 // translate forwards using RenderSystem. this should never have to happen as we do all the necessary translations with MatrixStacks,
@@ -458,7 +459,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
458459 }
459460 // otherwise, we send it to the current element (this is the same as super.super [ContainerEventHandler#mouseClicked], but in reverse order)
460461 //TODO: Why do we do this in reverse order?
461- GuiEventListener clickedChild = GuiUtils .findChild (children (), child -> child . mouseClicked ( mouseX , mouseY , button ) );
462+ GuiEventListener clickedChild = GuiUtils .findChild (children (), mouseX , mouseY , button , GuiEventListener :: mouseClicked );
462463 if (clickedChild != null ) {
463464 setFocused (clickedChild );
464465 if (button == GLFW .GLFW_MOUSE_BUTTON_LEFT ) {
@@ -491,7 +492,7 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
491492 return true ;
492493 }
493494 }
494- return GuiUtils .checkChildren (children (), child -> child instanceof GuiElement && child .keyPressed (keyCode , scanCode , modifiers )) ||
495+ return GuiUtils .checkChildren (children (), keyCode , scanCode , modifiers , ( child , k , s , m ) -> child instanceof GuiElement && child .keyPressed (k , s , m )) ||
495496 super .keyPressed (keyCode , scanCode , modifiers );
496497 }
497498
@@ -502,7 +503,7 @@ public boolean charTyped(char c, int keyCode) {
502503 return true ;
503504 }
504505 }
505- return GuiUtils .checkChildren (children (), child -> child instanceof GuiElement && child .charTyped (c , keyCode )) || super .charTyped (c , keyCode );
506+ return GuiUtils .checkChildrenChar (children (), c , keyCode , ( child , ch , k ) -> child instanceof GuiElement && child .charTyped (ch , k )) || super .charTyped (c , keyCode );
506507 }
507508
508509 /**
@@ -550,8 +551,12 @@ protected Slot findSlot(double mouseX, double mouseY) {
550551 if (overNoButtons && slot .isActive ()) {
551552 if (window == null ) {
552553 return slot ;
553- } else if (virtual && window .childrenContainsElement (element -> element instanceof GuiVirtualSlot v && v .isElementForSlot ((IVirtualSlot ) slot ))) {
554- return slot ;
554+ } else if (virtual ) {
555+ for (GuiElement child : window .children ()) {
556+ if (child instanceof GuiVirtualSlot v && v .isElementForSlot ((IVirtualSlot ) slot )) {
557+ return slot ;
558+ }
559+ }
555560 }
556561 }
557562 }
@@ -570,8 +575,14 @@ protected boolean isMouseOverSlot(@NotNull Slot slot, double mouseX, double mous
570575 if (super .isHovering (xPos , yPos , 16 , 16 , mouseX , mouseY )) {
571576 GuiWindow window = getWindowHovering (mouseX , mouseY );
572577 //If we are hovering over a window, check if the virtual slot is a child of the window
573- if (window == null || window .childrenContainsElement (element -> element instanceof GuiVirtualSlot v && v .isElementForSlot (virtualSlot ))) {
574- return overNoButtons (window , mouseX , mouseY );
578+ if (window == null ) {
579+ return overNoButtons ((GuiWindow ) null , mouseX , mouseY );
580+ } else {
581+ for (GuiElement child : window .children ()) {
582+ if (child instanceof GuiVirtualSlot v && v .isElementForSlot (virtualSlot )) {
583+ return overNoButtons (window , mouseX , mouseY );
584+ }
585+ }
575586 }
576587 }
577588 }
@@ -582,14 +593,18 @@ protected boolean isMouseOverSlot(@NotNull Slot slot, double mouseX, double mous
582593
583594 private boolean overNoButtons (@ Nullable GuiWindow window , double mouseX , double mouseY ) {
584595 if (window == null ) {
585- for (GuiEventListener child : children ()) {
586- if (child .isMouseOver (mouseX , mouseY )) {
587- return false ;
588- }
596+ return overNoButtons (children (), mouseX , mouseY );
597+ }
598+ return overNoButtons (window .children (), mouseX , mouseY );
599+ }
600+
601+ private static boolean overNoButtons (List <? extends GuiEventListener > children , double mouseX , double mouseY ) {
602+ for (GuiEventListener child : children ) {
603+ if (child .isMouseOver (mouseX , mouseY )) {
604+ return false ;
589605 }
590- return true ;
591606 }
592- return ! window . childrenContainsElement ( e -> e . isMouseOver ( mouseX , mouseY )) ;
607+ return true ;
593608 }
594609
595610 private boolean isVirtualSlotAvailable (IVirtualSlot virtualSlot ) {
0 commit comments