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);
}
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;
}
Aggregations