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
Next Next commit
changes according to reviews
  • Loading branch information
rlnt committed May 30, 2024
commit f76894d9a0600725497ff81ddcf89093650c16b1
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,15 @@ protected void handleGridInventoryEntryMouseClick(@Nullable GridInventoryEntry e
if (!menu.getCarried().isEmpty()) {
if (mouseButton == 0 && entry != null && ContainerItemStrategies.isKeySupported(entry.getWhat())) {
menu.handleInteraction(entry.getSerial(),
clickType == ClickType.QUICK_MOVE ? InventoryAction.FILL_ALL_ITEM : InventoryAction.FILL_ITEM);
clickType == ClickType.QUICK_MOVE ? InventoryAction.FILL_ENTIRE_ITEM
: InventoryAction.FILL_ITEM);
return;
}

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_ALL_ITEM
menu.handleInteraction(-1, clickType == ClickType.QUICK_MOVE ? InventoryAction.EMPTY_ENTIRE_ITEM
: InventoryAction.EMPTY_ITEM);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/appeng/helpers/InventoryAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public enum InventoryAction {
CRAFT_STACK, CRAFT_ITEM, CRAFT_SHIFT,

// fluid term
FILL_ITEM, FILL_ALL_ITEM, EMPTY_ITEM, EMPTY_ALL_ITEM,
FILL_ITEM, FILL_ENTIRE_ITEM, EMPTY_ITEM, EMPTY_ENTIRE_ITEM,

// extra...
MOVE_REGION, PICKUP_SINGLE, ROLL_UP, ROLL_DOWN, AUTO_CRAFT, PLACE_SINGLE,
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/appeng/menu/AEBaseMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@

public abstract class AEBaseMenu extends AbstractContainerMenu {
private static final int MAX_STRING_LENGTH = 32767;
private static final int MAX_CONTAINER_TRANSFER_ITERATIONS = 256;
private static final String HIDE_SLOT = "HideSlot";

private final IActionSource mySrc;
Expand Down Expand Up @@ -559,14 +560,14 @@ public void doAction(ServerPlayer player, InventoryAction action, int slot, long
var realInv = configInv.getDelegate();
var realInvSlot = appEngSlot.slot;

if (action == InventoryAction.FILL_ITEM || action == InventoryAction.FILL_ALL_ITEM) {
if (action == InventoryAction.FILL_ITEM || action == InventoryAction.FILL_ENTIRE_ITEM) {
var what = realInv.getKey(realInvSlot);
handleFillingHeldItem(
(amount, mode) -> realInv.extract(realInvSlot, what, amount, mode),
what, action == InventoryAction.FILL_ALL_ITEM);
} else if (action == InventoryAction.EMPTY_ITEM || action == InventoryAction.EMPTY_ALL_ITEM) {
what, action == InventoryAction.FILL_ENTIRE_ITEM);
} else if (action == InventoryAction.EMPTY_ITEM || action == InventoryAction.EMPTY_ENTIRE_ITEM) {
handleEmptyHeldItem((what, amount, mode) -> realInv.insert(realInvSlot, what, amount, mode),
action == InventoryAction.EMPTY_ALL_ITEM);
action == InventoryAction.EMPTY_ENTIRE_ITEM);
}
}

Expand Down Expand Up @@ -595,11 +596,11 @@ protected final void handleFillingHeldItem(FillingSource source, AEKey what, boo
return;
}

int maxIterations = 10_000;
long amount = fillAll ? Long.MAX_VALUE : what.getAmountPerUnit();
boolean filled = false;
int maxIterations = fillAll ? MAX_CONTAINER_TRANSFER_ITERATIONS : 1;

do {
while (maxIterations > 0) {
// Check if we can pull out of the system
var canPull = source.extract(amount, Actionable.SIMULATE);
if (canPull <= 0) {
Expand Down Expand Up @@ -628,7 +629,7 @@ protected final void handleFillingHeldItem(FillingSource source, AEKey what, boo

filled = true;
maxIterations--;
} while (fillAll && maxIterations > 0);
}

if (filled) {
ctx.playFillSound(getPlayer(), what);
Expand All @@ -653,10 +654,10 @@ protected final void handleEmptyHeldItem(EmptyingSink sink, boolean emptyAll) {

var what = content.what();
long amount = emptyAll ? Long.MAX_VALUE : what.getAmountPerUnit();
int maxIterations = 10_000;
int maxIterations = emptyAll ? MAX_CONTAINER_TRANSFER_ITERATIONS : 1;
boolean emptied = false;

do {
while (maxIterations > 0) {
// Check if we can pull out of the container
var canExtract = ctx.extract(what, amount, Actionable.SIMULATE);
if (canExtract <= 0) {
Expand Down Expand Up @@ -686,7 +687,7 @@ protected final void handleEmptyHeldItem(EmptyingSink sink, boolean emptyAll) {

emptied = true;
maxIterations--;
} while (emptyAll && maxIterations > 0);
}

if (emptied) {
ctx.playEmptySound(getPlayer(), what);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/appeng/menu/me/common/MEStorageMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,14 @@ protected void handleNetworkInteraction(ServerPlayer player, @Nullable AEKey cli

if (action == InventoryAction.FILL_ITEM) {
tryFillContainerItem(clickedKey, false, false);
} else if (action == InventoryAction.FILL_ALL_ITEM) {
} 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_ALL_ITEM) {
} 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) {
Expand Down
Loading