Coordinate censoring

This commit is contained in:
Logan Darklock 2019-09-01 09:47:27 -07:00
parent 44ec969203
commit 445037b614
No known key found for this signature in database
GPG Key ID: B8C37CEDE1AC60EA
16 changed files with 127 additions and 31 deletions

View File

@ -616,6 +616,16 @@ public final class Settings {
*/
public final Setting<Boolean> echoCommands = new Setting<>(true);
/**
* Censor coordinates in goals and block positions
*/
public final Setting<Boolean> censorCoordinates = new Setting<>(false);
/**
* Censor arguments to ran commands, to hide, for example, coordinates to #goal
*/
public final Setting<Boolean> censorRanCommands = new Setting<>(false);
/**
* Don't stop walking forward when you need to break blocks in your way
*/

View File

@ -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

View File

@ -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)
);
}
/**

View File

@ -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)
);
}
}

View File

@ -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
);
}
}

View File

@ -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);
}

View File

@ -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)
);
}
}

View File

@ -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)
);
}
}

View File

@ -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) {

View File

@ -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)
);
}
}

View File

@ -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)
* <p>
@ -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)
);
}
}

View File

@ -386,7 +386,7 @@ public class ExampleBaritoneControlOld implements Helper, AbstractGameEventListe
}
if (msg.equals("chests")) {
for (Map.Entry<BlockPos, IRememberedInventory> entry : baritone.getWorldProvider().getCurrentWorld().getContainerMemory().getRememberedInventories().entrySet()) {
logDirect(entry.getKey() + "");
logDirect(BetterBlockPos.from(entry.getKey()) + "");
log(entry.getValue().getContents());
}
return true;

View File

@ -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 "<censored>";
}
return Integer.toString(coord);
}
public static String settingToString(Settings.Setting setting) throws IllegalStateException {
if (setting.getName().equals("logger")) {
return "logger";

View File

@ -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<String, List<CommandArgument>> 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;

View File

@ -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<BlockPos, IRememberedInventory> entry : entries) {
BlockPos pos = entry.getKey();
// betterblockpos has censoring
BetterBlockPos pos = new BetterBlockPos(entry.getKey());
IRememberedInventory inv = entry.getValue();
logDirect(pos.toString());

View File

@ -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));
}
}