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

Add Fill all and Empty All Container Actions #7891

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Move decision on which action to take fully to client-side.
  • Loading branch information
shartte committed May 31, 2024
commit 432894b0c1a335d8b8dfca559edccb60acc1af6f
37 changes: 23 additions & 14 deletions src/main/java/appeng/client/gui/me/common/MEStorageScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,31 @@ protected void handleGridInventoryEntryMouseClick(@Nullable GridInventoryEntry e
AELog.debug("Clicked on grid inventory entry serial=%s, key=%s", entry.getSerial(), entry.getWhat());
}

// Check for emptying and filling actions and send them to the server
if (!menu.getCarried().isEmpty()) {
if (mouseButton == 0 && entry != null && ContainerItemStrategies.isKeySupported(entry.getWhat())) {
menu.handleInteraction(entry.getSerial(),
clickType == ClickType.QUICK_MOVE ? InventoryAction.FILL_ENTIRE_ITEM
: InventoryAction.FILL_ITEM);
return;
// Left-Clicking on an entry that is supported by a container strategy will either fill the currently
// held container, or it will consume a container from the grid to be filled.
// Holding shift tries to fill the entire container, while only transferring a single unit otherwise.
if (mouseButton == 0 && entry != null && ContainerItemStrategies.isKeySupported(entry.getWhat())) {
InventoryAction action;
if (clickType != ClickType.QUICK_MOVE) {
action = InventoryAction.FILL_ITEM; // Simple click fills item in hand or puts filled item in hand
} else {
// Shift-click on fluid with an empty hand -> move filled container to player
action = menu.getCarried().isEmpty() ? InventoryAction.FILL_ENTIRE_ITEM_MOVE_TO_PLAYER
: InventoryAction.FILL_ENTIRE_ITEM;
}

if (mouseButton == 1) {
var emptyingAction = ContainerItemStrategies.getEmptyingAction(menu.getCarried());
if (emptyingAction != null && menu.isKeyVisible(emptyingAction.what())) {
menu.handleInteraction(-1, clickType == ClickType.QUICK_MOVE ? InventoryAction.EMPTY_ENTIRE_ITEM
: InventoryAction.EMPTY_ITEM);
return;
}
menu.handleInteraction(entry.getSerial(), action);
return;
}

// Right-clicking with an item in hand tries to empty the container into the network
// Holding shift tries to empty the entire container, while only transferring a single unit otherwise.
if (mouseButton == 1 && !menu.getCarried().isEmpty()) {
var emptyingAction = ContainerItemStrategies.getEmptyingAction(menu.getCarried());
if (emptyingAction != null && menu.isKeyVisible(emptyingAction.what())) {
menu.handleInteraction(-1, clickType == ClickType.QUICK_MOVE ? InventoryAction.EMPTY_ENTIRE_ITEM
: InventoryAction.EMPTY_ITEM);
return;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/appeng/helpers/InventoryAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public enum InventoryAction {
CRAFT_STACK, CRAFT_ITEM, CRAFT_SHIFT,

// fluid term
FILL_ITEM, FILL_ENTIRE_ITEM, EMPTY_ITEM, EMPTY_ENTIRE_ITEM,
FILL_ITEM, FILL_ITEM_MOVE_TO_PLAYER, FILL_ENTIRE_ITEM, FILL_ENTIRE_ITEM_MOVE_TO_PLAYER, EMPTY_ITEM,
EMPTY_ENTIRE_ITEM,

// extra...
MOVE_REGION, PICKUP_SINGLE, ROLL_UP, ROLL_DOWN, AUTO_CRAFT, PLACE_SINGLE,
Expand Down
77 changes: 32 additions & 45 deletions src/main/java/appeng/menu/me/common/MEStorageMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.shorts.ShortSet;

import appeng.api.behaviors.ContainerItemStrategies;
import appeng.api.config.Actionable;
import appeng.api.config.Setting;
import appeng.api.config.Settings;
Expand Down Expand Up @@ -409,36 +408,33 @@ protected void handleNetworkInteraction(ServerPlayer player, @Nullable AEKey cli
return;
}

if (action == InventoryAction.PICKUP_OR_SET_DOWN && ContainerItemStrategies.isKeySupported(clickedKey)) {
action = InventoryAction.FILL_ITEM;
}

if (action == InventoryAction.SPLIT_OR_PLACE_SINGLE) {
if (ContainerItemStrategies.getContainedStack(getCarried()) != null) {
action = InventoryAction.EMPTY_ITEM;
}
}

if (action == InventoryAction.FILL_ITEM) {
tryFillContainerItem(clickedKey, false, false);
} else if (action == InventoryAction.FILL_ENTIRE_ITEM) {
tryFillContainerItem(clickedKey, false, true);
} else if (action == InventoryAction.SHIFT_CLICK) {
tryFillContainerItem(clickedKey, true, false);
} else if (action == InventoryAction.EMPTY_ITEM) {
handleEmptyHeldItem((what, amount, mode) -> StorageHelper.poweredInsert(energySource, storage, what, amount,
getActionSource(), mode), false);
} else if (action == InventoryAction.EMPTY_ENTIRE_ITEM) {
handleEmptyHeldItem((what, amount, mode) -> StorageHelper.poweredInsert(energySource, storage, what, amount,
getActionSource(), mode), true);
} else if (action == InventoryAction.AUTO_CRAFT) {
// Handle auto-crafting requests
if (action == InventoryAction.AUTO_CRAFT) {
var locator = getLocator();
if (locator != null && clickedKey != null) {
CraftAmountMenu.open(player, locator, clickedKey, clickedKey.getAmountPerUnit());
}
return;
}

// Attempt fluid related actions first
switch (action) {
case FILL_ITEM -> tryFillContainerItem(clickedKey, false, false);
case FILL_ITEM_MOVE_TO_PLAYER -> tryFillContainerItem(clickedKey, true, false);
case FILL_ENTIRE_ITEM -> tryFillContainerItem(clickedKey, false, true);
case FILL_ENTIRE_ITEM_MOVE_TO_PLAYER -> tryFillContainerItem(clickedKey, true, true);
case EMPTY_ITEM ->
handleEmptyHeldItem(
(what, amount, mode) -> StorageHelper.poweredInsert(energySource, storage, what, amount,
getActionSource(), mode),
false);
case EMPTY_ENTIRE_ITEM ->
handleEmptyHeldItem(
(what, amount, mode) -> StorageHelper.poweredInsert(energySource, storage, what, amount,
getActionSource(), mode),
true);
}

// Handle interactions where the player wants to put something into the network
if (clickedKey == null) {
if (action == InventoryAction.SPLIT_OR_PLACE_SINGLE || action == InventoryAction.ROLL_DOWN) {
Expand All @@ -449,16 +445,14 @@ protected void handleNetworkInteraction(ServerPlayer player, @Nullable AEKey cli
return;
}

// Any of the remaining actions are for items only
if (!(clickedKey instanceof AEItemKey clickedItem)) {
return;
}

switch (action) {
case SHIFT_CLICK:
moveOneStackToPlayer(clickedItem);
break;

case ROLL_DOWN: {
case SHIFT_CLICK -> moveOneStackToPlayer(clickedItem);
case ROLL_DOWN -> {
// Insert 1 of the carried stack into the network (or at least try to), regardless of what we're
// hovering in the network inventory.
var carried = getCarried();
Expand All @@ -470,9 +464,7 @@ protected void handleNetworkInteraction(ServerPlayer player, @Nullable AEKey cli
}
}
}
break;
case ROLL_UP:
case PICKUP_SINGLE: {
case ROLL_UP, PICKUP_SINGLE -> {
// Extract 1 of the hovered stack from the network (or at least try to), and add it to the carried item
var item = getCarried();

Expand All @@ -496,8 +488,7 @@ protected void handleNetworkInteraction(ServerPlayer player, @Nullable AEKey cli
}
}
}
break;
case PICKUP_OR_SET_DOWN: {
case PICKUP_OR_SET_DOWN -> {
if (!getCarried().isEmpty()) {
putCarriedItemIntoNetwork(false);
} else {
Expand All @@ -514,8 +505,7 @@ protected void handleNetworkInteraction(ServerPlayer player, @Nullable AEKey cli
}
}
}
break;
case SPLIT_OR_PLACE_SINGLE:
case SPLIT_OR_PLACE_SINGLE -> {
if (!getCarried().isEmpty()) {
putCarriedItemIntoNetwork(true);
} else {
Expand All @@ -538,26 +528,23 @@ protected void handleNetworkInteraction(ServerPlayer player, @Nullable AEKey cli
setCarried(ItemStack.EMPTY);
}
}

break;
case CREATIVE_DUPLICATE:
}
case CREATIVE_DUPLICATE -> {
if (player.getAbilities().instabuild) {
var is = clickedItem.toStack();
is.setCount(is.getMaxStackSize());
setCarried(is);
}
break;
case MOVE_REGION:
}
case MOVE_REGION -> {
final int playerInv = player.getInventory().items.size();
for (int slotNum = 0; slotNum < playerInv; slotNum++) {
if (!moveOneStackToPlayer(clickedItem)) {
break;
}
}
break;
default:
AELog.warn("Received unhandled inventory action %s from client in %s", action, getClass());
break;
}
default -> AELog.warn("Received unhandled inventory action %s from client in %s", action, getClass());
}
}

Expand Down
Loading