Search in sources :

Example 1 with IJEIIngredientHelper

use of mekanism.client.jei.interfaces.IJEIIngredientHelper in project Mekanism by mekanism.

the class GuiElementHandler method getIngredientUnderMouse.

@Nullable
private Object getIngredientUnderMouse(List<? extends IGuiEventListener> children, double mouseX, double mouseY) {
    for (IGuiEventListener child : children) {
        if (child instanceof Widget) {
            Widget widget = (Widget) child;
            if (!widget.visible) {
                // Skip this child if it isn't visible
                continue;
            }
            if (widget instanceof GuiElement) {
                GuiElement element = (GuiElement) widget;
                // Start by checking if we have any grandchildren that have an element being hovered as if we do it is the one
                // we want to take as the grandchildren in general should be a more "forward" facing layer
                Object underGrandChild = getIngredientUnderMouse(element.children(), mouseX, mouseY);
                if (underGrandChild != null) {
                    // If we have a grandchild that was an ingredient helper, return its ingredient
                    return underGrandChild;
                }
            }
        }
        if (child instanceof IJEIIngredientHelper && child.isMouseOver(mouseX, mouseY)) {
            return ((IJEIIngredientHelper) child).getIngredient(mouseX, mouseY);
        }
    }
    return null;
}
Also used : IGuiEventListener(net.minecraft.client.gui.IGuiEventListener) Widget(net.minecraft.client.gui.widget.Widget) GuiElement(mekanism.client.gui.element.GuiElement) IJEIIngredientHelper(mekanism.client.jei.interfaces.IJEIIngredientHelper) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)1 GuiElement (mekanism.client.gui.element.GuiElement)1 IJEIIngredientHelper (mekanism.client.jei.interfaces.IJEIIngredientHelper)1 IGuiEventListener (net.minecraft.client.gui.IGuiEventListener)1 Widget (net.minecraft.client.gui.widget.Widget)1