Skip to content

Commit 0247e54

Browse files
committed
Change parameter order of "executeClicks()"
1 parent a3fd31b commit 0247e54

10 files changed

Lines changed: 80 additions & 78 deletions

src/main/java/net/evmodder/evmod/apis/ClickUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package net.evmodder.evmod.apis;
22

3+
import java.util.ArrayDeque;
34
import java.util.Arrays;
5+
import java.util.List;
46
import java.util.Queue;
57
import java.util.Timer;
68
import java.util.TimerTask;
@@ -140,7 +142,7 @@ private int calcRemainingTicks(int clicksToExecute){
140142
private boolean clickOpOngoing/*, waitedForClicks*/;
141143
private int estimatedMsLeft;
142144
public final boolean hasOngoingClicks(){return clickOpOngoing;}
143-
public final void executeClicks(Queue<InvAction> clicks, Function<InvAction, Boolean> canProceed, Runnable onComplete){
145+
public final void executeClicks(Function<InvAction, Boolean> canProceed, Runnable onComplete, Queue<InvAction> clicks){
144146
final MinecraftClient client = MinecraftClient.getInstance();
145147
if(clickOpOngoing){
146148
Main.LOGGER.warn("executeClicks() already has an ongoing operation");
@@ -227,6 +229,9 @@ public final void executeClicks(Queue<InvAction> clicks, Function<InvAction, Boo
227229
});
228230
}}, 0l, 23l);//51l = just over a tick, 23l=just under half a tick
229231
}
232+
public final void executeClicks(Function<InvAction, Boolean> canProceed, Runnable onComplete, InvAction... clicks){
233+
executeClicks(canProceed, onComplete, new ArrayDeque<>(List.of(clicks)));
234+
}
230235

231236
public static void executeClicksLEGACY(
232237
MinecraftClient client,

src/main/java/net/evmodder/evmod/keybinds/KeybindInventoryOrganize.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,8 @@ public void organizeInventory(final boolean RESTOCK_ONLY, Runnable onComplete){
401401
if(onComplete != null) onComplete.run();
402402
return;
403403
}
404-
Main.clickUtils.executeClicks(clicks,
405-
_0->true,
406-
// _0->{
404+
Main.clickUtils.executeClicks(_0->true,
405+
// _0->{
407406
// //client.player.sendMessage(Text.literal("click "+c.slotId()+" "+c.button()+" "+c.actionType()), false);
408407
// return true;
409408
// },
@@ -415,7 +414,8 @@ public void organizeInventory(final boolean RESTOCK_ONLY, Runnable onComplete){
415414
depth = 0;
416415
if(onComplete != null) onComplete.run();
417416
}
418-
});
417+
},
418+
clicks);
419419
}
420420

421421
public void refreshLayout(List<String> strings){

src/main/java/net/evmodder/evmod/keybinds/KeybindInventoryRestock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ else for(KeybindInventoryOrganize kio : organizationLayouts)
142142
if(clicks.isEmpty()) return;
143143

144144
Main.LOGGER.info("InvRestock: Scheduled with "+clicks.size()+" clicks");
145-
Main.clickUtils.executeClicks(clicks, _0->true, ()->Main.LOGGER.info("InvRestock: DONE!"));
145+
Main.clickUtils.executeClicks(_0->true, ()->Main.LOGGER.info("InvRestock: DONE!"), clicks);
146146
}
147147

148148
private void organizeThenRestock(int i){

src/main/java/net/evmodder/evmod/keybinds/KeybindMapCopy.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ private void copyMapArtInBundles(final ArrayDeque<InvAction> clicks, final ItemS
325325
if(numEmptyMapsInGrid > 0) clicks.add(new InvAction(f.INPUT_START+1, 0, ActionType.SHIFT_CLICK));
326326

327327
//Main.LOGGER.info("MapCopyBundle: STARTED");
328-
Main.clickUtils.executeClicks(clicks, _0->true, ()->Main.LOGGER.info("MapCopyBundle: DONE"));
328+
Main.clickUtils.executeClicks(_0->true, ()->Main.LOGGER.info("MapCopyBundle: DONE"), clicks);
329329
}
330330

331331
private boolean isMapArtBundle(ItemStack stack){
@@ -521,16 +521,16 @@ else if(moveExactToCrafter){
521521
if(numEmptyMapsInGrid > 0) clicks.add(new InvAction(f.INPUT_START+1, 0, ActionType.SHIFT_CLICK));
522522

523523
//Main.LOGGER.info("MapCopy: STARTED");
524-
Main.clickUtils.executeClicks(clicks,
525-
c->{
526-
// Don't start individual copy operation unless we can fully knock it out (unless impossible to do in 1 go)
527-
final Integer clicksNeeded = reserveClicks.get(c);
528-
if(clicksNeeded == null || clicksNeeded <= Main.clickUtils.calcAvailableClicks()) return true;
529-
return false; // Wait for clicks
530-
},
524+
Main.clickUtils.executeClicks(c->{
525+
// Don't start individual copy operation unless we can fully knock it out (unless impossible to do in 1 go)
526+
final Integer clicksNeeded = reserveClicks.get(c);
527+
if(clicksNeeded == null || clicksNeeded <= Main.clickUtils.calcAvailableClicks()) return true;
528+
return false; // Wait for clicks
529+
},
531530
()->{
532531
Main.LOGGER.info("MapCopy: DONE");
533-
}
532+
},
533+
clicks
534534
);
535535
}
536536

src/main/java/net/evmodder/evmod/keybinds/KeybindMapLoad.java

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -110,37 +110,37 @@ private final void loadMapArtFromBundles(){
110110
}
111111
// client.player.sendMessage(Text.literal("Scheduling clicks: "+clicks.size()), true);
112112
Main.LOGGER.info("MapLoadBundle: STARTED");
113-
Main.clickUtils.executeClicks(clicks,
114-
c->{
115-
if(client.player == null || client.world == null) return true;
116-
Integer skipIfLoaded = ableToSkipClicks.get(c);
113+
Main.clickUtils.executeClicks(c->{
114+
if(client.player == null || client.world == null) return true;
115+
Integer skipIfLoaded = ableToSkipClicks.get(c);
117116
// Main.LOGGER.info("click for slot: "+c.slotId()+", clicksLeft: "+clicks.size());
118-
if(skipIfLoaded != null){
119-
//Main.LOGGER.info("MapLoadBundle: potentially skippable");
120-
BundleContentsComponent contents = client.player.currentScreenHandler.slots.get(c.slot()).getStack().get(DataComponentTypes.BUNDLE_CONTENTS);
121-
if(contents != null && contents.stream().allMatch(s -> isLoadedMapArt(client.world, s))){
117+
if(skipIfLoaded != null){
118+
//Main.LOGGER.info("MapLoadBundle: potentially skippable");
119+
BundleContentsComponent contents = client.player.currentScreenHandler.slots.get(c.slot()).getStack().get(DataComponentTypes.BUNDLE_CONTENTS);
120+
if(contents != null && contents.stream().allMatch(s -> isLoadedMapArt(client.world, s))){
122121
// Main.LOGGER.info("MapLoadBundle: skippable! whoop whoop: "+(skipIfLoaded));
123-
for(int i=0; i<skipIfLoaded; ++i) clicks.remove();
124-
return false;
125-
}
122+
for(int i=0; i<skipIfLoaded; ++i) clicks.remove();
123+
return false;
126124
}
127-
if(c.slot() != emptySlot) return true;
128-
if(stateUpdateWaitStart == 0){stateUpdateWaitStart = -1; return true;}
129-
ItemStack item = client.player.currentScreenHandler.slots.get(emptySlot).getStack();
125+
}
126+
if(c.slot() != emptySlot) return true;
127+
if(stateUpdateWaitStart == 0){stateUpdateWaitStart = -1; return true;}
128+
ItemStack item = client.player.currentScreenHandler.slots.get(emptySlot).getStack();
130129
// if(!isLoadedMapArt(client.world, item)) return false;
131-
if(!isLoadedMapArt(client.world, item)){
132-
if(stateLoadWaitStart == 0) stateLoadWaitStart = System.currentTimeMillis();
133-
if(System.currentTimeMillis() - stateLoadWaitStart < STATE_LOAD_TIMEOUT) return false;
134-
stateUpdateWaitStart = stateLoadWaitStart = 0;
135-
Main.LOGGER.warn("MapLoadBundle: Timed out while waiting for map state to load!");
136-
return true;
137-
}
138-
// Wait a bit even aft map state is loaded, to ensure it REALLY gets loaded
139-
else if(stateUpdateWaitStart <= 0){stateUpdateWaitStart = System.currentTimeMillis(); return false;}
140-
else if(System.currentTimeMillis() - stateUpdateWaitStart < WAIT_FOR_STATE_UPDATE) return false;
141-
else{stateUpdateWaitStart = 0; return true;}
142-
},
143-
()->Main.LOGGER.info("MapLoadBundle: DONE!")
130+
if(!isLoadedMapArt(client.world, item)){
131+
if(stateLoadWaitStart == 0) stateLoadWaitStart = System.currentTimeMillis();
132+
if(System.currentTimeMillis() - stateLoadWaitStart < STATE_LOAD_TIMEOUT) return false;
133+
stateUpdateWaitStart = stateLoadWaitStart = 0;
134+
Main.LOGGER.warn("MapLoadBundle: Timed out while waiting for map state to load!");
135+
return true;
136+
}
137+
// Wait a bit even aft map state is loaded, to ensure it REALLY gets loaded
138+
else if(stateUpdateWaitStart <= 0){stateUpdateWaitStart = System.currentTimeMillis(); return false;}
139+
else if(System.currentTimeMillis() - stateUpdateWaitStart < WAIT_FOR_STATE_UPDATE) return false;
140+
else{stateUpdateWaitStart = 0; return true;}
141+
},
142+
()->Main.LOGGER.info("MapLoadBundle: DONE!"),
143+
clicks
144144
);
145145
}
146146

@@ -187,37 +187,37 @@ public final void loadMapArtFromContainer(){
187187
for(int j=0; j<hbi; ++j) clicks.add(new InvAction(putBackSlots[j], hbButtons[j], ActionType.HOTBAR_SWAP));
188188

189189
Main.LOGGER.info("MapLoad: STARTED, clicks: "+clicks.size()+", extraPutBackIndex: "+extraPutBackIndex);
190-
Main.clickUtils.executeClicks(clicks,
191-
c->{
192-
if(client.player == null || client.world == null) return true;
190+
Main.clickUtils.executeClicks(c->{
191+
if(client.player == null || client.world == null) return true;
193192
// if(isUnloadedMapArt(/*client.player.clientWorld*/client.world, item)) return false;
194-
if(clickIndex % hbButtons.length != 0 && clickIndex != extraPutBackIndex){++clickIndex; return true;}
195-
if(Main.clickUtils.calcAvailableClicks() < MAX_BATCH_SIZE) return false; // Wait for clicks
193+
if(clickIndex % hbButtons.length != 0 && clickIndex != extraPutBackIndex){++clickIndex; return true;}
194+
if(Main.clickUtils.calcAvailableClicks() < MAX_BATCH_SIZE) return false; // Wait for clicks
196195

197-
if((clickIndex/hbButtons.length)%2 == 0 && clickIndex < extraPutBackIndex){++clickIndex; return true;} // Moving TO hotbar
196+
if((clickIndex/hbButtons.length)%2 == 0 && clickIndex < extraPutBackIndex){++clickIndex; return true;} // Moving TO hotbar
198197
// ItemStack item = client.player.getInventory().getStack(c.button());
199-
//if(!isLoadedMapArt(client.world, item)){ // Weird issue rn with non-maps getting moved around? (bundles?)
200-
//if(isUnloadedMapArt(client.world, s){
201-
// Ugh just wait if any unloaded map in hotbar(or inv)
202-
if(client.player.getInventory().main.stream().anyMatch(s -> isUnloadedMapArt(client.world, s))){
198+
//if(!isLoadedMapArt(client.world, item)){ // Weird issue rn with non-maps getting moved around? (bundles?)
199+
//if(isUnloadedMapArt(client.world, s){
200+
// Ugh just wait if any unloaded map in hotbar(or inv)
201+
if(client.player.getInventory().main.stream().anyMatch(s -> isUnloadedMapArt(client.world, s))){
203202
// Main.LOGGER.info("MapLoad: still waiting for map state to load from hotbar slot: "+c.button());
204-
if(stateLoadWaitStart == 0) stateLoadWaitStart = System.currentTimeMillis();
205-
if(System.currentTimeMillis() - stateLoadWaitStart < STATE_LOAD_TIMEOUT) return false;
206-
stateUpdateWaitStart = stateLoadWaitStart = 0;
207-
Main.LOGGER.warn("MapLoad: Timed out while waiting for map state to load!");
208-
return true;
209-
}
210-
else if(stateUpdateWaitStart == 0){stateUpdateWaitStart = System.currentTimeMillis(); return false;}
211-
else if(System.currentTimeMillis() - stateUpdateWaitStart < WAIT_FOR_STATE_UPDATE) return false;
212-
Main.LOGGER.info("MapLoad: map state loaded and updated");
203+
if(stateLoadWaitStart == 0) stateLoadWaitStart = System.currentTimeMillis();
204+
if(System.currentTimeMillis() - stateLoadWaitStart < STATE_LOAD_TIMEOUT) return false;
213205
stateUpdateWaitStart = stateLoadWaitStart = 0;
214-
++clickIndex;
206+
Main.LOGGER.warn("MapLoad: Timed out while waiting for map state to load!");
215207
return true;
216-
},
208+
}
209+
else if(stateUpdateWaitStart == 0){stateUpdateWaitStart = System.currentTimeMillis(); return false;}
210+
else if(System.currentTimeMillis() - stateUpdateWaitStart < WAIT_FOR_STATE_UPDATE) return false;
211+
Main.LOGGER.info("MapLoad: map state loaded and updated");
212+
stateUpdateWaitStart = stateLoadWaitStart = 0;
213+
++clickIndex;
214+
return true;
215+
},
217216
()->{
218217
clickIndex = 0;
219218
Main.LOGGER.info("MapLoad: DONE!");
220-
}
219+
},
220+
clicks
221221
);
222222
}
223223

src/main/java/net/evmodder/evmod/keybinds/KeybindMapMove.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ else if(stack.getItem() == Items.FILLED_MAP){
203203
}
204204

205205
//Main.LOGGER.info("MapMove: STARTED");
206-
Main.clickUtils.executeClicks(clicks, c->{
206+
Main.clickUtils.executeClicks(c->{
207207
// Don't start cursor-pickup move operation if we can't complete it in 1 go
208208
final Integer clicksNeeded = reserveClicks.get(c);
209209
if(clicksNeeded == null || clicksNeeded <= Main.clickUtils.calcAvailableClicks()) return true;
210210
return false; // Wait for clicks
211-
},
212-
()->Main.LOGGER.info("MapMove: DONE!")
211+
}, ()->Main.LOGGER.info("MapMove: DONE!"),
212+
clicks
213213
);
214214
}
215215

src/main/java/net/evmodder/evmod/keybinds/KeybindMapMoveBundle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ else if(!cursorStack.isEmpty()){
151151
}
152152
if(bundleSlot != -1 && !pickupHalf) clicks.add(new InvAction(bundleSlot, 0, ActionType.CLICK));
153153

154-
Main.clickUtils.executeClicks(clicks, _0->true, ()->Main.LOGGER.info("MapBundleOp: DONE!"));
154+
Main.clickUtils.executeClicks(_0->true, ()->Main.LOGGER.info("MapBundleOp: DONE!"), clicks);
155155
}
156156

157157
/*public KeybindMapMoveBundle(boolean regular, boolean reverse){

src/main/java/net/evmodder/evmod/keybinds/MapClickMoveNeighbors.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ public static void moveNeighbors(PlayerEntity player, int destSlot, ItemStack ma
176176

177177
final int numClicks = clicks.size();
178178
ongoingClickMove = true;
179-
Main.clickUtils.executeClicks(clicks, /*canProceed=*/_0->true, ()->{
179+
Main.clickUtils.executeClicks(/*canProceed=*/_0->true, ()->{
180180
ongoingClickMove = false;
181181
Main.LOGGER.info("MapMoveClick: DONE (clicks:"+numClicks+")");
182182
player.sendMessage(Text.literal("MapMoveClick: DONE (clicks:"+numClicks+")"), true);
183-
});
183+
}, clicks);
184184
// if(Main.inventoryUtils.addClick(null) >= Main.inventoryUtils.MAX_CLICKS){
185185
// Main.LOGGER.warn("Not enough clicks available to execute MapMoveNeighbors :(");
186186
// return;

src/main/java/net/evmodder/evmod/listeners/MapHandRestock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ private final void tryToStockNextMap(PlayerEntity player){
485485
// clicks.add(new ClickEvent(restockFromSlotFinal, 0, SlotActionType.PICKUP)); // Putback bundle
486486
clicks.add(new InvAction(restockFromSlotFinal, 1, ActionType.CLICK)); // Take last from bundle
487487
clicks.add(new InvAction(36+player.getInventory().selectedSlot, 0, ActionType.CLICK)); // Place in active hb slot
488-
Main.clickUtils.executeClicks(clicks, _0->true, ()->Main.LOGGER.info("HandRestockFromBundle: DONE"));
488+
Main.clickUtils.executeClicks(_0->true, ()->Main.LOGGER.info("HandRestockFromBundle: DONE"), clicks);
489489
Main.LOGGER.info("MapRestock: Extracted from bundle: s="+restockFromSlotFinal+" -> hb="+player.getInventory().selectedSlot);
490490
}
491491
else if(isHotbarSlot){

src/main/java/net/evmodder/evmod/onTick/AutoPlaceMapArt.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,6 @@ private final MapPlacementData getNearestMapPlacement(PlayerEntity player){
415415
return new MapPlacementData(nearestSlot, bundleSlot, nearestIfe);
416416
}
417417

418-
private final void executeClicks(Runnable onDone, InvAction... clicks){
419-
Main.clickUtils.executeClicks(new ArrayDeque<>(List.of(clicks)), _0->true, onDone);
420-
}
421418
private final void getMapIntoMainHand(MinecraftClient client, int slot, int bundleSlot){
422419
// assert slot != client.player.getInventory().selectedSlot+36 || bundleSlot != -1;
423420

@@ -436,7 +433,7 @@ private final void getMapIntoMainHand(MinecraftClient client, int slot, int bund
436433
}
437434
else{
438435
// Swap from upper inv to main hand
439-
executeClicks(onDone, new InvAction(slot, selectedSlot, ActionType.HOTBAR_SWAP));
436+
Main.clickUtils.executeClicks(_0->true, onDone, new InvAction(slot, selectedSlot, ActionType.HOTBAR_SWAP));
440437
Main.LOGGER.info("AutoPlaceMapArt: Swapped nextMap to inv.selectedSlot: s="+slot+"->hb="+(selectedSlot));
441438
}
442439
}
@@ -454,7 +451,7 @@ private final void getMapIntoMainHand(MinecraftClient client, int slot, int bund
454451
}
455452
else{
456453
// Try to move item out of main hand
457-
executeClicks(onDone, new InvAction(selectedSlot+36, 0, ActionType.SHIFT_CLICK));
454+
Main.clickUtils.executeClicks(_0->true, onDone, new InvAction(selectedSlot+36, 0, ActionType.SHIFT_CLICK));
458455
Main.LOGGER.info("AutoPlaceMapArt: Shift-clicking item out of mainhand (to upper inv), hb="+selectedSlot);
459456
}
460457
return;
@@ -468,7 +465,7 @@ private final void getMapIntoMainHand(MinecraftClient client, int slot, int bund
468465
}
469466
clicks.add(new InvAction(slot, 1, ActionType.CLICK)); // Take from bundle
470467
clicks.add(new InvAction(selectedSlot+36, 0, ActionType.CLICK)); // Place in main hand
471-
Main.clickUtils.executeClicks(clicks, _0->true, onDone);
468+
Main.clickUtils.executeClicks(_0->true, onDone, clicks);
472469
Main.LOGGER.info("AutoPlaceMapArt: Extracted map from bundle into mainhand");
473470
}
474471
}
@@ -552,7 +549,7 @@ public final void placeNearestMap(MinecraftClient client){
552549
Main.LOGGER.warn("AutoPlaceMapArt: item stuck on cursor! attempting to place into empty slot");
553550
for(int i=44; i>=0; --i) if(!client.player.playerScreenHandler.slots.get(i).hasStack()){
554551
// Place stack on cursor
555-
Main.clickUtils.executeClicks(new ArrayDeque<>(List.of(new InvAction(i, 0, ActionType.CLICK))), _0->true, ()->{});
552+
Main.clickUtils.executeClicks(_0->true, ()->{}, new InvAction(i, 0, ActionType.CLICK));
556553
return;
557554
}
558555
disableAndReset();

0 commit comments

Comments
 (0)