Search in sources :

Example 1 with IGhostIngredientConsumer

use of mekanism.client.jei.interfaces.IJEIGhostTarget.IGhostIngredientConsumer in project Mekanism by mekanism.

the class GhostIngredientHandler method getTargets.

private <INGREDIENT> List<TargetInfo<INGREDIENT>> getTargets(List<? extends IGuiEventListener> children, INGREDIENT ingredient) {
    List<TargetInfo<INGREDIENT>> ghostTargets = new ArrayList<>();
    for (IGuiEventListener child : children) {
        if (child instanceof Widget) {
            Widget widget = (Widget) child;
            if (widget.visible) {
                if (widget instanceof GuiElement) {
                    // Start by adding any grandchild ghost targets we have as they are the "top" layer, and we want them
                    // to get checked/interacted with first
                    ghostTargets.addAll(getTargets(((GuiElement) widget).children(), ingredient));
                }
                // Then go ahead and check if our element is a ghost target and if it is, and it supports the ingredient add it
                if (widget instanceof IJEIGhostTarget) {
                    IJEIGhostTarget ghostTarget = (IJEIGhostTarget) widget;
                    IGhostIngredientConsumer ghostHandler = ghostTarget.getGhostHandler();
                    if (ghostHandler != null && ghostHandler.supportsIngredient(ingredient)) {
                        ghostTargets.add(new TargetInfo<>(ghostTarget, ghostHandler, widget.x, widget.y, widget.getWidth(), widget.getHeight()));
                    }
                }
            }
        }
    }
    return ghostTargets;
}
Also used : IGuiEventListener(net.minecraft.client.gui.IGuiEventListener) ArrayList(java.util.ArrayList) Widget(net.minecraft.client.gui.widget.Widget) IJEIGhostTarget(mekanism.client.jei.interfaces.IJEIGhostTarget) IGhostIngredientConsumer(mekanism.client.jei.interfaces.IJEIGhostTarget.IGhostIngredientConsumer) GuiElement(mekanism.client.gui.element.GuiElement)

Aggregations

ArrayList (java.util.ArrayList)1 GuiElement (mekanism.client.gui.element.GuiElement)1 IJEIGhostTarget (mekanism.client.jei.interfaces.IJEIGhostTarget)1 IGhostIngredientConsumer (mekanism.client.jei.interfaces.IJEIGhostTarget.IGhostIngredientConsumer)1 IGuiEventListener (net.minecraft.client.gui.IGuiEventListener)1 Widget (net.minecraft.client.gui.widget.Widget)1