Skip to content

Commit 8f865ea

Browse files
committed
Add retain exact modes to fluid regulators and robot arms
1 parent 7141fcf commit 8f865ea

File tree

7 files changed

+33
-17
lines changed

7 files changed

+33
-17
lines changed

src/main/java/gregtech/api/mui/GTGuiTextures.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,11 @@ public static class IDs {
184184
18, 18 * 2, 18, 18, true);
185185

186186
public static final UITexture[] TRANSFER_MODE_OVERLAY = slice("textures/gui/overlay/transfer_mode_overlay.png",
187-
18, 18 * 3, 18, 18, true);
187+
18, 18 * 4, 18, 18, true);
188188

189189
public static final UITexture[] FLUID_TRANSFER_MODE_OVERLAY = slice(
190190
"textures/gui/overlay/fluid_transfer_mode_overlay.png",
191-
18, 18 * 3, 18, 18, true);
191+
18, 18 * 4, 18, 18, true);
192192

193193
public static final UITexture[] DISTRIBUTION_MODE_OVERLAY = slice(
194194
"textures/gui/widget/button_distribution_mode.png",

src/main/java/gregtech/common/covers/CoverFluidRegulator.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,14 @@ protected int doTransferFluidsInternal(IFluidHandler myFluidHandler, IFluidHandl
6565
return switch (transferMode) {
6666
case TRANSFER_ANY -> GTTransferUtils.transferFluids(sourceHandler, destHandler, transferLimit,
6767
fluidFilterContainer::test);
68-
case KEEP_EXACT -> doKeepExact(transferLimit, sourceHandler, destHandler,
69-
fluidFilterContainer::test,
70-
this.fluidFilterContainer.getTransferSize());
7168
case TRANSFER_EXACT -> doTransferExact(transferLimit, sourceHandler, destHandler,
7269
fluidFilterContainer::test, this.fluidFilterContainer.getTransferSize());
70+
case KEEP_EXACT -> doKeepExact(transferLimit, sourceHandler, destHandler,
71+
fluidFilterContainer::test,
72+
this.fluidFilterContainer.getTransferSize(), true);
73+
case RETAIN_EXACT -> doKeepExact(transferLimit, sourceHandler, destHandler,
74+
fluidFilterContainer::test,
75+
this.fluidFilterContainer.getTransferSize(), false);
7376
};
7477
}
7578

@@ -107,7 +110,7 @@ protected int doKeepExact(final int transferLimit,
107110
final IFluidHandler sourceHandler,
108111
final IFluidHandler destHandler,
109112
final Predicate<FluidStack> fluidFilter,
110-
int keepAmount) {
113+
int keepAmount, boolean direction) {
111114
if (sourceHandler == null || destHandler == null || fluidFilter == null)
112115
return 0;
113116

@@ -127,11 +130,12 @@ protected int doKeepExact(final int transferLimit,
127130

128131
// if fluid needs to be moved to meet the Keep Exact value
129132
int amountInDest;
130-
if ((amountInDest = destFluids.getOrDefault(fluidStack, 0)) < keepAmount) {
133+
if (direction ? (amountInDest = destFluids.getOrDefault(fluidStack, 0)) < keepAmount :
134+
(amountInDest = sourceFluids.getOrDefault(fluidStack, 0)) > keepAmount) {
131135

132136
// move the lesser of the remaining transfer limit and the difference in actual vs keep exact amount
133137
int amountToMove = Math.min(transferLimit - transferred,
134-
keepAmount - amountInDest);
138+
direction ? (keepAmount - amountInDest) : (amountInDest - keepAmount));
135139

136140
// Nothing to do here, try the next fluid.
137141
if (amountToMove <= 0)
@@ -281,7 +285,7 @@ public int getMaxTransferRate() {
281285
return switch (this.transferMode) {
282286
case TRANSFER_ANY -> 1;
283287
case TRANSFER_EXACT -> maxFluidTransferRate;
284-
case KEEP_EXACT -> Integer.MAX_VALUE;
288+
case KEEP_EXACT, RETAIN_EXACT -> Integer.MAX_VALUE;
285289
};
286290
}
287291

src/main/java/gregtech/common/covers/CoverRoboticArm.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ protected int doTransferItems(IItemHandler itemHandler, IItemHandler myItemHandl
6969
return switch (transferMode) {
7070
case TRANSFER_ANY -> doTransferItemsAny(itemHandler, myItemHandler, maxTransferAmount);
7171
case TRANSFER_EXACT -> doTransferExact(itemHandler, myItemHandler, maxTransferAmount);
72-
case KEEP_EXACT -> doKeepExact(itemHandler, myItemHandler, maxTransferAmount);
72+
case KEEP_EXACT -> doKeepExact(itemHandler, myItemHandler, maxTransferAmount, true);
73+
case RETAIN_EXACT -> doKeepExact(itemHandler, myItemHandler, maxTransferAmount, false);
7374
};
7475
}
7576

@@ -122,7 +123,8 @@ protected int doTransferExact(IItemHandler itemHandler, IItemHandler myItemHandl
122123
return Math.min(itemsTransferred, maxTransferAmount);
123124
}
124125

125-
protected int doKeepExact(IItemHandler itemHandler, IItemHandler myItemHandler, int maxTransferAmount) {
126+
protected int doKeepExact(IItemHandler itemHandler, IItemHandler myItemHandler, int maxTransferAmount,
127+
boolean direction) {
126128
Map<Integer, GroupItemInfo> currentItemAmount = doCountDestinationInventoryItemsByMatchIndex(itemHandler,
127129
myItemHandler);
128130
Map<Integer, GroupItemInfo> sourceItemAmounts = doCountDestinationInventoryItemsByMatchIndex(myItemHandler,
@@ -145,12 +147,20 @@ protected int doKeepExact(IItemHandler itemHandler, IItemHandler myItemHandler,
145147
}
146148

147149
int itemAmount = 0;
148-
if (currentItemAmount.containsKey(filterSlotIndex)) {
149-
GroupItemInfo destItemInfo = currentItemAmount.get(filterSlotIndex);
150-
itemAmount = destItemInfo.totalCount;
150+
if (direction) {
151+
if (currentItemAmount.containsKey(filterSlotIndex)) {
152+
GroupItemInfo destItemInfo = currentItemAmount.get(filterSlotIndex);
153+
itemAmount = destItemInfo.totalCount;
154+
}
155+
} else {
156+
if (sourceItemAmounts.containsKey(filterSlotIndex)) {
157+
GroupItemInfo sourceItemInfo = sourceItemAmounts.get(filterSlotIndex);
158+
itemAmount = sourceItemInfo.totalCount;
159+
}
151160
}
152-
if (itemAmount < itemToKeepAmount) {
153-
sourceInfo.totalCount = itemToKeepAmount - itemAmount;
161+
162+
if (direction ? (itemAmount < itemToKeepAmount) : (itemAmount > itemToKeepAmount)) {
163+
sourceInfo.totalCount = direction ? (itemToKeepAmount - itemAmount) : (itemAmount - itemToKeepAmount);
154164
} else {
155165
iterator.remove();
156166
}

src/main/java/gregtech/common/covers/TransferMode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ public enum TransferMode implements IStringSerializable {
88

99
TRANSFER_ANY("cover.robotic_arm.transfer_mode.transfer_any", 1),
1010
TRANSFER_EXACT("cover.robotic_arm.transfer_mode.transfer_exact", 1024),
11-
KEEP_EXACT("cover.robotic_arm.transfer_mode.keep_exact", Integer.MAX_VALUE);
11+
KEEP_EXACT("cover.robotic_arm.transfer_mode.keep_exact", Integer.MAX_VALUE),
12+
RETAIN_EXACT("cover.robotic_arm.transfer_mode.retain_exact", Integer.MAX_VALUE);
1213

1314
public static final TransferMode[] VALUES = values();
1415
public final String localeName;

src/main/resources/assets/gregtech/lang/en_us.lang

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,6 +1335,7 @@ cover.robotic_arm.exact=§7items
13351335
cover.robotic_arm.transfer_mode.transfer_any=Transfer Any
13361336
cover.robotic_arm.transfer_mode.transfer_exact=Supply Exact
13371337
cover.robotic_arm.transfer_mode.keep_exact=Keep Exact
1338+
cover.robotic_arm.transfer_mode.retain_exact=Retain Exact
13381339
cover.robotic_arm.transfer_mode.description=§eTransfer Any§r - in this mode, cover will transfer as many items matching its filter as possible./n§eSupply Exact§r - in this mode, cover will supply items in portions specified in item filter slots (or variable under this button for ore dictionary filter). If amount of items is less than portion size, items won't be moved. If there's a §bSmart Item Filter§r, the variable under this button will act as a multiplier instead./n§eKeep Exact§r - in this mode, cover will keep specified amount of items in the destination inventory, supplying additional amount of items if required./n§7Tip: left/right click on filter slots to change item amount, use shift clicking to change amount faster.
13391340

13401341
cover.pump.title=Pump Cover Settings (%s)
517 Bytes
Loading
525 Bytes
Loading

0 commit comments

Comments
 (0)