Skip to content
Open
Changes from all commits
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
26 changes: 18 additions & 8 deletions src/main/java/dev/shared/kopoklesz/behaviour/AutoRefin.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

@Feature(name = "Auto refiner", description = "Automatically refine materials")
public class AutoRefin implements Behavior, Configurable<AutoRefinConfig> {
private static final long TRADE_WINDOW_ADDRESS_OFFSET = 0x78L;

private final OreAPI ores;
private final GuiManager guiManager;
Expand Down Expand Up @@ -81,19 +82,28 @@ public void onTickBehavior() {
ore -> ore,
this::maxRefine));

lastRefineAttemptFailed = true; // assume refine attempt will fail
lastCargoAmount = currentCargo; // update last cargo amount

// Find the ore with the highest refineable amount
refineMap.entrySet().stream()
.filter(e -> e.getValue() > 0)
.max(Map.Entry.comparingByValue())
.ifPresent(entry -> {
darkbotApi.refine(
darkbotApi.readLong(guiManager.getAddress() + 0x78),
entry.getKey(),
entry.getValue());
lastRefineAttemptFailed = false; // refine attempt succeeded
try {
long guiAddress = guiManager.getAddress();
if (guiAddress == 0)
return;

long tradeWindowAddress = darkbotApi.readLong(guiAddress + TRADE_WINDOW_ADDRESS_OFFSET);
if (tradeWindowAddress == 0)
return;
Comment on lines +92 to +97
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lastRefineAttemptFailed/lastCargoAmount are updated before verifying GUI/trade-window addresses, and the lambda returns early when guiAddress/tradeWindowAddress are 0. That leaves lastRefineAttemptFailed=true with unchanged cargo, so subsequent ticks will return at the if (lastRefineAttemptFailed && currentCargo == lastCargoAmount) guard and never re-check the addresses until cargo changes. This prevents recovery after a transient invalid GUI state. Consider only marking an attempt as "failed" (and caching cargo) after the addresses are validated and an actual refine call is attempted, or resetting the tracking variables when skipping due to invalid addresses so the next tick can retry.

Suggested change
if (guiAddress == 0)
return;
long tradeWindowAddress = darkbotApi.readLong(guiAddress + 0x78);
if (tradeWindowAddress == 0)
return;
if (guiAddress == 0) {
// GUI address invalid, don't treat this as a failed refine attempt
lastRefineAttemptFailed = false;
lastCargoAmount = -1;
return;
}
long tradeWindowAddress = darkbotApi.readLong(guiAddress + 0x78);
if (tradeWindowAddress == 0) {
// Trade window address invalid, don't treat this as a failed refine attempt
lastRefineAttemptFailed = false;
lastCargoAmount = -1;
return;
}

Copilot uses AI. Check for mistakes.

lastRefineAttemptFailed = true; // assume refine attempt will fail
lastCargoAmount = currentCargo; // update last cargo amount
darkbotApi.refine(tradeWindowAddress, entry.getKey(), entry.getValue());
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
lastRefineAttemptFailed = false; // refine attempt succeeded
} catch (RuntimeException ignored) {
// Keep bot alive on transient client/API states (for example while user
// interacts with upgrade windows), retry next tick.
}
});
}

Expand Down
Loading