From ff2714b15fe05fcb338ffe68a2b0bab5d05c15f1 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 11 Sep 2018 13:45:43 -0700 Subject: [PATCH] refactor logging, fixes #153 --- .../baritone/behavior/impl/MineBehavior.java | 2 +- .../behavior/impl/PathingBehavior.java | 22 +++--- .../pathing/calc/AStarPathFinder.java | 10 +-- .../movement/movements/MovementPillar.java | 2 +- .../movement/movements/MovementTraverse.java | 6 +- .../java/baritone/pathing/path/IPath.java | 8 +- .../baritone/pathing/path/PathExecutor.java | 20 ++--- .../utils/ExampleBaritoneControl.java | 76 +++++++++---------- src/main/java/baritone/utils/Helper.java | 17 ++++- 9 files changed, 86 insertions(+), 77 deletions(-) diff --git a/src/main/java/baritone/behavior/impl/MineBehavior.java b/src/main/java/baritone/behavior/impl/MineBehavior.java index ab68783e..5b0d6a5a 100644 --- a/src/main/java/baritone/behavior/impl/MineBehavior.java +++ b/src/main/java/baritone/behavior/impl/MineBehavior.java @@ -60,7 +60,7 @@ public class MineBehavior extends Behavior { } List locs = scanFor(mining, 64); if (locs.isEmpty()) { - displayChatMessageRaw("No locations for " + mining + " known, cancelling"); + logDebug("No locations for " + mining + " known, cancelling"); cancel(); return; } diff --git a/src/main/java/baritone/behavior/impl/PathingBehavior.java b/src/main/java/baritone/behavior/impl/PathingBehavior.java index 14060fba..cd4cf357 100644 --- a/src/main/java/baritone/behavior/impl/PathingBehavior.java +++ b/src/main/java/baritone/behavior/impl/PathingBehavior.java @@ -77,14 +77,14 @@ public class PathingBehavior extends Behavior { if (current.failed() || current.finished()) { current = null; if (goal == null || goal.isInGoal(playerFeet())) { - displayChatMessageRaw("All done. At " + goal); + logDebug("All done. At " + goal); dispatchPathEvent(PathEvent.AT_GOAL); next = null; return; } if (next != null && !next.getPath().positions().contains(playerFeet())) { // if the current path failed, we may not actually be on the next one, so make sure - displayChatMessageRaw("Discarding next path as it does not contain current position"); + logDebug("Discarding next path as it does not contain current position"); // for example if we had a nicely planned ahead path that starts where current ends // that's all fine and good // but if we fail in the middle of current @@ -94,7 +94,7 @@ public class PathingBehavior extends Behavior { next = null; } if (next != null) { - displayChatMessageRaw("Continuing on to planned next path"); + logDebug("Continuing on to planned next path"); dispatchPathEvent(PathEvent.CONTINUING_ONTO_PLANNED_NEXT); current = next; next = null; @@ -118,7 +118,7 @@ public class PathingBehavior extends Behavior { if (next != null) { if (next.getPath().positions().contains(playerFeet())) { // jump directly onto the next path - displayChatMessageRaw("Splicing into planned next path early..."); + logDebug("Splicing into planned next path early..."); dispatchPathEvent(PathEvent.SPLICING_ONTO_NEXT_EARLY); current = next; next = null; @@ -141,7 +141,7 @@ public class PathingBehavior extends Behavior { } if (ticksRemainingInSegment().get() < Baritone.settings().planningTickLookAhead.get()) { // and this path has 5 seconds or less left - displayChatMessageRaw("Path almost over. Planning ahead..."); + logDebug("Path almost over. Planning ahead..."); dispatchPathEvent(PathEvent.NEXT_SEGMENT_CALC_STARTED); findPathInNewThread(current.getPath().getDest(), false, Optional.of(current.getPath())); } @@ -248,7 +248,7 @@ public class PathingBehavior extends Behavior { } new Thread(() -> { if (talkAboutIt) { - displayChatMessageRaw("Starting to search for path from " + start + " to " + goal); + logDebug("Starting to search for path from " + start + " to " + goal); } Optional path = findPath(start, previous); @@ -280,9 +280,9 @@ public class PathingBehavior extends Behavior { if (talkAboutIt && current != null && current.getPath() != null) { if (goal == null || goal.isInGoal(current.getPath().getDest())) { - displayChatMessageRaw("Finished finding a path from " + start + " to " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered"); + logDebug("Finished finding a path from " + start + " to " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered"); } else { - displayChatMessageRaw("Found path segment from " + start + " towards " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered"); + logDebug("Found path segment from " + start + " towards " + goal + ". " + current.getPath().getNumNodesConsidered() + " nodes considered"); } } @@ -301,7 +301,7 @@ public class PathingBehavior extends Behavior { private Optional findPath(BlockPos start, Optional previous) { Goal goal = this.goal; if (goal == null) { - displayChatMessageRaw("no goal"); + logDebug("no goal"); return Optional.empty(); } if (Baritone.settings().simplifyUnloadedYCoord.get()) { @@ -320,7 +320,7 @@ public class PathingBehavior extends Behavior { } // TODO simplify each individual goal in a GoalComposite if (pos != null && world().getChunk(pos) instanceof EmptyChunk) { - displayChatMessageRaw("Simplifying " + goal.getClass() + " to GoalXZ due to distance"); + logDebug("Simplifying " + goal.getClass() + " to GoalXZ due to distance"); goal = new GoalXZ(pos.getX(), pos.getZ()); } } @@ -334,7 +334,7 @@ public class PathingBehavior extends Behavior { IPathFinder pf = new AStarPathFinder(start, goal, previous.map(IPath::positions)); return pf.calculate(timeout); } catch (Exception e) { - displayChatMessageRaw("Pathing exception: " + e); + logDebug("Pathing exception: " + e); e.printStackTrace(); return Optional.empty(); } diff --git a/src/main/java/baritone/pathing/calc/AStarPathFinder.java b/src/main/java/baritone/pathing/calc/AStarPathFinder.java index 674d5b64..16bc1997 100644 --- a/src/main/java/baritone/pathing/calc/AStarPathFinder.java +++ b/src/main/java/baritone/pathing/calc/AStarPathFinder.java @@ -77,7 +77,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { long startTime = System.nanoTime() / 1000000L; boolean slowPath = Baritone.settings().slowPath.get(); if (slowPath) { - displayChatMessageRaw("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.get() + "ms instead of " + timeout + "ms"); + logDebug("slowPath is on, path timeout will be " + Baritone.settings().slowPathTimeoutMS.get() + "ms instead of " + timeout + "ms"); } long timeoutTime = startTime + (slowPath ? Baritone.settings().slowPathTimeoutMS.get() : timeout); //long lastPrintout = 0; @@ -102,7 +102,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { numNodes++; if (goal.isInGoal(currentNodePos)) { currentlyRunning = null; - displayChatMessageRaw("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered"); + logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, " + numMovementsConsidered + " movements considered"); return Optional.of(new Path(startNode, currentNode, numNodes)); } Movement[] possibleMovements = getConnectedPositions(currentNodePos, calcContext);//movement that we could take that start at currentNodePos, in random order @@ -191,7 +191,7 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { bestDist = dist; } if (dist > MIN_DIST_PATH * MIN_DIST_PATH) { // square the comparison since distFromStartSq is squared - displayChatMessageRaw("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered"); + logDebug("Took " + (System.nanoTime() / 1000000L - startTime) + "ms, A* cost coefficient " + COEFFICIENTS[i] + ", " + numMovementsConsidered + " movements considered"); if (COEFFICIENTS[i] >= 3) { System.out.println("Warning: cost coefficient is greater than three! Probably means that"); System.out.println("the path I found is pretty terrible (like sneak-bridging for dozens of blocks)"); @@ -202,8 +202,8 @@ public class AStarPathFinder extends AbstractNodeCostSearch implements Helper { return Optional.of(new Path(startNode, bestSoFar[i], numNodes)); } } - displayChatMessageRaw("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks"); - displayChatMessageRaw("No path found =("); + logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks"); + logDebug("No path found =("); currentlyRunning = null; return Optional.empty(); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java index 73a591ad..db5bbf49 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementPillar.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementPillar.java @@ -139,7 +139,7 @@ public class MovementPillar extends Movement { if (ladder) { BlockPos against = vine ? getAgainst(src) : src.offset(fromDown.getValue(BlockLadder.FACING).getOpposite()); if (against == null) { - displayChatMessageRaw("Unable to climb vines"); + logDebug("Unable to climb vines"); return state.setStatus(MovementState.MovementStatus.UNREACHABLE); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index da206d5e..67430d05 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -171,7 +171,7 @@ public class MovementTraverse extends Movement { boolean isTheBridgeBlockThere = MovementHelper.canWalkOn(positionToPlace) || ladder; BlockPos whereAmI = playerFeet(); if (whereAmI.getY() != dest.getY() && !ladder) { - displayChatMessageRaw("Wrong Y coordinate"); + logDebug("Wrong Y coordinate"); if (whereAmI.getY() < dest.getY()) { state.setInput(InputOverrideHandler.Input.JUMP, true); } @@ -203,7 +203,7 @@ public class MovementTraverse extends Movement { against1 = against1.down(); if (MovementHelper.canPlaceAgainst(against1)) { if (!MovementHelper.throwaway(true)) { // get ready to place a throwaway block - displayChatMessageRaw("bb pls get me some blocks. dirt or cobble"); + logDebug("bb pls get me some blocks. dirt or cobble"); return state.setStatus(MovementState.MovementStatus.UNREACHABLE); } state.setInput(InputOverrideHandler.Input.SNEAK, true); @@ -240,7 +240,7 @@ public class MovementTraverse extends Movement { // If we are in the block that we are trying to get to, we are sneaking over air and we need to place a block beneath us against the one we just walked off of // Out.log(from + " " + to + " " + faceX + "," + faceY + "," + faceZ + " " + whereAmI); if (!MovementHelper.throwaway(true)) {// get ready to place a throwaway block - displayChatMessageRaw("bb pls get me some blocks. dirt or cobble"); + logDebug("bb pls get me some blocks. dirt or cobble"); return state.setStatus(MovementState.MovementStatus.UNREACHABLE); } double faceX = (dest.getX() + src.getX() + 1.0D) * 0.5D; diff --git a/src/main/java/baritone/pathing/path/IPath.java b/src/main/java/baritone/pathing/path/IPath.java index 39c17993..0db487d5 100644 --- a/src/main/java/baritone/pathing/path/IPath.java +++ b/src/main/java/baritone/pathing/path/IPath.java @@ -128,12 +128,12 @@ public interface IPath extends Helper { for (int i = 0; i < positions().size(); i++) { BlockPos pos = positions().get(i); if (Minecraft.getMinecraft().world.getChunk(pos) instanceof EmptyChunk) { - displayChatMessageRaw("Cutting off path at edge of loaded chunks"); - displayChatMessageRaw("Length decreased by " + (positions().size() - i - 1)); + logDebug("Cutting off path at edge of loaded chunks"); + logDebug("Length decreased by " + (positions().size() - i - 1)); return new CutoffPath(this, i); } } - displayChatMessageRaw("Path ends within loaded chunks"); + logDebug("Path ends within loaded chunks"); return this; } @@ -146,7 +146,7 @@ public interface IPath extends Helper { } double factor = Baritone.settings().pathCutoffFactor.get(); int newLength = (int) (length() * factor); - //displayChatMessageRaw("Static cutoff " + length() + " to " + newLength); + //logDebug("Static cutoff " + length() + " to " + newLength); return new CutoffPath(this, newLength); } } diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index c1281359..5a8af7db 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -92,7 +92,7 @@ public class PathExecutor implements Helper { if (!Blocks.AIR.equals(BlockStateInterface.getBlock(whereAmI.down()))) {//do not skip if standing on air, because our position isn't stable to skip for (int i = 0; i < pathPosition - 1 && i < path.length(); i++) {//this happens for example when you lag out and get teleported back a couple blocks if (whereAmI.equals(path.positions().get(i))) { - displayChatMessageRaw("Skipping back " + (pathPosition - i) + " steps, to " + i); + logDebug("Skipping back " + (pathPosition - i) + " steps, to " + i); int previousPos = pathPosition; pathPosition = Math.max(i - 1, 0); // previous step might not actually be done for (int j = pathPosition; j <= previousPos; j++) { @@ -105,7 +105,7 @@ public class PathExecutor implements Helper { for (int i = pathPosition + 2; i < path.length(); i++) { //dont check pathPosition+1. the movement tells us when it's done (e.g. sneak placing) if (whereAmI.equals(path.positions().get(i))) { if (i - pathPosition > 2) { - displayChatMessageRaw("Skipping forward " + (i - pathPosition) + " steps, to " + i); + logDebug("Skipping forward " + (i - pathPosition) + " steps, to " + i); } System.out.println("Double skip sundae"); pathPosition = i - 1; @@ -121,7 +121,7 @@ public class PathExecutor implements Helper { ticksAway++; System.out.println("FAR AWAY FROM PATH FOR " + ticksAway + " TICKS. Current distance: " + distanceFromPath + ". Threshold: " + MAX_DIST_FROM_PATH); if (ticksAway > MAX_TICKS_AWAY) { - displayChatMessageRaw("Too far away from path for too long, cancelling path"); + logDebug("Too far away from path for too long, cancelling path"); System.out.println("Too many ticks"); pathPosition = path.length() + 3; Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); @@ -134,7 +134,7 @@ public class PathExecutor implements Helper { if (distanceFromPath > MAX_MAX_DIST_FROM_PATH) { if (!(path.movements().get(pathPosition) instanceof MovementFall)) { // might be midair if (pathPosition == 0 || !(path.movements().get(pathPosition - 1) instanceof MovementFall)) { // might have overshot the landing - displayChatMessageRaw("too far from path"); + logDebug("too far from path"); pathPosition = path.length() + 3; Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); failed = true; @@ -211,7 +211,7 @@ public class PathExecutor implements Helper { } long end = System.nanoTime() / 1000000L; if (end - start > 0) { - //displayChatMessageRaw("Recalculating break and place took " + (end - start) + "ms"); + //logDebug("Recalculating break and place took " + (end - start) + "ms"); } Movement movement = path.movements().get(pathPosition); if (costEstimateIndex == null || costEstimateIndex != pathPosition) { @@ -220,7 +220,7 @@ public class PathExecutor implements Helper { currentMovementInitialCostEstimate = movement.getCost(null); for (int i = 1; i < Baritone.settings().costVerificationLookahead.get() && pathPosition + i < path.length() - 1; i++) { if (path.movements().get(pathPosition + i).calculateCostWithoutCaching() >= ActionCosts.COST_INF) { - displayChatMessageRaw("Something has changed in the world and a future movement has become impossible. Cancelling."); + logDebug("Something has changed in the world and a future movement has become impossible. Cancelling."); pathPosition = path.length() + 3; failed = true; Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); @@ -230,7 +230,7 @@ public class PathExecutor implements Helper { } double currentCost = movement.recalculateCost(); if (currentCost >= ActionCosts.COST_INF) { - displayChatMessageRaw("Something has changed in the world and this movement has become impossible. Cancelling."); + logDebug("Something has changed in the world and this movement has become impossible. Cancelling."); pathPosition = path.length() + 3; failed = true; Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); @@ -238,7 +238,7 @@ public class PathExecutor implements Helper { } MovementState.MovementStatus movementStatus = movement.update(); if (movementStatus == UNREACHABLE || movementStatus == FAILED) { - displayChatMessageRaw("Movement returns status " + movementStatus); + logDebug("Movement returns status " + movementStatus); pathPosition = path.length() + 3; failed = true; Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); @@ -259,7 +259,7 @@ public class PathExecutor implements Helper { // as you break the blocks required, the remaining cost goes down, to the point where // ticksOnCurrent is greater than recalculateCost + 100 // this is why we cache cost at the beginning, and don't recalculate for this comparison every tick - displayChatMessageRaw("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + currentMovementInitialCostEstimate + "). Cancelling."); + logDebug("This movement has taken too long (" + ticksOnCurrent + " ticks, expected " + currentMovementInitialCostEstimate + "). Cancelling."); movement.cancel(); Baritone.INSTANCE.getInputOverrideHandler().clearAllKeys(); pathPosition = path.length() + 3; @@ -318,7 +318,7 @@ public class PathExecutor implements Helper { } return; } - //displayChatMessageRaw("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection())); + //logDebug("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection())); } player().setSprinting(false); } diff --git a/src/main/java/baritone/utils/ExampleBaritoneControl.java b/src/main/java/baritone/utils/ExampleBaritoneControl.java index b12db109..6a301a6c 100644 --- a/src/main/java/baritone/utils/ExampleBaritoneControl.java +++ b/src/main/java/baritone/utils/ExampleBaritoneControl.java @@ -92,26 +92,26 @@ public class ExampleBaritoneControl extends Behavior { goal = new GoalBlock(new BlockPos(Integer.parseInt(params[0]), Integer.parseInt(params[1]), Integer.parseInt(params[2]))); break; default: - displayChatMessageRaw("unable to understand lol"); + logDirect("unable to understand lol"); return; } } catch (NumberFormatException ex) { - displayChatMessageRaw("unable to parse integer " + ex); + logDirect("unable to parse integer " + ex); return; } PathingBehavior.INSTANCE.setGoal(goal); - displayChatMessageRaw("Goal: " + goal); + logDirect("Goal: " + goal); return; } if (msg.equals("path")) { if (!PathingBehavior.INSTANCE.path()) { if (PathingBehavior.INSTANCE.getGoal() == null) { - displayChatMessageRaw("No goal."); + logDirect("No goal."); } else { if (PathingBehavior.INSTANCE.getGoal().isInGoal(playerFeet())) { - displayChatMessageRaw("Already in goal"); + logDirect("Already in goal"); } else { - displayChatMessageRaw("Currently executing a path. Please cancel it first."); + logDirect("Currently executing a path. Please cancel it first."); } } } @@ -123,13 +123,13 @@ public class ExampleBaritoneControl extends Behavior { FollowBehavior.INSTANCE.cancel(); MineBehavior.INSTANCE.cancel(); event.cancel(); - displayChatMessageRaw("ok canceled"); + logDirect("ok canceled"); return; } if (msg.toLowerCase().equals("forcecancel")) { AbstractNodeCostSearch.forceCancel(); event.cancel(); - displayChatMessageRaw("ok force canceled"); + logDirect("ok force canceled"); return; } if (msg.toLowerCase().equals("invert")) { @@ -140,8 +140,8 @@ public class ExampleBaritoneControl extends Behavior { } else if (goal instanceof GoalBlock) { runAwayFrom = ((GoalBlock) goal).getGoalPos(); } else { - displayChatMessageRaw("Goal must be GoalXZ or GoalBlock to invert"); - displayChatMessageRaw("Inverting goal of player feet"); + logDirect("Goal must be GoalXZ or GoalBlock to invert"); + logDirect("Inverting goal of player feet"); runAwayFrom = playerFeet(); } PathingBehavior.INSTANCE.setGoal(new GoalRunAway(1, runAwayFrom) { @@ -151,7 +151,7 @@ public class ExampleBaritoneControl extends Behavior { } }); if (!PathingBehavior.INSTANCE.path()) { - displayChatMessageRaw("Currently executing a path. Please cancel it first."); + logDirect("Currently executing a path. Please cancel it first."); } event.cancel(); return; @@ -159,31 +159,31 @@ public class ExampleBaritoneControl extends Behavior { if (msg.toLowerCase().equals("follow")) { Optional entity = MovementHelper.whatEntityAmILookingAt(); if (!entity.isPresent()) { - displayChatMessageRaw("You aren't looking at an entity bruh"); + logDirect("You aren't looking at an entity bruh"); event.cancel(); return; } FollowBehavior.INSTANCE.follow(entity.get()); - displayChatMessageRaw("Following " + entity.get()); + logDirect("Following " + entity.get()); event.cancel(); return; } if (msg.toLowerCase().equals("reloadall")) { WorldProvider.INSTANCE.getCurrentWorld().cache.reloadAllFromDisk(); - displayChatMessageRaw("ok"); + logDirect("ok"); event.cancel(); return; } if (msg.toLowerCase().equals("saveall")) { WorldProvider.INSTANCE.getCurrentWorld().cache.save(); - displayChatMessageRaw("ok"); + logDirect("ok"); event.cancel(); return; } if (msg.toLowerCase().startsWith("find")) { String blockType = msg.toLowerCase().substring(4).trim(); LinkedList locs = WorldProvider.INSTANCE.getCurrentWorld().cache.getLocationsOf(blockType, 1, 4); - displayChatMessageRaw("Have " + locs.size() + " locations"); + logDirect("Have " + locs.size() + " locations"); for (BlockPos pos : locs) { Block actually = BlockStateInterface.get(pos).getBlock(); if (!ChunkPacker.blockToString(actually).equalsIgnoreCase(blockType)) { @@ -197,20 +197,20 @@ public class ExampleBaritoneControl extends Behavior { String[] blockTypes = msg.toLowerCase().substring(4).trim().split(" "); for (String s : blockTypes) { if (ChunkPacker.stringToBlock(s) == null) { - displayChatMessageRaw(s + " isn't a valid block name"); + logDirect(s + " isn't a valid block name"); event.cancel(); return; } } MineBehavior.INSTANCE.mine(blockTypes); - displayChatMessageRaw("Started mining blocks of type " + Arrays.toString(blockTypes)); + logDirect("Started mining blocks of type " + Arrays.toString(blockTypes)); event.cancel(); return; } if (msg.toLowerCase().startsWith("thisway")) { Goal goal = GoalXZ.fromDirection(playerFeetAsVec(), player().rotationYaw, Double.parseDouble(msg.substring(7).trim())); PathingBehavior.INSTANCE.setGoal(goal); - displayChatMessageRaw("Goal: " + goal); + logDirect("Goal: " + goal); event.cancel(); return; } @@ -222,7 +222,7 @@ public class ExampleBaritoneControl extends Behavior { } Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType); if (tag == null) { - displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); + logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); event.cancel(); return; } @@ -230,9 +230,9 @@ public class ExampleBaritoneControl extends Behavior { // might as well show them from oldest to newest List sorted = new ArrayList<>(waypoints); sorted.sort(Comparator.comparingLong(Waypoint::creationTimestamp)); - displayChatMessageRaw("Waypoints under tag " + tag + ":"); + logDirect("Waypoints under tag " + tag + ":"); for (Waypoint waypoint : sorted) { - displayChatMessageRaw(waypoint.toString()); + logDirect(waypoint.toString()); } event.cancel(); return; @@ -246,15 +246,15 @@ public class ExampleBaritoneControl extends Behavior { Waypoint.Tag tag = Waypoint.Tag.fromString(waypointType); if (tag == null) { String mining = waypointType; - //displayChatMessageRaw("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); + //logDirect("Not a valid tag. Tags are: " + Arrays.asList(Waypoint.Tag.values()).toString().toLowerCase()); event.cancel(); if (ChunkPacker.stringToBlock(mining) == null) { - displayChatMessageRaw("No locations for " + mining + " known, cancelling"); + logDirect("No locations for " + mining + " known, cancelling"); return; } List locs = MineBehavior.scanFor(Arrays.asList(mining), 64); if (locs.isEmpty()) { - displayChatMessageRaw("No locations for " + mining + " known, cancelling"); + logDirect("No locations for " + mining + " known, cancelling"); return; } PathingBehavior.INSTANCE.setGoal(new GoalComposite(locs.stream().map(GoalGetToBlock::new).toArray(Goal[]::new))); @@ -263,7 +263,7 @@ public class ExampleBaritoneControl extends Behavior { } Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(tag); if (waypoint == null) { - displayChatMessageRaw("None saved for tag " + tag); + logDirect("None saved for tag " + tag); event.cancel(); return; } @@ -271,7 +271,7 @@ public class ExampleBaritoneControl extends Behavior { PathingBehavior.INSTANCE.setGoal(goal); if (!PathingBehavior.INSTANCE.path()) { if (!goal.isInGoal(playerFeet())) { - displayChatMessageRaw("Currently executing a path. Please cancel it first."); + logDirect("Currently executing a path. Please cancel it first."); } } event.cancel(); @@ -283,30 +283,30 @@ public class ExampleBaritoneControl extends Behavior { BlockPos spawnPoint = player().getBedLocation(); // for some reason the default spawnpoint is underground sometimes Goal goal = new GoalXZ(spawnPoint.getX(), spawnPoint.getZ()); - displayChatMessageRaw("spawn not saved, defaulting to world spawn. set goal to " + goal); + logDirect("spawn not saved, defaulting to world spawn. set goal to " + goal); PathingBehavior.INSTANCE.setGoal(goal); } else { Goal goal = new GoalBlock(waypoint.location); PathingBehavior.INSTANCE.setGoal(goal); - displayChatMessageRaw("Set goal to most recent bed " + goal); + logDirect("Set goal to most recent bed " + goal); } event.cancel(); return; } if (msg.toLowerCase().equals("sethome")) { WorldProvider.INSTANCE.getCurrentWorld().waypoints.addWaypoint(new Waypoint("", Waypoint.Tag.HOME, playerFeet())); - displayChatMessageRaw("Saved. Say home to set goal."); + logDirect("Saved. Say home to set goal."); event.cancel(); return; } if (msg.toLowerCase().equals("home")) { Waypoint waypoint = WorldProvider.INSTANCE.getCurrentWorld().waypoints.getMostRecentByTag(Waypoint.Tag.HOME); if (waypoint == null) { - displayChatMessageRaw("home not saved"); + logDirect("home not saved"); } else { Goal goal = new GoalBlock(waypoint.location); PathingBehavior.INSTANCE.setGoal(goal); - displayChatMessageRaw("Set goal to saved home " + goal); + logDirect("Set goal to saved home " + goal); } event.cancel(); return; @@ -325,7 +325,7 @@ public class ExampleBaritoneControl extends Behavior { if (cost >= ActionCosts.COST_INF) { strCost = "IMPOSSIBLE"; } - displayChatMessageRaw(parts[parts.length - 1] + " " + move.getDest().getX() + "," + move.getDest().getY() + "," + move.getDest().getZ() + " " + strCost); + logDirect(parts[parts.length - 1] + " " + move.getDest().getX() + "," + move.getDest().getY() + "," + move.getDest().getZ() + " " + strCost); } event.cancel(); return; @@ -335,13 +335,13 @@ public class ExampleBaritoneControl extends Behavior { if (msg.equalsIgnoreCase(setting.getName())) { setting.value ^= true; event.cancel(); - displayChatMessageRaw("Toggled " + setting.getName() + " to " + setting.value); + logDirect("Toggled " + setting.getName() + " to " + setting.value); return; } } if (msg.toLowerCase().equals("baritone") || msg.toLowerCase().equals("settings")) { for (Settings.Setting setting : Baritone.settings().allSettings) { - displayChatMessageRaw(setting.toString()); + logDirect(setting.toString()); } event.cancel(); return; @@ -362,11 +362,11 @@ public class ExampleBaritoneControl extends Behavior { setting.value = Double.parseDouble(data[1]); } } catch (NumberFormatException e) { - displayChatMessageRaw("Unable to parse " + data[1]); + logDirect("Unable to parse " + data[1]); event.cancel(); return; } - displayChatMessageRaw(setting.toString()); + logDirect(setting.toString()); event.cancel(); return; } @@ -374,7 +374,7 @@ public class ExampleBaritoneControl extends Behavior { } if (Baritone.settings().byLowerName.containsKey(msg.toLowerCase())) { Settings.Setting setting = Baritone.settings().byLowerName.get(msg.toLowerCase()); - displayChatMessageRaw(setting.toString()); + logDirect(setting.toString()); event.cancel(); return; } diff --git a/src/main/java/baritone/utils/Helper.java b/src/main/java/baritone/utils/Helper.java index 30e1f398..9bcf082d 100755 --- a/src/main/java/baritone/utils/Helper.java +++ b/src/main/java/baritone/utils/Helper.java @@ -73,15 +73,24 @@ public interface Helper { return new Rotation(player().rotationYaw, player().rotationPitch); } - default void displayChatMessageRaw(String message) { + /** + * Send a message to chat only if chatDebug is on + * @param message + */ + default void logDebug(String message) { if (!Baritone.settings().chatDebug.get()) { System.out.println("Suppressed debug message:"); System.out.println(message); - /*if (!Stream.of(Thread.currentThread().getStackTrace()).map(StackTraceElement::getClassName).anyMatch(x -> x.equals(ExampleBaritoneControl.class.getName()))) { - return; - }*/ + return; } + logDirect(message); + } + /** + * Send a message to chat regardless of chatDebug (should only be used for critically important messages, or as a direct response to a chat command) + * @param message + */ + default void logDirect(String message) { ITextComponent component = MESSAGE_PREFIX.createCopy(); component.getStyle().setColor(TextFormatting.GRAY); component.appendSibling(new TextComponentString(" " + message));