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