diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 6ff01352..316d6e47 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -616,6 +616,16 @@ public final class Settings { */ public final Setting echoCommands = new Setting<>(true); + /** + * Censor coordinates in goals and block positions + */ + public final Setting censorCoordinates = new Setting<>(false); + + /** + * Censor arguments to ran commands, to hide, for example, coordinates to #goal + */ + public final Setting censorRanCommands = new Setting<>(false); + /** * Don't stop walking forward when you need to break blocks in your way */ diff --git a/src/api/java/baritone/api/cache/Waypoint.java b/src/api/java/baritone/api/cache/Waypoint.java index ac57ea34..720e835e 100644 --- a/src/api/java/baritone/api/cache/Waypoint.java +++ b/src/api/java/baritone/api/cache/Waypoint.java @@ -17,6 +17,7 @@ package baritone.api.cache; +import baritone.api.utils.BetterBlockPos; import net.minecraft.util.math.BlockPos; import java.util.Date; @@ -80,7 +81,12 @@ public class Waypoint implements IWaypoint { @Override public String toString() { - return name + " " + location.toString() + " " + new Date(creationTimestamp).toString(); + return String.format( + "%s %s %s", + name, + BetterBlockPos.from(location).toString(), + new Date(creationTimestamp).toString() + ); } @Override diff --git a/src/api/java/baritone/api/pathing/goals/GoalBlock.java b/src/api/java/baritone/api/pathing/goals/GoalBlock.java index 89dd6304..55385f46 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalBlock.java +++ b/src/api/java/baritone/api/pathing/goals/GoalBlock.java @@ -17,6 +17,7 @@ package baritone.api.pathing.goals; +import baritone.api.utils.SettingsUtil; import baritone.api.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; @@ -67,7 +68,12 @@ public class GoalBlock implements Goal, IGoalRenderPos { @Override public String toString() { - return "GoalBlock{x=" + x + ",y=" + y + ",z=" + z + "}"; + return String.format( + "GoalBlock{x=%s,y=%s,z=%s}", + SettingsUtil.possiblyCensorCoordinate(x), + SettingsUtil.possiblyCensorCoordinate(y), + SettingsUtil.possiblyCensorCoordinate(z) + ); } /** diff --git a/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java b/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java index fb2a07aa..6bf4d026 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java +++ b/src/api/java/baritone/api/pathing/goals/GoalGetToBlock.java @@ -17,6 +17,7 @@ package baritone.api.pathing.goals; +import baritone.api.utils.SettingsUtil; import baritone.api.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; @@ -61,6 +62,11 @@ public class GoalGetToBlock implements Goal, IGoalRenderPos { @Override public String toString() { - return "GoalGetToBlock{x=" + x + ",y=" + y + ",z=" + z + "}"; + return String.format( + "GoalGetToBlock{x=%s,y=%s,z=%s}", + SettingsUtil.possiblyCensorCoordinate(x), + SettingsUtil.possiblyCensorCoordinate(y), + SettingsUtil.possiblyCensorCoordinate(z) + ); } } diff --git a/src/api/java/baritone/api/pathing/goals/GoalNear.java b/src/api/java/baritone/api/pathing/goals/GoalNear.java index 4f75aba7..94a02ba5 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalNear.java +++ b/src/api/java/baritone/api/pathing/goals/GoalNear.java @@ -17,6 +17,7 @@ package baritone.api.pathing.goals; +import baritone.api.utils.SettingsUtil; import baritone.api.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; @@ -56,11 +57,12 @@ public class GoalNear implements Goal, IGoalRenderPos { @Override public String toString() { - return "GoalNear{" + - "x=" + x + - ", y=" + y + - ", z=" + z + - ", rangeSq=" + rangeSq + - "}"; + return String.format( + "GoalNear{x=%s, y=%s, z=%s, rangeSq=%d}", + SettingsUtil.possiblyCensorCoordinate(x), + SettingsUtil.possiblyCensorCoordinate(y), + SettingsUtil.possiblyCensorCoordinate(z), + rangeSq + ); } } diff --git a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java index 3f4a02de..85e294a3 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalRunAway.java +++ b/src/api/java/baritone/api/pathing/goals/GoalRunAway.java @@ -17,6 +17,7 @@ package baritone.api.pathing.goals; +import baritone.api.utils.SettingsUtil; import net.minecraft.util.math.BlockPos; import java.util.Arrays; @@ -82,7 +83,11 @@ public class GoalRunAway implements Goal { @Override public String toString() { if (maintainY != null) { - return "GoalRunAwayFromMaintainY y=" + maintainY + ", " + Arrays.asList(from); + return String.format( + "GoalRunAwayFromMaintainY y=%s, %s", + SettingsUtil.possiblyCensorCoordinate(maintainY), + Arrays.asList(from) + ); } else { return "GoalRunAwayFrom" + Arrays.asList(from); } diff --git a/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java b/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java index 24ae385a..167a00a6 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java +++ b/src/api/java/baritone/api/pathing/goals/GoalStrictDirection.java @@ -17,6 +17,7 @@ package baritone.api.pathing.goals; +import baritone.api.utils.SettingsUtil; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; @@ -64,12 +65,13 @@ public class GoalStrictDirection implements Goal { @Override public String toString() { - return "GoalStrictDirection{" + - "x=" + x + - ", y=" + y + - ", z=" + z + - ", dx=" + dx + - ", dz=" + dz + - "}"; + return String.format( + "GoalStrictDirection{x=%s, y=%s, z=%s, dx=%s, dz=%s}", + SettingsUtil.possiblyCensorCoordinate(x), + SettingsUtil.possiblyCensorCoordinate(y), + SettingsUtil.possiblyCensorCoordinate(z), + SettingsUtil.possiblyCensorCoordinate(dx), + SettingsUtil.possiblyCensorCoordinate(dz) + ); } } diff --git a/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java b/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java index f1026ab5..d0b51e17 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java +++ b/src/api/java/baritone/api/pathing/goals/GoalTwoBlocks.java @@ -17,6 +17,7 @@ package baritone.api.pathing.goals; +import baritone.api.utils.SettingsUtil; import baritone.api.utils.interfaces.IGoalRenderPos; import net.minecraft.util.math.BlockPos; @@ -73,6 +74,11 @@ public class GoalTwoBlocks implements Goal, IGoalRenderPos { @Override public String toString() { - return "GoalTwoBlocks{x=" + x + ",y=" + y + ",z=" + z + "}"; + return String.format( + "GoalTwoBlocks{x=%s,y=%s,z=%s}", + SettingsUtil.possiblyCensorCoordinate(x), + SettingsUtil.possiblyCensorCoordinate(y), + SettingsUtil.possiblyCensorCoordinate(z) + ); } } diff --git a/src/api/java/baritone/api/pathing/goals/GoalXZ.java b/src/api/java/baritone/api/pathing/goals/GoalXZ.java index 86511b54..aeb301b0 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalXZ.java +++ b/src/api/java/baritone/api/pathing/goals/GoalXZ.java @@ -19,6 +19,7 @@ package baritone.api.pathing.goals; import baritone.api.BaritoneAPI; import baritone.api.utils.BetterBlockPos; +import baritone.api.utils.SettingsUtil; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; @@ -65,7 +66,11 @@ public class GoalXZ implements Goal { @Override public String toString() { - return "GoalXZ{x=" + x + ",z=" + z + "}"; + return String.format( + "GoalXZ{x=%s,z=%s}", + SettingsUtil.possiblyCensorCoordinate(x), + SettingsUtil.possiblyCensorCoordinate(z) + ); } public static double calculate(double xDiff, double zDiff) { diff --git a/src/api/java/baritone/api/pathing/goals/GoalYLevel.java b/src/api/java/baritone/api/pathing/goals/GoalYLevel.java index 9add7176..fed62c74 100644 --- a/src/api/java/baritone/api/pathing/goals/GoalYLevel.java +++ b/src/api/java/baritone/api/pathing/goals/GoalYLevel.java @@ -18,6 +18,7 @@ package baritone.api.pathing.goals; import baritone.api.pathing.movement.ActionCosts; +import baritone.api.utils.SettingsUtil; /** * Useful for mining (getting to diamond / iron level) @@ -59,6 +60,9 @@ public class GoalYLevel implements Goal, ActionCosts { @Override public String toString() { - return "GoalYLevel{y=" + level + "}"; + return String.format( + "GoalYLevel{y=%s}", + SettingsUtil.possiblyCensorCoordinate(level) + ); } } diff --git a/src/api/java/baritone/api/utils/BetterBlockPos.java b/src/api/java/baritone/api/utils/BetterBlockPos.java index 3b94a833..b0f536e5 100644 --- a/src/api/java/baritone/api/utils/BetterBlockPos.java +++ b/src/api/java/baritone/api/utils/BetterBlockPos.java @@ -22,6 +22,8 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3i; +import javax.annotation.Nonnull; + /** * A better BlockPos that has fewer hash collisions (and slightly more performant offsets) *

@@ -51,6 +53,20 @@ public final class BetterBlockPos extends BlockPos { this(pos.getX(), pos.getY(), pos.getZ()); } + /** + * Like constructor but returns null if pos is null, good if you just need to possibly censor coordinates + * + * @param pos The BlockPos, possibly null, to convert + * @return A BetterBlockPos or null if pos was null + */ + public static BetterBlockPos from(BlockPos pos) { + if (pos == null) { + return null; + } + + return new BetterBlockPos(pos); + } + @Override public int hashCode() { return (int) longHash(x, y, z); @@ -182,4 +198,15 @@ public final class BetterBlockPos extends BlockPos { public BetterBlockPos west(int amt) { return amt == 0 ? this : new BetterBlockPos(x - amt, y, z); } + + @Override + @Nonnull + public String toString() { + return String.format( + "BetterBlockPos{x=%s,y=%s,z=%s}", + SettingsUtil.possiblyCensorCoordinate(x), + SettingsUtil.possiblyCensorCoordinate(y), + SettingsUtil.possiblyCensorCoordinate(z) + ); + } } diff --git a/src/api/java/baritone/api/utils/ExampleBaritoneControlOld.java b/src/api/java/baritone/api/utils/ExampleBaritoneControlOld.java index e37dea19..56f6976b 100644 --- a/src/api/java/baritone/api/utils/ExampleBaritoneControlOld.java +++ b/src/api/java/baritone/api/utils/ExampleBaritoneControlOld.java @@ -386,7 +386,7 @@ public class ExampleBaritoneControlOld implements Helper, AbstractGameEventListe } if (msg.equals("chests")) { for (Map.Entry entry : baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet()) { - logDirect(entry.getKey() + ""); + logDirect(BetterBlockPos.from(entry.getKey()) + ""); log(entry.getValue().getContents()); } return true; diff --git a/src/api/java/baritone/api/utils/SettingsUtil.java b/src/api/java/baritone/api/utils/SettingsUtil.java index 17387aa0..3a2f4f1f 100644 --- a/src/api/java/baritone/api/utils/SettingsUtil.java +++ b/src/api/java/baritone/api/utils/SettingsUtil.java @@ -17,6 +17,7 @@ package baritone.api.utils; +import baritone.api.BaritoneAPI; import baritone.api.Settings; import net.minecraft.block.Block; import net.minecraft.item.Item; @@ -145,6 +146,14 @@ public class SettingsUtil { return settingValueToString(setting, setting.defaultValue); } + public static String possiblyCensorCoordinate(int coord) { + if (BaritoneAPI.getSettings().censorCoordinates.value) { + return ""; + } + + return Integer.toString(coord); + } + public static String settingToString(Settings.Setting setting) throws IllegalStateException { if (setting.getName().equals("logger")) { return "logger"; diff --git a/src/api/java/baritone/api/utils/command/BaritoneChatControl.java b/src/api/java/baritone/api/utils/command/BaritoneChatControl.java index be390e2a..a06887b2 100644 --- a/src/api/java/baritone/api/utils/command/BaritoneChatControl.java +++ b/src/api/java/baritone/api/utils/command/BaritoneChatControl.java @@ -88,9 +88,11 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener { } } - private void logRanCommand(String msg) { + private void logRanCommand(String command, String rest) { if (settings.echoCommands.value) { - logDirect(new TextComponentString(String.format("> %s", msg)) {{ + String msg = command + rest; + String toDisplay = settings.censorRanCommands.value ? command + " ..." : msg; + logDirect(new TextComponentString(String.format("> %s", toDisplay)) {{ getStyle() .setColor(TextFormatting.WHITE) .setHoverEvent(new HoverEvent( @@ -122,6 +124,8 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener { } Pair> pair = CommandExecution.expand(msg); + String command = pair.first(); + String rest = msg.substring(pair.first().length()); ArgConsumer argc = new ArgConsumer(pair.second()); if (!argc.has()) { @@ -130,8 +134,8 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener { continue; } - if (setting.getName().equalsIgnoreCase(pair.first())) { - logRanCommand(msg); + if (setting.getName().equalsIgnoreCase(command)) { + logRanCommand(command, rest); if (setting.getValueClass() == Boolean.class) { CommandManager.execute(String.format("set toggle %s", setting.getName())); @@ -149,7 +153,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener { } if (setting.getName().equalsIgnoreCase(pair.first())) { - logRanCommand(msg); + logRanCommand(command, rest); CommandManager.execute(String.format("set %s %s", setting.getName(), argc.getString())); return true; } @@ -162,7 +166,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener { return false; } - logRanCommand(msg); + logRanCommand(command, rest); CommandManager.execute(execution); return true; diff --git a/src/api/java/baritone/api/utils/command/defaults/ChestsCommand.java b/src/api/java/baritone/api/utils/command/defaults/ChestsCommand.java index 300cf974..a9ca11fb 100644 --- a/src/api/java/baritone/api/utils/command/defaults/ChestsCommand.java +++ b/src/api/java/baritone/api/utils/command/defaults/ChestsCommand.java @@ -19,6 +19,7 @@ package baritone.api.utils.command.defaults; import baritone.api.Settings; import baritone.api.cache.IRememberedInventory; +import baritone.api.utils.BetterBlockPos; import baritone.api.utils.command.Command; import baritone.api.utils.command.exception.CommandInvalidStateException; import baritone.api.utils.command.helpers.arguments.ArgConsumer; @@ -49,7 +50,8 @@ public class ChestsCommand extends Command { } for (Map.Entry entry : entries) { - BlockPos pos = entry.getKey(); + // betterblockpos has censoring + BetterBlockPos pos = new BetterBlockPos(entry.getKey()); IRememberedInventory inv = entry.getValue(); logDirect(pos.toString()); diff --git a/src/main/java/baritone/behavior/MemoryBehavior.java b/src/main/java/baritone/behavior/MemoryBehavior.java index d98e3237..5caee6a3 100644 --- a/src/main/java/baritone/behavior/MemoryBehavior.java +++ b/src/main/java/baritone/behavior/MemoryBehavior.java @@ -24,6 +24,7 @@ import baritone.api.event.events.PacketEvent; import baritone.api.event.events.PlayerUpdateEvent; import baritone.api.event.events.TickEvent; import baritone.api.event.events.type.EventState; +import baritone.api.utils.BetterBlockPos; import baritone.cache.ContainerMemory; import baritone.utils.BlockStateInterface; import net.minecraft.block.Block; @@ -99,8 +100,8 @@ public final class MemoryBehavior extends Behavior { TileEntityLockable lockable = (TileEntityLockable) tileEntity; int size = lockable.getSizeInventory(); - BlockPos position = tileEntity.getPos(); - BlockPos adj = neighboringConnectedBlock(position); + BetterBlockPos position = BetterBlockPos.from(tileEntity.getPos()); + BetterBlockPos adj = BetterBlockPos.from(neighboringConnectedBlock(position)); System.out.println(position + " " + adj); if (adj != null) { size *= 2; // double chest or double trapped chest @@ -239,7 +240,8 @@ public final class MemoryBehavior extends Behavior { this.slots = slots; this.type = type; this.pos = pos; - System.out.println("Future inventory created " + time + " " + slots + " " + type + " " + pos); + // betterblockpos has censoring + System.out.println("Future inventory created " + time + " " + slots + " " + type + " " + BetterBlockPos.from(pos)); } }