Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

Commit 72c65e2

Browse files
authored
Merge pull request #110 from Jookly123/master
refactor mining speed retrieval to account for decimal speeds
2 parents 4859ef1 + a16e64a commit 72c65e2

3 files changed

Lines changed: 38 additions & 14 deletions

File tree

src/main/java/com/jelly/mightyminerv2/feature/impl/AutoGetStats/tasks/impl/MiningSpeedRetrievalTask.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import net.minecraft.client.Minecraft;
99

1010
import java.util.List;
11+
import java.util.regex.Matcher;
12+
import java.util.regex.Pattern;
1113

1214
/**
1315
* A task that retrieves the Mining Speed value from the player's SkyBlock GUI.
@@ -17,6 +19,7 @@ public class MiningSpeedRetrievalTask extends AbstractInventoryTask<Integer> {
1719
private final Minecraft mc = Minecraft.getMinecraft();
1820
private final Clock timer = new Clock();
1921
private Integer miningSpeed;
22+
private static final Pattern MINING_SPEED_PATTERN = Pattern.compile("Mining Speed\\s+([\\d,]+\\.?\\d*)");
2023

2124
@Override
2225
public void init() {
@@ -48,16 +51,24 @@ public void onTick() {
4851

4952
List<String> loreList = InventoryUtil.getItemLoreFromOpenContainer("Your SkyBlock Profile");
5053
for (String lore : loreList) {
51-
if (!lore.contains("Mining Speed")) continue;
52-
try {
53-
String[] split = lore.replace(",", "").split(" ");
54-
miningSpeed = Integer.parseInt(split[split.length - 1]);
55-
taskStatus = TaskStatus.SUCCESS;
56-
return;
57-
} catch (Exception e) {
58-
taskStatus = TaskStatus.FAILURE;
59-
error = "Failed to parse mining speed in GUI";
60-
return;
54+
Matcher matcher = MINING_SPEED_PATTERN.matcher(lore);
55+
if (matcher.find()) {
56+
try {
57+
// The number - for example, "2,000" or "123.45" or "1,234.56"
58+
String numberAsString = matcher.group(1);
59+
String cleanNumberString = numberAsString.replace(",", "");
60+
61+
// Mining speeds from the 'sbmenu' can be a decimal
62+
double rawMiningSpeed = Double.parseDouble(cleanNumberString);
63+
miningSpeed = (int) rawMiningSpeed;
64+
65+
taskStatus = TaskStatus.SUCCESS;
66+
return;
67+
} catch (NumberFormatException e) {
68+
taskStatus = TaskStatus.FAILURE;
69+
error = "Found 'Mining Speed' but failed to parse the number in line: '" + lore + "'. Exiting with error: " + e.getMessage();
70+
return;
71+
}
6172
}
6273
}
6374

src/main/java/com/jelly/mightyminerv2/macro/impl/GlacialMacro/states/PathfindingState.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
import java.util.List;
1515

16+
import static com.jelly.mightyminerv2.util.Logger.sendError;
17+
1618
/**
1719
* PathfindingState is responsible for navigating to the best available vein
1820
* and handling the pathfinding logic for the Glacial Macro.
@@ -22,13 +24,17 @@ public class PathfindingState implements GlacialMacroState {
2224
private boolean isNavigating = false;
2325
private final Clock commissionCheckClock = new Clock();
2426

27+
// Counter for consecutive pathfinding failures (would indicate player is stuck)
28+
private int pathingFailures = 0;
29+
private static final int MAX_PATHING_FAILURES = 5;
30+
2531
@Override
2632
public void onStart(GlacialMacro macro) {
2733
log("Starting pathing state");
2834
InventoryUtil.holdItem("Aspect of the Void");
2935
RouteNavigator.getInstance().stop(); // Ensure pathfinding is stopped
3036
macro.updateMiningTasks(); // Update tasks at the beginning of each pathfinding cycle
31-
37+
pathingFailures = 0;
3238
isNavigating = false;
3339
}
3440

@@ -58,10 +64,17 @@ public GlacialMacroState onTick(GlacialMacro macro) {
5864

5965
if (RouteNavigator.getInstance().succeeded()) {
6066
log("Successfully reached the destination vein.");
67+
pathingFailures = 0;
6168
return new MiningState();
6269
} else {
6370
Pair<GlaciteVeins, RouteWaypoint> failedVein = macro.getCurrentVein();
6471
logError("RouteNavigator failed to reach destination: " + (failedVein != null ? failedVein.first() : "Unknown"));
72+
pathingFailures++;
73+
log("Pathing failure count: " + pathingFailures);
74+
if (pathingFailures >= MAX_PATHING_FAILURES) {
75+
sendError("Failed to pathfind " + MAX_PATHING_FAILURES + " times. Assuming player is stuck. Changing lobbies.");
76+
return new NewLobbyState();
77+
}
6578

6679
if (failedVein != null) {
6780
log("Blacklisting the unreachable vein.");
@@ -87,6 +100,7 @@ public GlacialMacroState onTick(GlacialMacro macro) {
87100
// Check if we are already at the destination
88101
if (bestVein.second().isWithinRange(PlayerUtil.getBlockStandingOn(), 2)) {
89102
log("Already at the destination. Starting to mine");
103+
pathingFailures = 0;
90104
return new MiningState();
91105
}
92106

src/main/java/com/jelly/mightyminerv2/macro/impl/GlacialMacro/states/StartingState.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public GlacialMacroState onTick(GlacialMacro macro) {
2929
}
3030

3131
SubLocation subLocation = GameStateHandler.getInstance().getCurrentSubLocation();
32-
if (subLocation == SubLocation.GLACITE_TUNNELS || subLocation == SubLocation.DWARVEN_BASE_CAMP) {
33-
32+
if (subLocation == SubLocation.DWARVEN_BASE_CAMP) {
3433
if (!InventoryUtil.areItemsInHotbar(macro.getNecessaryItems())) {
3534
macro.disable("Please put the following items in hotbar: " + InventoryUtil.getMissingItemsInHotbar(macro.getNecessaryItems()));
3635
return null;
@@ -39,7 +38,7 @@ public GlacialMacroState onTick(GlacialMacro macro) {
3938
log("Player is in a valid location. Initialising stats");
4039
return new GettingStatsState();
4140
} else {
42-
log("Player is not in the Glacite Tunnels. Teleporting...");
41+
log("Player is not at Dwarven Base Camp. Teleporting...");
4342
return new TeleportingState(new StartingState());
4443
}
4544
}

0 commit comments

Comments
 (0)