Skip to content

Commit ff5e3fa

Browse files
committed
Update AutoFly
1 parent 4d3750d commit ff5e3fa

2 files changed

Lines changed: 105 additions & 68 deletions

File tree

src/main/java/net/wurstclient/hacks/AutoFlyHack.java

Lines changed: 71 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,27 @@ public String toString()
112112
}
113113
}
114114

115+
public static enum ClickGuiStartMode
116+
{
117+
DIRECTIONAL("Directional (.autofly)"),
118+
CHUNKS("Chunk trail (.autofly chunk)"),
119+
GRID("Grid"),
120+
WAYPOINTS("Waypoints");
121+
122+
private final String name;
123+
124+
ClickGuiStartMode(String name)
125+
{
126+
this.name = name;
127+
}
128+
129+
@Override
130+
public String toString()
131+
{
132+
return name;
133+
}
134+
}
135+
115136
public static enum StopOnType
116137
{
117138
OFF("Off"),
@@ -143,6 +164,13 @@ public String toString()
143164
"Waypoints list. Format: x y z or x z (no Y). Separate by ';' or new lines.",
144165
"");
145166

167+
private final EnumSetting<ClickGuiStartMode> clickGuiStartMode =
168+
new EnumSetting<>("ClickGUI start mode",
169+
"What AutoFly should start when enabled from ClickGUI.\n\n"
170+
+ "Directional = same as .autofly\n"
171+
+ "Chunk trail = same as .autofly chunk",
172+
ClickGuiStartMode.values(), ClickGuiStartMode.DIRECTIONAL);
173+
146174
private final EnumSetting<RouteType> routeType = new EnumSetting<>(
147175
"Route type",
148176
"Where AutoFly gets its targets from.\n\n"
@@ -402,6 +430,7 @@ public AutoFlyHack()
402430
{
403431
super("AutoFly");
404432
setCategory(Category.MOVEMENT);
433+
addSetting(clickGuiStartMode);
405434
addSetting(waypointText);
406435
addSetting(routeType);
407436
addSetting(gridWidthChunks);
@@ -461,16 +490,7 @@ protected void onEnable()
461490
useExistingTargetsOnEnable = false;
462491
else
463492
{
464-
if(routeType.getSelected() == RouteType.GRID)
465-
loadTargetsFromGrid(MC.player.blockPosition());
466-
else if(routeType.getSelected() == RouteType.CHUNKS)
467-
{
468-
targets.clear();
469-
currentTarget = null;
470-
currentIndex = -1;
471-
chunkTrailPath.clear();
472-
}else
473-
loadTargetsFromSettings();
493+
startFromClickGuiMode();
474494
}
475495
if(targets.isEmpty())
476496
{
@@ -701,24 +721,23 @@ public void onUpdate()
701721
{
702722
if(checkChunkTrailPortalStop())
703723
return;
704-
}else
705-
{
706-
if(checkStopOn(stopOn, stopKeyword, false))
707-
return;
708-
709-
if(checkStopOn(stopOn2, stopKeyword2, true))
710-
return;
711-
712-
if(checkStopOn(stopOn3, stopKeyword3, false))
713-
return;
714-
715-
if(checkStopOnPlayers())
716-
return;
717-
718-
if(checkDisableOnDamage())
719-
return;
720724
}
721725

726+
if(checkStopOn(stopOn, stopKeyword, false))
727+
return;
728+
729+
if(checkStopOn(stopOn2, stopKeyword2, true))
730+
return;
731+
732+
if(checkStopOn(stopOn3, stopKeyword3, false))
733+
return;
734+
735+
if(checkStopOnPlayers())
736+
return;
737+
738+
if(checkDisableOnDamage())
739+
return;
740+
722741
if(allowManualAdjust.isChecked() && isManualInputActive())
723742
{
724743
beginManualAdjust(MC.player.position());
@@ -1489,6 +1508,32 @@ private void loadTargetsFromSettings()
14891508
loadTargetsFromJson();
14901509
}
14911510

1511+
private void startFromClickGuiMode()
1512+
{
1513+
ClickGuiStartMode mode = clickGuiStartMode.getSelected();
1514+
if(mode == null)
1515+
mode = ClickGuiStartMode.DIRECTIONAL;
1516+
1517+
switch(mode)
1518+
{
1519+
case DIRECTIONAL -> setForwardFromCommand(null, null, true);
1520+
1521+
case CHUNKS -> setChunkTrailFromCommand();
1522+
1523+
case GRID ->
1524+
{
1525+
routeType.setSelected(RouteType.GRID);
1526+
loadTargetsFromGrid(MC.player.blockPosition());
1527+
}
1528+
1529+
case WAYPOINTS ->
1530+
{
1531+
routeType.setSelected(RouteType.WAYPOINTS);
1532+
loadTargetsFromSettings();
1533+
}
1534+
}
1535+
}
1536+
14921537
private void startGridFromPlayer()
14931538
{
14941539
if(MC.player == null)

src/main/java/net/wurstclient/hud/GameStatsHud.java

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public final class GameStatsHud
3636
private static final float PADDING = 4F;
3737
private static final float LINE_GAP = 2F;
3838
private static final long SAMPLE_INTERVAL_MS = 1000L;
39-
private static final long SPEED_WINDOW_MS = 600L;
40-
private static final double SPEED_EMA_ALPHA = 0.5;
39+
private static final long SPEED_WINDOW_MS = 3000L;
4140
private static final double SPEED_MAX_PLAUSIBLE_BPS = 5000.0;
4241
private static final float GRAPH_GAP = 4F;
4342
private static final float GRAPH_TO_TEXT_GAP = 2F;
@@ -71,11 +70,7 @@ public final class GameStatsHud
7170
private double lastY;
7271
private double lastZ;
7372
private long lastMovementSampleMs;
74-
private final ArrayDeque<MovementSample> movementSamples =
75-
new ArrayDeque<>();
76-
private long movementWindowDurationMs;
77-
private double movementWindowDistance;
78-
private double liveSpeedBps;
73+
private final ArrayDeque<MovementPoint> movementPoints = new ArrayDeque<>();
7974
private double smoothedSpeedBps;
8075
private int mobKillsBaseline = -1;
8176
private int playerKillsBaseline = -1;
@@ -313,9 +308,7 @@ private void updateSessionTracking()
313308
if(Double.isFinite(delta) && delta >= 0)
314309
{
315310
distanceTravelledMeters += delta;
316-
long dtMs = Math.max(1L, now - lastMovementSampleMs);
317-
double horizontalDelta = Math.hypot(dx, dz);
318-
pushMovementSample(horizontalDelta, dtMs);
311+
pushMovementSample(x, z, now);
319312
}
320313
}
321314

@@ -424,41 +417,38 @@ private static String formatDistance(double meters)
424417

425418
private void resetMovementSpeed()
426419
{
427-
movementSamples.clear();
428-
movementWindowDurationMs = 0L;
429-
movementWindowDistance = 0;
430-
liveSpeedBps = 0;
420+
movementPoints.clear();
431421
smoothedSpeedBps = 0;
432422
}
433423

434-
private void pushMovementSample(double distance, long dtMs)
424+
private void pushMovementSample(double x, double z, long nowMs)
435425
{
436-
if(dtMs <= 0L || !Double.isFinite(distance) || distance < 0)
426+
if(!Double.isFinite(x) || !Double.isFinite(z))
437427
return;
438428

439-
double dtSec = dtMs / 1000D;
440-
double maxDistance = SPEED_MAX_PLAUSIBLE_BPS * dtSec;
441-
distance = Math.min(distance, maxDistance);
442-
443-
movementSamples.addLast(new MovementSample(distance, dtMs));
444-
movementWindowDistance += distance;
445-
movementWindowDurationMs += dtMs;
429+
movementPoints.addLast(new MovementPoint(x, z, nowMs));
430+
long minTime = nowMs - SPEED_WINDOW_MS;
431+
while(movementPoints.size() > 2
432+
&& movementPoints.peekFirst().timestampMs < minTime)
433+
movementPoints.removeFirst();
446434

447-
while(movementWindowDurationMs > SPEED_WINDOW_MS
448-
&& !movementSamples.isEmpty())
449-
{
450-
MovementSample oldest = movementSamples.removeFirst();
451-
movementWindowDistance -= oldest.distance;
452-
movementWindowDurationMs -= oldest.durationMs;
453-
}
435+
MovementPoint oldest = movementPoints.peekFirst();
436+
MovementPoint newest = movementPoints.peekLast();
437+
if(oldest == null || newest == null)
438+
return;
454439

455-
if(movementWindowDurationMs <= 0L)
456-
liveSpeedBps = 0;
457-
else
458-
liveSpeedBps =
459-
movementWindowDistance / (movementWindowDurationMs / 1000D);
440+
long dtMs = newest.timestampMs - oldest.timestampMs;
441+
if(dtMs <= 0L)
442+
return;
460443

461-
smoothedSpeedBps += SPEED_EMA_ALPHA * (liveSpeedBps - smoothedSpeedBps);
444+
double dx = newest.x - oldest.x;
445+
double dz = newest.z - oldest.z;
446+
double netDistance = Math.hypot(dx, dz);
447+
double dtSec = dtMs / 1000D;
448+
double speed = netDistance / dtSec;
449+
double maxDistance = SPEED_MAX_PLAUSIBLE_BPS * dtSec;
450+
speed = Math.min(speed, maxDistance / dtSec);
451+
smoothedSpeedBps = speed;
462452
}
463453

464454
private static String getWorldTime24h()
@@ -1028,15 +1018,17 @@ private static int withAlpha(int rgb, int alpha)
10281018
return (Math.max(0, Math.min(255, alpha)) << 24) | (rgb & 0x00FFFFFF);
10291019
}
10301020

1031-
private static final class MovementSample
1021+
private static final class MovementPoint
10321022
{
1033-
private final double distance;
1034-
private final long durationMs;
1023+
private final double x;
1024+
private final double z;
1025+
private final long timestampMs;
10351026

1036-
private MovementSample(double distance, long durationMs)
1027+
private MovementPoint(double x, double z, long timestampMs)
10371028
{
1038-
this.distance = distance;
1039-
this.durationMs = durationMs;
1029+
this.x = x;
1030+
this.z = z;
1031+
this.timestampMs = timestampMs;
10401032
}
10411033
}
10421034
}

0 commit comments

Comments
 (0)