Coordinate censoring

This commit is contained in:
Logan Darklock 2019-09-01 09:47:27 -07:00
parent e7412d0d46
commit ef38051826
14 changed files with 109 additions and 24 deletions

View File

@ -596,6 +596,11 @@ public final class Settings {
*/
public final Setting<Boolean> prefixControl = new Setting<>(true);
/**
* Censor coordinates in goals and block positions
*/
public final Setting<Boolean> censorCoordinates = 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

@ -18,6 +18,7 @@
package baritone.api.pathing.goals;
import baritone.api.BaritoneAPI;
import baritone.api.utils.SettingsUtil;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
@ -59,7 +60,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

@ -372,7 +372,7 @@ public class ExampleBaritoneControl implements Helper, AbstractGameEventListener
}
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;
@ -120,6 +121,14 @@ public class SettingsUtil {
return modified;
}
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

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