From 27d86f23e4490eff7e1be3041b98149cf434c7ba Mon Sep 17 00:00:00 2001 From: Simon Gerstmeier Date: Wed, 26 Apr 2023 18:59:45 +0200 Subject: [PATCH 1/5] Implemented ContainerTerminalStoragePart#quickMoveStack and made it handle quick move actions --- .../ContainerScreenTerminalStorage.java | 18 ++++++++---------- .../ContainerTerminalStoragePart.java | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 10 deletions(-) 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..9a8941e95 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 @@ -31,7 +31,6 @@ 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.inventory.container.ContainerExtended; import org.cyclops.integrateddynamics.api.network.IPositionedAddonsNetwork; @@ -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 @@ -696,12 +691,15 @@ public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) { int slot = getStorageSlotIndexAtPosition(mouseX, mouseY); Slot playerSlot = getSlotUnderMouse(); - // Handle clicks on storage slots + // Handle clicks on storage slots or container slots when storage has an active slot (item on cursor) 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)) { - return true; + boolean hasActiveSlot = tabOptional.get().getActiveSlotId() >= 0; + if(hasClickedInStorage || hasActiveSlot) { + if (tabOptional.get().handleClick(getMenu(), getMenu().getSelectedChannel(), slot, mouseButton, + hasClickedOutside, hasClickedInStorage, playerSlot != null ? playerSlot.index : -1)) { + return true; + } } } } diff --git a/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStoragePart.java b/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStoragePart.java index 1fdb81dd8..997105714 100644 --- a/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStoragePart.java +++ b/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStoragePart.java @@ -5,6 +5,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.inventory.MenuType; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.MinecraftForge; import org.cyclops.integrateddynamics.api.evaluate.EvaluationException; import org.cyclops.integrateddynamics.api.evaluate.variable.IVariable; @@ -18,6 +19,7 @@ import org.cyclops.integrateddynamics.core.inventory.container.ContainerMultipart; import org.cyclops.integrateddynamics.core.part.event.PartVariableDrivenVariableContentsUpdatedEvent; import org.cyclops.integratedterminals.RegistryEntries; +import org.cyclops.integratedterminals.api.terminalstorage.ITerminalStorageTabClient; import org.cyclops.integratedterminals.api.terminalstorage.location.ITerminalStorageLocation; import org.cyclops.integratedterminals.core.terminalstorage.location.TerminalStorageLocations; import org.cyclops.integratedterminals.part.PartTypeTerminalStorage; @@ -91,6 +93,21 @@ public boolean stillValid(Player playerIn) { return PartHelpers.canInteractWith(getPartTarget(), player, this.partContainer.get()); } + @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().handleClick(this, this.getSelectedChannel(), -1, 0, + false, false, slotID); + } + } + // Always return empty stack because the tab's #handleClick already does the quick move + return ItemStack.EMPTY; + } + + @Override public ITerminalStorageLocation getLocation() { return TerminalStorageLocations.PART; From 4ec6ad9bd801c4603b123676db7c7f53f0ecb019 Mon Sep 17 00:00:00 2001 From: Simon Gerstmeier Date: Thu, 27 Apr 2023 15:10:41 +0200 Subject: [PATCH 2/5] Excluded crafting result slot from quick move stack actions. Moved #quickMoveStack to terminal menu superclass. --- .../ContainerScreenTerminalStorage.java | 33 ++++++++++++++----- ...dientComponentItemStackCraftingCommon.java | 10 ++++-- .../ContainerTerminalStorageBase.java | 14 ++++++++ .../ContainerTerminalStoragePart.java | 17 ---------- 4 files changed, 45 insertions(+), 29 deletions(-) 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 9a8941e95..15f617399 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,10 +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.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; @@ -596,6 +593,11 @@ && mouseX > getGuiLeft() + TAB_OFFSET_X } }); + // Prevent quick move stack actions from applying to the crafting result slot + if(MinecraftHelpers.isShifted() && isSlotUnderMouseCraftingResult()) { + return true; + } + return super.mouseClicked(mouseX, mouseY, mouseButton); } @@ -610,6 +612,18 @@ public Slot getSlotUnderMouse() { return slot; } + public boolean isSlotUnderMouseCraftingResult() { + // If the player is hovering the crafting result slot of a terminal + boolean isCraftingResultSlot = false; + Optional> tabOptional = getSelectedClientTab(); + Slot playerSlot = getSlotUnderMouse(); + if(tabOptional.isPresent() && playerSlot != null) { + int craftingResultSlotIndex = TerminalStorageTabIngredientComponentItemStackCraftingCommon.getCraftingResultSlotIndex(getMenu(), tabOptional.get().getName()); + isCraftingResultSlot = craftingResultSlotIndex >= 0 && playerSlot.index == craftingResultSlotIndex; + } + return isCraftingResultSlot; + } + @Override public boolean mouseDragged(double mouseX, double mouseY, int mouseButton, double mouseXPrev, double mouseYPrev) { if (getSelectedClientTab().map(tab -> { @@ -688,16 +702,17 @@ public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) { this.clicked = false; Optional> tabOptional = getSelectedClientTab(); if (tabOptional.isPresent()) { + ITerminalStorageTabClient tab = tabOptional.get(); int slot = getStorageSlotIndexAtPosition(mouseX, mouseY); Slot playerSlot = getSlotUnderMouse(); - // Handle clicks on storage slots or container slots when storage has an active slot (item on cursor) + // Handle clicks on storage slots or container slots when storage has an active slot (item on cursor) or the crafting result slot boolean hasClickedOutside = this.hasClickedOutside(mouseX, mouseY, this.leftPos, this.topPos, mouseButton); boolean hasClickedInStorage = this.hasClickedInStorage(mouseX, mouseY); - boolean hasActiveSlot = tabOptional.get().getActiveSlotId() >= 0; - if(hasClickedInStorage || hasActiveSlot) { - if (tabOptional.get().handleClick(getMenu(), getMenu().getSelectedChannel(), slot, mouseButton, - hasClickedOutside, hasClickedInStorage, playerSlot != null ? playerSlot.index : -1)) { + boolean hasActiveSlot = tab.getActiveSlotId() >= 0; + if(hasClickedInStorage || hasActiveSlot || isSlotUnderMouseCraftingResult()) { + if (tab.handleClick(getMenu(), getMenu().getSelectedChannel(), slot, mouseButton, + hasClickedOutside, hasClickedInStorage, playerSlot == null ? -1 : playerSlot.index)) { return true; } } diff --git a/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingCommon.java b/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingCommon.java index 0b69ac7b1..2ea9751c6 100644 --- a/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingCommon.java +++ b/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingCommon.java @@ -51,9 +51,13 @@ public TerminalStorageTabIngredientComponentItemStackCraftingCommon(ContainerTer public static int getCraftingResultSlotIndex(AbstractContainerMenu container, ResourceLocation name) { ITerminalStorageTabCommon tabCommon = ((ContainerTerminalStorageBase) container).getTabCommon(name.toString()); - TerminalStorageTabIngredientComponentItemStackCraftingCommon tabCommonCrafting = - (TerminalStorageTabIngredientComponentItemStackCraftingCommon) tabCommon; - return tabCommonCrafting.getSlotCrafting().index; + if(tabCommon instanceof TerminalStorageTabIngredientComponentItemStackCraftingCommon) { + TerminalStorageTabIngredientComponentItemStackCraftingCommon tabCommonCrafting = + (TerminalStorageTabIngredientComponentItemStackCraftingCommon) tabCommon; + return tabCommonCrafting.getSlotCrafting().index; + } else { + return -1; + } } @Override 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..f75a145fc 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().handleClick(this, this.getSelectedChannel(), -1, 0, + false, false, slotID); + } + } + // 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 } diff --git a/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStoragePart.java b/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStoragePart.java index 997105714..1fdb81dd8 100644 --- a/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStoragePart.java +++ b/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStoragePart.java @@ -5,7 +5,6 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.inventory.MenuType; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.world.item.ItemStack; import net.minecraftforge.common.MinecraftForge; import org.cyclops.integrateddynamics.api.evaluate.EvaluationException; import org.cyclops.integrateddynamics.api.evaluate.variable.IVariable; @@ -19,7 +18,6 @@ import org.cyclops.integrateddynamics.core.inventory.container.ContainerMultipart; import org.cyclops.integrateddynamics.core.part.event.PartVariableDrivenVariableContentsUpdatedEvent; import org.cyclops.integratedterminals.RegistryEntries; -import org.cyclops.integratedterminals.api.terminalstorage.ITerminalStorageTabClient; import org.cyclops.integratedterminals.api.terminalstorage.location.ITerminalStorageLocation; import org.cyclops.integratedterminals.core.terminalstorage.location.TerminalStorageLocations; import org.cyclops.integratedterminals.part.PartTypeTerminalStorage; @@ -93,21 +91,6 @@ public boolean stillValid(Player playerIn) { return PartHelpers.canInteractWith(getPartTarget(), player, this.partContainer.get()); } - @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().handleClick(this, this.getSelectedChannel(), -1, 0, - false, false, slotID); - } - } - // Always return empty stack because the tab's #handleClick already does the quick move - return ItemStack.EMPTY; - } - - @Override public ITerminalStorageLocation getLocation() { return TerminalStorageLocations.PART; From 2dc19fa3f07c9a447c77690c5c655add179d565e Mon Sep 17 00:00:00 2001 From: Simon Gerstmeier Date: Mon, 1 May 2023 17:13:58 +0200 Subject: [PATCH 3/5] Added isQuickMove parameter to ITerminalStorageTabClient#handleClick --- .../ITerminalStorageTabClient.java | 4 ++- .../ContainerScreenTerminalStorage.java | 29 +++---------------- ...alStorageTabIngredientComponentClient.java | 7 +++-- ...dientComponentItemStackCraftingClient.java | 9 +++--- ...dientComponentItemStackCraftingCommon.java | 10 ++----- .../ContainerTerminalStorageBase.java | 2 +- 6 files changed, 19 insertions(+), 42 deletions(-) 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..547aaaea0 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. 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 15f617399..cc5a83b6b 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 @@ -593,11 +593,6 @@ && mouseX > getGuiLeft() + TAB_OFFSET_X } }); - // Prevent quick move stack actions from applying to the crafting result slot - if(MinecraftHelpers.isShifted() && isSlotUnderMouseCraftingResult()) { - return true; - } - return super.mouseClicked(mouseX, mouseY, mouseButton); } @@ -612,18 +607,6 @@ public Slot getSlotUnderMouse() { return slot; } - public boolean isSlotUnderMouseCraftingResult() { - // If the player is hovering the crafting result slot of a terminal - boolean isCraftingResultSlot = false; - Optional> tabOptional = getSelectedClientTab(); - Slot playerSlot = getSlotUnderMouse(); - if(tabOptional.isPresent() && playerSlot != null) { - int craftingResultSlotIndex = TerminalStorageTabIngredientComponentItemStackCraftingCommon.getCraftingResultSlotIndex(getMenu(), tabOptional.get().getName()); - isCraftingResultSlot = craftingResultSlotIndex >= 0 && playerSlot.index == craftingResultSlotIndex; - } - return isCraftingResultSlot; - } - @Override public boolean mouseDragged(double mouseX, double mouseY, int mouseButton, double mouseXPrev, double mouseYPrev) { if (getSelectedClientTab().map(tab -> { @@ -702,19 +685,15 @@ public boolean mouseReleased(double mouseX, double mouseY, int mouseButton) { this.clicked = false; Optional> tabOptional = getSelectedClientTab(); if (tabOptional.isPresent()) { - ITerminalStorageTabClient tab = tabOptional.get(); int slot = getStorageSlotIndexAtPosition(mouseX, mouseY); Slot playerSlot = getSlotUnderMouse(); - // Handle clicks on storage slots or container slots when storage has an active slot (item on cursor) or the crafting result slot + // Handle clicks on storage slots boolean hasClickedOutside = this.hasClickedOutside(mouseX, mouseY, this.leftPos, this.topPos, mouseButton); boolean hasClickedInStorage = this.hasClickedInStorage(mouseX, mouseY); - boolean hasActiveSlot = tab.getActiveSlotId() >= 0; - if(hasClickedInStorage || hasActiveSlot || isSlotUnderMouseCraftingResult()) { - if (tab.handleClick(getMenu(), getMenu().getSelectedChannel(), slot, mouseButton, - hasClickedOutside, hasClickedInStorage, playerSlot == null ? -1 : playerSlot.index)) { - return true; - } + if (tabOptional.get().handleClick(getMenu(), getMenu().getSelectedChannel(), slot, mouseButton, + 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..d2bb8e0e0 100644 --- a/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingClient.java +++ b/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingClient.java @@ -10,7 +10,6 @@ import net.minecraft.world.level.block.Blocks; import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; import org.cyclops.cyclopscore.helper.GuiHelpers; -import org.cyclops.cyclopscore.helper.MinecraftHelpers; import org.cyclops.integratedterminals.GeneralConfig; import org.cyclops.integratedterminals.IntegratedTerminals; import org.cyclops.integratedterminals.api.terminalstorage.ITerminalButton; @@ -93,11 +92,11 @@ 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(); - if (hoveredContainerSlot == craftingResultSlotIndex && shift) { + if (hoveredContainerSlot == craftingResultSlotIndex && isQuickMove) { IntegratedTerminals._instance.getPacketHandler().sendToServer( new TerminalStorageIngredientItemStackCraftingGridShiftClickOutput(getName().toString(), channel, GeneralConfig.shiftClickCraftingResultLimit)); @@ -108,7 +107,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 diff --git a/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingCommon.java b/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingCommon.java index 2ea9751c6..0b69ac7b1 100644 --- a/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingCommon.java +++ b/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingCommon.java @@ -51,13 +51,9 @@ public TerminalStorageTabIngredientComponentItemStackCraftingCommon(ContainerTer public static int getCraftingResultSlotIndex(AbstractContainerMenu container, ResourceLocation name) { ITerminalStorageTabCommon tabCommon = ((ContainerTerminalStorageBase) container).getTabCommon(name.toString()); - if(tabCommon instanceof TerminalStorageTabIngredientComponentItemStackCraftingCommon) { - TerminalStorageTabIngredientComponentItemStackCraftingCommon tabCommonCrafting = - (TerminalStorageTabIngredientComponentItemStackCraftingCommon) tabCommon; - return tabCommonCrafting.getSlotCrafting().index; - } else { - return -1; - } + TerminalStorageTabIngredientComponentItemStackCraftingCommon tabCommonCrafting = + (TerminalStorageTabIngredientComponentItemStackCraftingCommon) tabCommon; + return tabCommonCrafting.getSlotCrafting().index; } @Override 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 f75a145fc..4c7306c20 100644 --- a/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStorageBase.java +++ b/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStorageBase.java @@ -287,7 +287,7 @@ public ItemStack quickMoveStack(Player player, int slotID) { Optional> tabOptional = this.screen.getSelectedClientTab(); if(tabOptional.isPresent()) { tabOptional.get().handleClick(this, this.getSelectedChannel(), -1, 0, - false, false, slotID); + false, false, slotID, true); } } // Always return empty stack because the tab's #handleClick already does the quick move From 0ede3c454022243e1c1f54c8ac2754cd284bb01c Mon Sep 17 00:00:00 2001 From: Simon Gerstmeier Date: Tue, 2 May 2023 21:53:42 +0200 Subject: [PATCH 4/5] Implemented ITerminalStorageTabClient#isQuickMovePrevented --- .../ITerminalStorageTabClient.java | 16 ++++++++++++++++ .../ContainerScreenTerminalStorage.java | 3 +++ ...gredientComponentItemStackCraftingClient.java | 13 ++++++++++++- .../container/ContainerTerminalStorageBase.java | 2 +- 4 files changed, 32 insertions(+), 2 deletions(-) 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 547aaaea0..3ad01d8f7 100644 --- a/src/main/java/org/cyclops/integratedterminals/api/terminalstorage/ITerminalStorageTabClient.java +++ b/src/main/java/org/cyclops/integratedterminals/api/terminalstorage/ITerminalStorageTabClient.java @@ -161,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 cc5a83b6b..54bbcd249 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 @@ -563,6 +563,9 @@ && mouseX > getGuiLeft() + TAB_OFFSET_X return true; } } + if(MinecraftHelpers.isShifted() && 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; 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 d2bb8e0e0..65c5c054f 100644 --- a/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingClient.java +++ b/src/main/java/org/cyclops/integratedterminals/core/terminalstorage/TerminalStorageTabIngredientComponentItemStackCraftingClient.java @@ -10,6 +10,7 @@ import net.minecraft.world.level.block.Blocks; import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent; import org.cyclops.cyclopscore.helper.GuiHelpers; +import org.cyclops.cyclopscore.helper.MinecraftHelpers; import org.cyclops.integratedterminals.GeneralConfig; import org.cyclops.integratedterminals.IntegratedTerminals; import org.cyclops.integratedterminals.api.terminalstorage.ITerminalButton; @@ -96,7 +97,8 @@ public boolean handleClick(AbstractContainerMenu container, int channel, int hov boolean isQuickMove) { int craftingResultSlotIndex = TerminalStorageTabIngredientComponentItemStackCraftingCommon .getCraftingResultSlotIndex(container, getName()); - if (hoveredContainerSlot == craftingResultSlotIndex && isQuickMove) { + boolean shift = MinecraftHelpers.isShifted(); + if (hoveredContainerSlot == craftingResultSlotIndex && shift) { IntegratedTerminals._instance.getPacketHandler().sendToServer( new TerminalStorageIngredientItemStackCraftingGridShiftClickOutput(getName().toString(), channel, GeneralConfig.shiftClickCraftingResultLimit)); @@ -126,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 4c7306c20..4f02593f0 100644 --- a/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStorageBase.java +++ b/src/main/java/org/cyclops/integratedterminals/inventory/container/ContainerTerminalStorageBase.java @@ -285,7 +285,7 @@ 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()) { + if(tabOptional.isPresent() && !tabOptional.get().isQuickMovePrevented(slotID)) { tabOptional.get().handleClick(this, this.getSelectedChannel(), -1, 0, false, false, slotID, true); } From 450552f7c791780e23554d0ebadb6d538c0db011 Mon Sep 17 00:00:00 2001 From: Simon Gerstmeier Date: Tue, 2 May 2023 22:10:57 +0200 Subject: [PATCH 5/5] Fixed uncaught NPE in relation to isQuickMovePrevented --- .../client/gui/container/ContainerScreenTerminalStorage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 54bbcd249..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 @@ -563,7 +563,7 @@ && mouseX > getGuiLeft() + TAB_OFFSET_X return true; } } - if(MinecraftHelpers.isShifted() && tab.isQuickMovePrevented(playerSlot)) { + if(MinecraftHelpers.isShifted() && playerSlot != null && tab.isQuickMovePrevented(playerSlot)) { return true; } } else if (getSlotUnderMouse() != null) {