diff --git a/src/main/java/org/cyclops/integratedterminals/api/terminalstorage/ITerminalStorageTabClient.java b/src/main/java/org/cyclops/integratedterminals/api/terminalstorage/ITerminalStorageTabClient.java index 6ee2e93e4..3ad01d8f7 100644 --- a/src/main/java/org/cyclops/integratedterminals/api/terminalstorage/ITerminalStorageTabClient.java +++ b/src/main/java/org/cyclops/integratedterminals/api/terminalstorage/ITerminalStorageTabClient.java @@ -129,10 +129,12 @@ public default ResourceLocation getTabSettingsName() { * @param hasClickedInStorage If the player has clicked inside the storage space. * This can be true even if the storage slot is -1. * @param hoveredContainerSlot The container slot id that is being hovered. -1 if none. + * @param isQuickMove If the click comes from a quickMoveStack action * @return If further click processing should stop. */ public boolean handleClick(AbstractContainerMenu container, int channel, int hoveringStorageSlot, int mouseButton, - boolean hasClickedOutside, boolean hasClickedInStorage, int hoveredContainerSlot); + boolean hasClickedOutside, boolean hasClickedInStorage, int hoveredContainerSlot, + boolean isQuickMove); /** * Called when a mouse scroll happens in a gui. @@ -159,6 +161,22 @@ public boolean handleScroll(AbstractContainerMenu container, int channel, int ho */ public int getActiveSlotQuantity(); + /** + * Dictates if a slot can have {@link #handleClick} called on it by + * {@link org.cyclops.integratedterminals.inventory.container.ContainerTerminalStorageBase#quickMoveStack} + * @param slotIndex The index of the slot in question + * @return If vanilla quick move actions should apply to the given slot + */ + default public boolean isQuickMovePrevented(int slotIndex) {return false;}; + + /** + * Dictates if a slot can have {@link #handleClick} called on it by + * {@link org.cyclops.integratedterminals.inventory.container.ContainerTerminalStorageBase#quickMoveStack} + * @param slot The slot in question + * @return If vanilla quick move actions should apply to the given slot + */ + default public boolean isQuickMovePrevented(Slot slot) {return isQuickMovePrevented(slot.index);} + /** * Set the active quantity. * @param quantity A quantity to set. diff --git a/src/main/java/org/cyclops/integratedterminals/client/gui/container/ContainerScreenTerminalStorage.java b/src/main/java/org/cyclops/integratedterminals/client/gui/container/ContainerScreenTerminalStorage.java index 941546283..bb8c97461 100644 --- a/src/main/java/org/cyclops/integratedterminals/client/gui/container/ContainerScreenTerminalStorage.java +++ b/src/main/java/org/cyclops/integratedterminals/client/gui/container/ContainerScreenTerminalStorage.java @@ -28,11 +28,7 @@ import org.cyclops.cyclopscore.client.gui.component.input.WidgetTextFieldExtended; import org.cyclops.cyclopscore.client.gui.container.ContainerScreenExtended; import org.cyclops.cyclopscore.client.gui.image.Images; -import org.cyclops.cyclopscore.helper.GuiHelpers; -import org.cyclops.cyclopscore.helper.Helpers; -import org.cyclops.cyclopscore.helper.L10NHelpers; -import org.cyclops.cyclopscore.helper.MinecraftHelpers; -import org.cyclops.cyclopscore.helper.RenderHelpers; +import org.cyclops.cyclopscore.helper.*; import org.cyclops.cyclopscore.inventory.container.ContainerExtended; import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetwork; import org.cyclops.integratedterminals.IntegratedTerminals; @@ -567,6 +563,9 @@ && mouseX > getGuiLeft() + TAB_OFFSET_X return true; } } + if(MinecraftHelpers.isShifted() && playerSlot != null && tab.isQuickMovePrevented(playerSlot)) { + return true; + } } else if (getSlotUnderMouse() != null) { // Don't allow shift clicking items into container when no tab has been selected return false; @@ -597,11 +596,7 @@ && mouseX > getGuiLeft() + TAB_OFFSET_X } }); - if (!MinecraftHelpers.isShifted()) { - return super.mouseClicked(mouseX, mouseY, mouseButton); - } - - return false; + return super.mouseClicked(mouseX, mouseY, mouseButton); } @Nullable @@ -700,7 +695,7 @@ public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) { boolean hasClickedOutside = this.hasClickedOutside(mouseX, mouseY, this.leftPos, this.topPos, mouseButton); boolean hasClickedInStorage = this.hasClickedInStorage(mouseX, mouseY); if (tabOptional.get().handleClick(getMenu(), getMenu().getSelectedChannel(), slot, mouseButton, - hasClickedOutside, hasClickedInStorage, playerSlot != null ? playerSlot.index : -1)) { + hasClickedOutside, hasClickedInStorage, playerSlot != null ? playerSlot.index : -1, false)) { return true; } } diff --git a/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentClient.java b/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentClient.java index 0e86499e1..c370524c4 100644 --- a/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentClient.java +++ b/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentClient.java @@ -546,7 +546,8 @@ public void resetActiveSlot() { @Override public boolean handleClick(AbstractContainerMenu container, int channel, int hoveringStorageSlot, int mouseButton, - boolean hasClickedOutside, boolean hasClickedInStorage, int hoveredContainerSlot) { + boolean hasClickedOutside, boolean hasClickedInStorage, int hoveredContainerSlot, + boolean isQuickMove) { this.activeChannel = channel; IIngredientMatcher matcher = ingredientComponent.getMatcher(); @@ -586,7 +587,7 @@ public boolean handleClick(AbstractContainerMenu container, int channel, int hov } } } - } else if (hoveredContainerSlot >= 0 && !container.getSlot(hoveredContainerSlot).getItem().isEmpty() && shift) { + } else if (hoveredContainerSlot >= 0 && !container.getSlot(hoveredContainerSlot).getItem().isEmpty() && isQuickMove) { // Quick move max quantity from player to storage clickType = mouseButton == 2 ? TerminalClickType.PLAYER_QUICK_MOVE_INCREMENTAL : TerminalClickType.PLAYER_QUICK_MOVE; } else if (hasClickedInStorage && !container.getCarried().isEmpty()) { @@ -855,7 +856,7 @@ public int dragIntoSlot(AbstractContainerMenu container, int channel, Slot slot, int activeSlotQuantityOld = this.activeSlotQuantity; this.activeSlotQuantity = quantity; - this.handleClick(container, channel, getActiveSlotId(), 0, false, false, slot.index); + this.handleClick(container, channel, getActiveSlotId(), 0, false, false, slot.index, false); this.activeSlotId = oldActiveSlotId; this.activeSlotQuantity = activeSlotQuantityOld; diff --git a/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingClient.java b/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingClient.java index 5d44ae9fb..65c5c054f 100644 --- a/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingClient.java +++ b/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingClient.java @@ -93,7 +93,8 @@ public int getPlayerInventoryOffsetY() { @Override public boolean handleClick(AbstractContainerMenu container, int channel, int hoveringStorageSlot, int mouseButton, - boolean hasClickedOutside, boolean hasClickedInStorage, int hoveredContainerSlot) { + boolean hasClickedOutside, boolean hasClickedInStorage, int hoveredContainerSlot, + boolean isQuickMove) { int craftingResultSlotIndex = TerminalStorageTabIngredientComponentItemStackCraftingCommon .getCraftingResultSlotIndex(container, getName()); boolean shift = MinecraftHelpers.isShifted(); @@ -108,7 +109,7 @@ public boolean handleClick(AbstractContainerMenu container, int channel, int hov return false; } return super.handleClick(container, channel, hoveringStorageSlot, mouseButton, hasClickedOutside, - hasClickedInStorage, hoveredContainerSlot); + hasClickedInStorage, hoveredContainerSlot, isQuickMove); } @Override @@ -127,4 +128,13 @@ public void onCommonSlotRender(AbstractContainerScreen gui, PoseStack matrixStac tabCommon = container.getTabCommon(name); tabClient.onCommonSlotRender(gui, matrixStack, layer, partialTick, x, y, mouseX, mouseY, slot, tabCommon); } + + @Override + public boolean isQuickMovePrevented(int slotIndex) { + // Prevent quick move on the crafting result slot to stop accidental mass crafting due to inventory mods + // spamming quick moves + int craftingResultSlotIndex = TerminalStorageTabIngredientComponentItemStackCraftingCommon + .getCraftingResultSlotIndex(container, getName()); + return slotIndex == craftingResultSlotIndex; + } } diff --git a/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStorageBase.java b/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStorageBase.java index 16721ff34..4f02593f0 100644 --- a/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStorageBase.java +++ b/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStorageBase.java @@ -280,6 +280,20 @@ public List> getTabS return slots; } + @Override + public ItemStack quickMoveStack(Player player, int slotID) { + // Handle any (modded) client-side quick move controls + if(player.getLevel().isClientSide) { + Optional> tabOptional = this.screen.getSelectedClientTab(); + if(tabOptional.isPresent() && !tabOptional.get().isQuickMovePrevented(slotID)) { + tabOptional.get().handleClick(this, this.getSelectedChannel(), -1, 0, + false, false, slotID, true); + } + } + // Always return empty stack because the tab's #handleClick already does the quick move + return ItemStack.EMPTY; + } + protected void enableSlots(String tabName) { // Do nothing, they will be placed on the correct location client-side upon init }