Search in sources :

Example 1 with GuiVirtualSlot

use of mekanism.client.gui.element.slot.GuiVirtualSlot in project Mekanism by mekanism.

the class GuiMekanism method isMouseOverSlot.

@Override
protected boolean isMouseOverSlot(@Nonnull Slot slot, double mouseX, double mouseY) {
    if (slot instanceof IVirtualSlot) {
        // Virtual slots need special handling to allow for matching them to the window they may be attached to
        IVirtualSlot virtualSlot = (IVirtualSlot) slot;
        int xPos = virtualSlot.getActualX();
        int yPos = virtualSlot.getActualY();
        if (super.isHovering(xPos, yPos, 16, 16, mouseX, mouseY)) {
            GuiWindow window = getWindowHovering(mouseX, mouseY);
            // If we are hovering over a window, check if the virtual slot is a child of the window
            if (window == null || window.childrenContainsElement(element -> element instanceof GuiVirtualSlot && ((GuiVirtualSlot) element).isElementForSlot(virtualSlot))) {
                return overNoButtons(window, mouseX, mouseY);
            }
        }
        return false;
    }
    return isHovering(slot.x, slot.y, 16, 16, mouseX, mouseY);
}
Also used : GuiElement(mekanism.client.gui.element.GuiElement) LRU(mekanism.common.lib.collection.LRU) ResourceType(mekanism.common.util.MekanismUtils.ResourceType) SelectedWindowData(mekanism.common.inventory.container.SelectedWindowData) BooleanSupplier(java.util.function.BooleanSupplier) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration) Pair(org.apache.commons.lang3.tuple.Pair) SlotOverlay(mekanism.common.inventory.container.slot.SlotOverlay) GuiWindow(mekanism.client.gui.element.window.GuiWindow) Collection(java.util.Collection) SlotType(mekanism.client.gui.element.slot.SlotType) MekanismUtils(mekanism.common.util.MekanismUtils) WarningTracker(mekanism.client.gui.warning.WarningTracker) List(java.util.List) IWarningTracker(mekanism.client.gui.warning.IWarningTracker) MekanismRenderer(mekanism.client.render.MekanismRenderer) Optional(java.util.Optional) MekanismContainer(mekanism.common.inventory.container.MekanismContainer) GuiSlot(mekanism.client.gui.element.slot.GuiSlot) GuiWarningTab(mekanism.client.gui.element.tab.GuiWarningTab) Container(net.minecraft.inventory.container.Container) IGuiEventListener(net.minecraft.client.gui.IGuiEventListener) IVirtualSlot(mekanism.common.inventory.container.slot.IVirtualSlot) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) ITextComponent(net.minecraft.util.text.ITextComponent) WarningType(mekanism.client.gui.warning.WarningTracker.WarningType) ItemStack(net.minecraft.item.ItemStack) ItemRenderer(net.minecraft.client.renderer.ItemRenderer) Minecraft(net.minecraft.client.Minecraft) Slot(net.minecraft.inventory.container.Slot) ILangEntry(mekanism.api.text.ILangEntry) Nonnull(javax.annotation.Nonnull) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) Nullable(javax.annotation.Nullable) TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) Mekanism(mekanism.common.Mekanism) PlayerInventory(net.minecraft.entity.player.PlayerInventory) Widget(net.minecraft.client.gui.widget.Widget) DataType(mekanism.common.tile.component.config.DataType) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) IFancyFontRenderer(mekanism.client.render.IFancyFontRenderer) ContainerSlotType(mekanism.common.inventory.container.slot.ContainerSlotType) FontRenderer(net.minecraft.client.gui.FontRenderer) IHoverable(mekanism.client.gui.element.GuiElement.IHoverable) MekanismTileContainer(mekanism.common.inventory.container.tile.MekanismTileContainer) RenderSystem(com.mojang.blaze3d.systems.RenderSystem) ResourceLocation(net.minecraft.util.ResourceLocation) GuiVirtualSlot(mekanism.client.gui.element.slot.GuiVirtualSlot) GuiVirtualSlot(mekanism.client.gui.element.slot.GuiVirtualSlot) IVirtualSlot(mekanism.common.inventory.container.slot.IVirtualSlot) GuiWindow(mekanism.client.gui.element.window.GuiWindow)

Example 2 with GuiVirtualSlot

use of mekanism.client.gui.element.slot.GuiVirtualSlot in project Mekanism by mekanism.

the class GuiMekanism method findSlot.

@Nullable
@Override
// Don't use directly, this is normally private in ContainerScreen
@Deprecated
protected Slot findSlot(double mouseX, double mouseY) {
    // We override the implementation we have in VirtualSlotContainerScreen so that we can cache getting our window
    // and have some general performance improvements given we can batch a bunch of lookups together
    boolean checkedWindow = false;
    boolean overNoButtons = false;
    GuiWindow window = null;
    for (Slot slot : menu.slots) {
        boolean virtual = slot instanceof IVirtualSlot;
        int xPos = slot.x;
        int yPos = slot.y;
        if (virtual) {
            // Virtual slots need special handling to allow for matching them to the window they may be attached to
            IVirtualSlot virtualSlot = (IVirtualSlot) slot;
            xPos = virtualSlot.getActualX();
            yPos = virtualSlot.getActualY();
        }
        if (super.isHovering(xPos, yPos, 16, 16, mouseX, mouseY)) {
            if (!checkedWindow) {
                // Only lookup the window once
                checkedWindow = true;
                window = getWindowHovering(mouseX, mouseY);
                overNoButtons = overNoButtons(window, mouseX, mouseY);
            }
            if (overNoButtons && slot.isActive()) {
                if (window == null) {
                    return slot;
                } else if (virtual && window.childrenContainsElement(element -> element instanceof GuiVirtualSlot && ((GuiVirtualSlot) element).isElementForSlot((IVirtualSlot) slot))) {
                    return slot;
                }
            }
        }
    }
    return null;
}
Also used : GuiVirtualSlot(mekanism.client.gui.element.slot.GuiVirtualSlot) IVirtualSlot(mekanism.common.inventory.container.slot.IVirtualSlot) GuiWindow(mekanism.client.gui.element.window.GuiWindow) GuiSlot(mekanism.client.gui.element.slot.GuiSlot) IVirtualSlot(mekanism.common.inventory.container.slot.IVirtualSlot) Slot(net.minecraft.inventory.container.Slot) InventoryContainerSlot(mekanism.common.inventory.container.slot.InventoryContainerSlot) GuiVirtualSlot(mekanism.client.gui.element.slot.GuiVirtualSlot) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)2 GuiSlot (mekanism.client.gui.element.slot.GuiSlot)2 GuiVirtualSlot (mekanism.client.gui.element.slot.GuiVirtualSlot)2 GuiWindow (mekanism.client.gui.element.window.GuiWindow)2 IVirtualSlot (mekanism.common.inventory.container.slot.IVirtualSlot)2 InventoryContainerSlot (mekanism.common.inventory.container.slot.InventoryContainerSlot)2 Slot (net.minecraft.inventory.container.Slot)2 MatrixStack (com.mojang.blaze3d.matrix.MatrixStack)1 RenderSystem (com.mojang.blaze3d.systems.RenderSystem)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Optional (java.util.Optional)1 BooleanSupplier (java.util.function.BooleanSupplier)1 Supplier (java.util.function.Supplier)1 Nonnull (javax.annotation.Nonnull)1 ILangEntry (mekanism.api.text.ILangEntry)1 GuiElement (mekanism.client.gui.element.GuiElement)1 IHoverable (mekanism.client.gui.element.GuiElement.IHoverable)1 SlotType (mekanism.client.gui.element.slot.SlotType)1