Search in sources :

Example 1 with IVirtualSlot

use of mekanism.common.inventory.container.slot.IVirtualSlot in project Mekanism by mekanism.

the class VirtualSlotContainerScreen method renderSlot.

@Override
// Don't use directly, this is normally private in ContainerScreen
@Deprecated
protected final void renderSlot(@Nonnull MatrixStack matrixStack, @Nonnull Slot slot) {
    if (!(slot instanceof IVirtualSlot)) {
        // If we are not a virtual slot, the super method is good enough
        super.renderSlot(matrixStack, slot);
        return;
    }
    // Basically a copy of super.moveItems, except with the rendering at the bottom adjusted
    // for if we are a virtual slot
    ItemStack currentStack = slot.getItem();
    boolean shouldDrawOverlay = false;
    boolean skipStackRendering = slot == this.clickedSlot && !this.draggingItem.isEmpty() && !this.isSplittingStack;
    ItemStack heldStack = minecraft.player.inventory.getCarried();
    String s = null;
    if (slot == this.clickedSlot && !this.draggingItem.isEmpty() && this.isSplittingStack && !currentStack.isEmpty()) {
        currentStack = currentStack.copy();
        currentStack.setCount(currentStack.getCount() / 2);
    } else if (isQuickCrafting && quickCraftSlots.contains(slot) && !heldStack.isEmpty()) {
        if (quickCraftSlots.size() == 1) {
            return;
        }
        if (Container.canItemQuickReplace(slot, heldStack, true) && this.menu.canDragTo(slot)) {
            currentStack = heldStack.copy();
            shouldDrawOverlay = true;
            Container.getQuickCraftSlotCount(quickCraftSlots, this.quickCraftingType, currentStack, slot.getItem().isEmpty() ? 0 : slot.getItem().getCount());
            int k = Math.min(currentStack.getMaxStackSize(), slot.getMaxStackSize(currentStack));
            if (currentStack.getCount() > k) {
                s = TextFormatting.YELLOW.toString() + k;
                currentStack.setCount(k);
            }
        } else {
            quickCraftSlots.remove(slot);
            recalculateQuickCraftRemaining();
        }
    }
    // If the slot is a virtual slot, have the GuiSlot that corresponds to it handle the rendering
    ((IVirtualSlot) slot).updateRenderInfo(skipStackRendering ? ItemStack.EMPTY : currentStack, shouldDrawOverlay, s);
}
Also used : IVirtualSlot(mekanism.common.inventory.container.slot.IVirtualSlot) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IVirtualSlot

use of mekanism.common.inventory.container.slot.IVirtualSlot 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 3 with IVirtualSlot

use of mekanism.common.inventory.container.slot.IVirtualSlot 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)

Example 4 with IVirtualSlot

use of mekanism.common.inventory.container.slot.IVirtualSlot in project Mekanism by mekanism.

the class VirtualSlotContainerScreen method renderFloatingItem.

@Override
// Don't use directly, this is normally private in ContainerScreen
@Deprecated
protected final void renderFloatingItem(@Nonnull ItemStack stack, int x, int y, @Nullable String altText) {
    if (!stack.isEmpty()) {
        if (stack == this.snapbackItem && this.snapbackEnd instanceof IVirtualSlot) {
            // Use an instance equality check to see if we are rendering the returning stack (used in touch screens)
            // if we are and the slot we are returning to is a virtual one, so the position may be changing
            // then recalculate where the stack actually is/should be to send it to the correct position
            float f = (float) (Util.getMillis() - this.snapbackTime) / 100.0F;
            if (f >= 1.0F) {
                // I don't think this should ever happen given we validated it isn't the case before entering
                // drawItemStack, but just in case it is, update the returningStack and exit
                this.snapbackItem = ItemStack.EMPTY;
                return;
            }
            // Recalculate the x and y values to make sure they are the correct values
            IVirtualSlot returningVirtualSlot = (IVirtualSlot) this.snapbackEnd;
            int xOffset = returningVirtualSlot.getActualX() - this.snapbackStartX;
            int yOffset = returningVirtualSlot.getActualY() - this.snapbackStartY;
            x = this.snapbackStartX + (int) (xOffset * f);
            y = this.snapbackStartY + (int) (yOffset * f);
        }
        // noinspection ConstantConditions, altText can be null, just is marked as caught as nonnull by mojang's class level stuff
        super.renderFloatingItem(stack, x, y, altText);
    }
}
Also used : IVirtualSlot(mekanism.common.inventory.container.slot.IVirtualSlot)

Aggregations

IVirtualSlot (mekanism.common.inventory.container.slot.IVirtualSlot)4 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 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