Skip to content

Commit eacd3fd

Browse files
committed
fix wireless pattern access terminal hotkey not closing the terminal when used inside the terminal (fix #351)
1 parent 4efce8f commit eacd3fd

4 files changed

Lines changed: 51 additions & 23 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
- Spain Spanish Translation and updates to the Mexican Spanish Translation (#353)
2+
- rework pickup so it will fill to a full stack
3+
- always use pickup to ME for items that are being restocked (even if it wouldn't be available / enabled)

src/main/java/de/mari_023/ae2wtlib/AE2wtlibEvents.java

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static void restock(ServerPlayer player, ItemStack item, int count, Consu
5353
if (cTHandler.getTargetGrid().getStorageService() == null)
5454
return;
5555

56-
int toAdd = Math.max(item.getMaxStackSize() / 2, 1) - count;
56+
int toAdd = item.getMaxStackSize() - count;
5757
if (toAdd == 0)
5858
return;
5959

@@ -91,24 +91,12 @@ public static void insertStackInME(ItemEntity entity, Player player) {
9191
return;
9292
if (player.level().isClientSide())
9393
return;
94-
if (player.isShiftKeyDown())
95-
return;
96-
CraftingTerminalHandler cTHandler = CraftingTerminalHandler.getCraftingTerminalHandler(player);
97-
ItemStack terminal = cTHandler.getCraftingTerminal();
98-
99-
if (!(MagnetHandler.getMagnetMode(terminal).pickupToME()))
100-
return;
101-
if (!cTHandler.inRange())
102-
return;
10394

104-
MagnetHost magnetHost = cTHandler.getMagnetHost();
105-
if (magnetHost == null)
95+
if (!canInsert(stack, player))
10696
return;
10797

108-
// if the filter is empty, it will match anything, even in whitelist mode
109-
if (magnetHost.getInsertFilter().isEmpty() && magnetHost.getInsertMode() == IncludeExclude.WHITELIST)
110-
return;
111-
if (!magnetHost.getInsertFilter().matchesFilter(AEItemKey.of(stack), magnetHost.getInsertMode()))
98+
CraftingTerminalHandler cTHandler = CraftingTerminalHandler.getCraftingTerminalHandler(player);
99+
if (!cTHandler.inRange())
112100
return;
113101

114102
if (cTHandler.getTargetGrid() == null)
@@ -126,6 +114,47 @@ public static void insertStackInME(ItemEntity entity, Player player) {
126114
stack.setCount(leftover);
127115
}
128116

117+
private static boolean canInsert(ItemStack stack, Player player) {
118+
CraftingTerminalHandler cTHandler = CraftingTerminalHandler.getCraftingTerminalHandler(player);
119+
ItemStack terminal = cTHandler.getCraftingTerminal();
120+
121+
cTHandler.checkTerminal();
122+
if (cTHandler.isRestockEnabled() && isRestocking(stack, player))
123+
return true;
124+
125+
if (player.isShiftKeyDown())
126+
return false;
127+
128+
if (!(MagnetHandler.getMagnetMode(terminal).pickupToME()))
129+
return false;
130+
131+
MagnetHost magnetHost = cTHandler.getMagnetHost();
132+
if (magnetHost == null)
133+
return false;
134+
135+
// if the filter is empty, it will match anything, even in whitelist mode
136+
if (magnetHost.getInsertFilter().isEmpty() && magnetHost.getInsertMode() == IncludeExclude.WHITELIST)
137+
return false;
138+
if (!magnetHost.getInsertFilter().matchesFilter(AEItemKey.of(stack), magnetHost.getInsertMode()))
139+
return false;
140+
141+
return true;
142+
}
143+
144+
private static boolean isRestocking(ItemStack stack, Player player) {
145+
if (stack.is(AE2wtlibTags.NO_RESTOCK)) {
146+
return false;
147+
}
148+
if (stack.getMaxStackSize() == 1) {
149+
return false;
150+
}
151+
for (int i = 0; i < 9; i++) {
152+
if (ItemStack.isSameItemSameComponents(stack, player.getInventory().getItem(i)))
153+
return true;
154+
}
155+
return false;
156+
}
157+
129158
public static void pickBlock(ItemStack stack) {
130159
PacketDistributor.sendToServer(new PickBlockPacket(stack));
131160
}
@@ -152,9 +181,6 @@ public static void pickBlock(ServerPlayer player, ItemStack stack) {
152181
if (insert < toReplace.getCount())
153182
return;
154183
int targetAmount = stack.getMaxStackSize();
155-
if (!stack.is(AE2wtlibTags.NO_RESTOCK) && targetAmount != 1) {
156-
targetAmount /= 2;
157-
}
158184
var extracted = networkInventory.extract(AEItemKey.of(stack), targetAmount, Actionable.SIMULATE, playerSource);
159185
if (extracted == 0)
160186
return;

src/main/java/de/mari_023/ae2wtlib/mixin/GuiMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void restockOverlay(GuiGraphics guiGraphics, int x, int y, DeltaTracker d
3131
return;
3232
CraftingTerminalHandler handler = CraftingTerminalHandler
3333
.getCraftingTerminalHandler(Minecraft.getInstance().player);
34-
if (!handler.isRestockEnabled() || stack.getCount() == 1 || !handler.isRestockAble(stack))
34+
if (!handler.isRestockEnabled() || stack.getMaxStackSize() == 1 || !handler.isRestockAble(stack))
3535
return;
3636
String number = ReadableNumberConverter.format(handler.getAccessibleAmount(stack), 3);
3737
if (number.startsWith(","))

src/main/resources/assets/ae2wtlib/ae2guide/ae2wtlib/restock.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ If Restock is enabled, your <ItemLink id="ae2:wireless_crafting_terminal" /> wil
1313

1414
You can enable it in the GUI, or using a Keybind.
1515

16-
When enabled, it will try to keep the Stack you are using at half the stack size, so 32 for most items.
16+
When enabled, it will try to keep the Stack you are using at the max stack size, so 64 for most items.
1717
It will take any missing items from your ME System,
18-
or put excess items into your ME System.
19-
This means that if you place a few items, then break them again, the item likely won't overflow into a different slot,
18+
or put excess items into your ME System if you pick up more.
19+
This means that if you place a few items, then break them again, the item won't overflow into a different slot,
2020
even if you don't hava an active <ItemLink id="ae2wtlib:magnet_card" />.
2121

2222
It will **NOT** restock stacks holding a single item before being used.

0 commit comments

Comments
 (0)