Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed quick move stack actions in the storage terminal #100

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, M> matcher = ingredientComponent.getMatcher();
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,20 @@ public List<Pair<Slot, ITerminalStorageTabCommon.ISlotPositionCallback>> getTabS
return slots;
}

@Override
public ItemStack quickMoveStack(Player player, int slotID) {
// Handle any (modded) client-side quick move controls
if(player.getLevel().isClientSide) {
Optional<ITerminalStorageTabClient<?>> 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
}
Expand Down