From 9ad273a46c689cb469b3da1fd870615b7c805ebe Mon Sep 17 00:00:00 2001 From: Babbaj Date: Sat, 23 Sep 2023 17:00:11 -0400 Subject: [PATCH] silence elytra chat spam --- fabric/build.gradle | 2 +- src/api/java/baritone/api/Settings.java | 5 +++ .../java/baritone/process/ElytraProcess.java | 20 ++++++------ .../process/elytra/ElytraBehavior.java | 32 +++++++++++-------- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/fabric/build.gradle b/fabric/build.gradle index c88ff80ef..30ed3926d 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -103,4 +103,4 @@ publishing { repositories { // Add repositories to publish to here. } -} \ No newline at end of file +} diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index adbbd6eaa..9171a3d68 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -1468,6 +1468,11 @@ public final class Settings { */ public final Setting elytraTermsAccepted = new Setting<>(false); + /** + * Verbose chat logging in elytra mode + */ + public final Setting elytraChatSpam = new Setting<>(false); + /** * A map of lowercase setting field names to their respective setting */ diff --git a/src/main/java/baritone/process/ElytraProcess.java b/src/main/java/baritone/process/ElytraProcess.java index d1e10a5cf..2c57c6f55 100644 --- a/src/main/java/baritone/process/ElytraProcess.java +++ b/src/main/java/baritone/process/ElytraProcess.java @@ -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); @@ -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) { diff --git a/src/main/java/baritone/process/elytra/ElytraBehavior.java b/src/main/java/baritone/process/elytra/ElytraBehavior.java index 501c6a22b..d4913f466 100644 --- a/src/main/java/baritone/process/elytra/ElytraBehavior.java +++ b/src/main/java/baritone/process/elytra/ElytraBehavior.java @@ -174,9 +174,9 @@ public CompletableFuture 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) -> { @@ -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) -> { @@ -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 { @@ -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; @@ -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), @@ -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")); } } @@ -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); @@ -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); @@ -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; @@ -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); + } + } }