Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

silence elytra chat spam #4137

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ publishing {
repositories {
// Add repositories to publish to here.
}
}
}
5 changes: 5 additions & 0 deletions src/api/java/baritone/api/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,11 @@ public final class Settings {
*/
public final Setting<Boolean> elytraTermsAccepted = new Setting<>(false);

/**
* Verbose chat logging in elytra mode
*/
public final Setting<Boolean> elytraChatSpam = new Setting<>(false);

/**
* A map of lowercase setting field names to their respective setting
*/
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/baritone/process/ElytraProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public class ElytraProcess extends BaritoneProcessHelper implements IBaritonePro
private ElytraBehavior behavior;
private boolean predictingTerrain;

@Override
public void onLostControl() {
this.state = State.START_FLYING; // TODO: null state?
this.goingToLandingSpot = false;
this.landingSpot = null;
this.reachedGoal = false;
this.goal = null;
destroyBehaviorAsync();
}

private ElytraProcess(Baritone baritone) {
super(baritone);
baritone.getGameEventHandler().registerEventListener(this);
Expand Down Expand Up @@ -276,16 +286,6 @@ public void landingSpotIsBad(BetterBlockPos endPos) {
this.state = State.FLYING;
}

@Override
public void onLostControl() {
this.goal = null;
this.goingToLandingSpot = false;
this.landingSpot = null;
this.reachedGoal = false;
this.state = State.START_FLYING; // TODO: null state?
destroyBehaviorAsync();
}

private void destroyBehaviorAsync() {
ElytraBehavior behavior = this.behavior;
if (behavior != null) {
Expand Down
32 changes: 19 additions & 13 deletions src/main/java/baritone/process/elytra/ElytraBehavior.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ public CompletableFuture<Void> pathToDestination(final BlockPos from) {
.thenRun(() -> {
final double distance = this.path.get(0).distanceTo(this.path.get(this.path.size() - 1));
if (this.completePath) {
logDirect(String.format("Computed path (%.1f blocks in %.4f seconds)", distance, (System.nanoTime() - start) / 1e9d));
logVerbose(String.format("Computed path (%.1f blocks in %.4f seconds)", distance, (System.nanoTime() - start) / 1e9d));
} else {
logDirect(String.format("Computed segment (Next %.1f blocks in %.4f seconds)", distance, (System.nanoTime() - start) / 1e9d));
logVerbose(String.format("Computed segment (Next %.1f blocks in %.4f seconds)", distance, (System.nanoTime() - start) / 1e9d));
}
})
.whenComplete((result, ex) -> {
Expand Down Expand Up @@ -231,9 +231,9 @@ public void pathNextSegment(final int afterIncl) {
final double distance = this.path.get(0).distanceTo(this.path.get(recompute));

if (this.completePath) {
logDirect(String.format("Computed path (%.1f blocks in %.4f seconds)", distance, (System.nanoTime() - start) / 1e9d));
logVerbose(String.format("Computed path (%.1f blocks in %.4f seconds)", distance, (System.nanoTime() - start) / 1e9d));
} else {
logDirect(String.format("Computed segment (Next %.1f blocks in %.4f seconds)", distance, (System.nanoTime() - start) / 1e9d));
logVerbose(String.format("Computed segment (Next %.1f blocks in %.4f seconds)", distance, (System.nanoTime() - start) / 1e9d));
}
})
.whenComplete((result, ex) -> {
Expand All @@ -243,7 +243,7 @@ public void pathNextSegment(final int afterIncl) {
if (cause instanceof PathCalculationException) {
logDirect("Failed to compute next segment");
if (ctx.player().distanceToSqr(pathStart.getCenter()) < 16 * 16) {
logDirect("Player is near the segment start, therefore repeating this calculation is pointless. Marking as complete");
logVerbose("Player is near the segment start, therefore repeating this calculation is pointless. Marking as complete");
completePath = true;
}
} else {
Expand Down Expand Up @@ -321,7 +321,7 @@ private void pathfindAroundObstacles() {
if (ElytraBehavior.this.process.state != ElytraProcess.State.LANDING && this.ticksNearUnchanged > 100) {
this.pathRecalcSegment(OptionalInt.of(rangeEndExcl - 1))
.thenRun(() -> {
logDirect("Recalculating segment, no progress in last 100 ticks");
logVerbose("Recalculating segment, no progress in last 100 ticks");
});
this.ticksNearUnchanged = 0;
return;
Expand All @@ -348,7 +348,7 @@ private void pathfindAroundObstacles() {
final long start = System.nanoTime();
this.pathRecalcSegment(rejoinMainPathAt)
.thenRun(() -> {
logDirect(String.format("Recalculated segment around path blockage near %s %s %s (next %.1f blocks in %.4f seconds)",
logVerbose(String.format("Recalculated segment around path blockage near %s %s %s (next %.1f blocks in %.4f seconds)",
SettingsUtil.maybeCensor(blockage.x),
SettingsUtil.maybeCensor(blockage.y),
SettingsUtil.maybeCensor(blockage.z),
Expand All @@ -360,7 +360,7 @@ private void pathfindAroundObstacles() {
}
}
if (!canSeeAny && rangeStartIncl < rangeEndExcl - 2 && process.state != ElytraProcess.State.GET_TO_JUMP) {
this.pathRecalcSegment(OptionalInt.of(rangeEndExcl - 1)).thenRun(() -> logDirect("Recalculated segment since no path points were visible"));
this.pathRecalcSegment(OptionalInt.of(rangeEndExcl - 1)).thenRun(() -> logVerbose("Recalculated segment since no path points were visible"));
}
}

Expand Down Expand Up @@ -581,10 +581,10 @@ public void tick() {
trySwapElytra();

if (ctx.player().horizontalCollision) {
logDirect("hbonk");
logVerbose("hbonk");
}
if (ctx.player().verticalCollision) {
logDirect("vbonk");
logVerbose("vbonk");
}

final SolverContext solverContext = this.new SolverContext(false);
Expand All @@ -609,14 +609,14 @@ public void tick() {
}

if (solution == null) {
logDirect("no solution");
logVerbose("no solution");
return;
}

baritone.getLookBehavior().updateTarget(solution.rotation, false);

if (!solution.solvedPitch) {
logDirect("no pitch solution, probably gonna crash in a few ticks LOL!!!");
logVerbose("no pitch solution, probably gonna crash in a few ticks LOL!!!");
return;
} else {
this.aimPos = new BetterBlockPos(solution.goingTo.x, solution.goingTo.y, solution.goingTo.z);
Expand Down Expand Up @@ -758,7 +758,7 @@ private void tickUseFireworks(final Vec3 start, final Vec3 goingTo, final boolea
logDirect("no fireworks");
return;
}
logDirect("attempting to use firework" + (forceUseFirework ? " (forced)" : ""));
logVerbose("attempting to use firework" + (forceUseFirework ? " (forced)" : ""));
ctx.playerController().processRightClick(ctx.player(), ctx.world(), InteractionHand.MAIN_HAND);
this.minimumBoostTicks = 10 * (1 + getFireworkBoost(ctx.player().getItemInHand(InteractionHand.MAIN_HAND)).orElse(0));
this.remainingFireworkTicks = 10;
Expand Down Expand Up @@ -1317,4 +1317,10 @@ private void trySwapElytra() {
queueWindowClick(ctx.player().inventoryMenu.containerId, slotId, 0, ClickType.PICKUP);
}
}

void logVerbose(String message) {
if (Baritone.settings().elytraChatSpam.value) {
logDebug(message);
}
}
}