Search in sources :

Example 11 with IGuiEventListener

use of net.minecraft.client.gui.IGuiEventListener 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

IGuiEventListener (net.minecraft.client.gui.IGuiEventListener)11 Constraint (me.ichun.mods.ichunutil.client.gui.bns.window.constraint.Constraint)3 Fragment (me.ichun.mods.ichunutil.client.gui.bns.window.Fragment)2 GuiElement (mekanism.client.gui.element.GuiElement)2 Widget (net.minecraft.client.gui.widget.Widget)2 ArrayList (java.util.ArrayList)1 BooleanSupplier (java.util.function.BooleanSupplier)1 Nullable (javax.annotation.Nullable)1 GuiWindow (mekanism.client.gui.element.window.GuiWindow)1 IJEIGhostTarget (mekanism.client.jei.interfaces.IJEIGhostTarget)1 IGhostIngredientConsumer (mekanism.client.jei.interfaces.IJEIGhostTarget.IGhostIngredientConsumer)1 IJEIIngredientHelper (mekanism.client.jei.interfaces.IJEIIngredientHelper)1 Slot (net.minecraft.inventory.container.Slot)1 ItemStack (net.minecraft.item.ItemStack)1 BackpackInventorySlot (net.p3pp3rf1y.sophisticatedbackpacks.common.gui.BackpackInventorySlot)1