its too many blank lines

This commit is contained in:
Leijurv
2019-09-19 13:43:40 -07:00
parent 0a38e6f690
commit 61d4f102ba
75 changed files with 55 additions and 316 deletions

View File

@@ -27,6 +27,7 @@ import baritone.pathing.calc.PathNode;
* @author leijurv
*/
class LinkedListOpenSet implements IOpenSet {
private Node first = null;
@Override
@@ -83,6 +84,7 @@ class LinkedListOpenSet implements IOpenSet {
}
public static class Node { //wrapper with next
private Node nextOpen;
private PathNode val;
}

View File

@@ -39,11 +39,9 @@ public class BlacklistCommand extends Command {
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
IGetToBlockProcess proc = baritone.getGetToBlockProcess();
if (!proc.isActive()) {
throw new CommandInvalidStateException("GetToBlockProcess is not currently active");
}
if (proc.blacklistClosest()) {
logDirect("Blacklisted closest instances");
} else {

View File

@@ -45,14 +45,11 @@ public class BuildCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
File file = args.getDatatypePost(RelativeFile.class, schematicsDir).getAbsoluteFile();
if (!file.getName().toLowerCase(Locale.US).endsWith(".schematic")) {
file = new File(file.getAbsolutePath() + ".schematic");
}
BetterBlockPos origin = ctx.playerFeet();
BetterBlockPos buildOrigin;
if (args.has()) {
args.requireMax(3);
buildOrigin = args.getDatatype(RelativeBlockPos.class).apply(origin);
@@ -60,13 +57,10 @@ public class BuildCommand extends Command {
args.requireMax(0);
buildOrigin = origin;
}
boolean success = baritone.getBuilderProcess().build(file.getName(), file, buildOrigin);
if (!success) {
throw new CommandInvalidStateException("Couldn't load the schematic");
}
logDirect(String.format("Successfully loaded schematic for building\nOrigin: %s", buildOrigin));
}
@@ -76,10 +70,8 @@ public class BuildCommand extends Command {
return RelativeFile.tabComplete(args, schematicsDir);
} else if (args.has(2)) {
args.get();
return args.tabCompleteDatatype(RelativeBlockPos.class);
}
return Stream.empty();
}

View File

@@ -46,18 +46,14 @@ public class ChestsCommand extends Command {
args.requireMax(0);
Set<Map.Entry<BlockPos, IRememberedInventory>> entries =
ctx.worldData().getContainerMemory().getRememberedInventories().entrySet();
if (entries.isEmpty()) {
throw new CommandInvalidStateException("No remembered inventories");
}
for (Map.Entry<BlockPos, IRememberedInventory> entry : entries) {
// betterblockpos has censoring
BetterBlockPos pos = new BetterBlockPos(entry.getKey());
IRememberedInventory inv = entry.getValue();
logDirect(pos.toString());
for (ItemStack item : inv.getContents()) {
ITextComponent component = item.getTextComponent();
component.appendText(String.format(" x %d", item.getCount()));

View File

@@ -42,22 +42,18 @@ public class ClearareaCommand extends Command {
protected void executed(String label, ArgConsumer args, Settings settings) {
BetterBlockPos pos1 = ctx.playerFeet();
BetterBlockPos pos2;
if (args.has()) {
args.requireMax(3);
pos2 = args.getDatatype(RelativeBlockPos.class).apply(pos1);
} else {
args.requireMax(0);
Goal goal = baritone.getCustomGoalProcess().getGoal();
if (!(goal instanceof GoalBlock)) {
throw new CommandInvalidStateException("Goal is not a GoalBlock");
} else {
pos2 = new BetterBlockPos(((GoalBlock) goal).getGoalPos());
}
}
baritone.getBuilderProcess().clearArea(pos1, pos2);
logDirect("Success");
}

View File

@@ -42,11 +42,9 @@ public class ComeCommand extends Command {
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
Entity entity = MC.getRenderViewEntity();
if (isNull(entity)) {
throw new CommandInvalidStateException("render view entity is null");
}
baritone.getCustomGoalProcess().setGoalAndPath(new GoalBlock(new BlockPos(entity)));
logDirect("Coming");
}

View File

@@ -48,7 +48,6 @@ public class DefaultCommands {
new GcCommand(baritone),
new InvertCommand(baritone),
new ClearareaCommand(baritone),
new TunnelCommand(baritone),
new RenderCommand(baritone),
new FarmCommand(baritone),

View File

@@ -42,11 +42,9 @@ public class ExploreCommand extends Command {
} else {
args.requireMax(0);
}
GoalXZ goal = args.has()
? args.getDatatypePost(RelativeGoalXZ.class, ctx.playerFeet())
: new GoalXZ(ctx.playerFeet());
baritone.getExploreProcess().explore(goal.getX(), goal.getZ());
logDirect(String.format("Exploring from %s", goal.toString()));
}
@@ -56,7 +54,6 @@ public class ExploreCommand extends Command {
if (args.hasAtMost(2)) {
return args.tabCompleteDatatype(RelativeGoalXZ.class);
}
return Stream.empty();
}

View File

@@ -34,6 +34,7 @@ import java.util.stream.Stream;
import static java.util.Arrays.asList;
public class ExploreFilterCommand extends Command {
public ExploreFilterCommand(IBaritone baritone) {
super(baritone, "explorefilter");
}
@@ -43,7 +44,6 @@ public class ExploreFilterCommand extends Command {
args.requireMax(2);
File file = args.getDatatypePost(RelativeFile.class, MC.gameDir.getAbsoluteFile().getParentFile());
boolean invert = false;
if (args.has()) {
if (args.getString().equalsIgnoreCase("invert")) {
invert = true;
@@ -51,7 +51,6 @@ public class ExploreFilterCommand extends Command {
throw new CommandInvalidTypeException(args.consumed(), "either \"invert\" or nothing");
}
}
try {
baritone.getExploreProcess().applyJsonFilter(file.toPath().toAbsolutePath(), invert);
} catch (NoSuchFileException e) {
@@ -61,7 +60,6 @@ public class ExploreFilterCommand extends Command {
} catch (Exception e) {
throw new RuntimeException(e);
}
logDirect(String.format("Explore filter applied. Inverted: %s", Boolean.toString(invert)));
}
@@ -70,7 +68,6 @@ public class ExploreFilterCommand extends Command {
if (args.hasExactlyOne()) {
return RelativeFile.tabComplete(args, RelativeFile.gameDir());
}
return Stream.empty();
}

View File

@@ -40,13 +40,10 @@ public class FindCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
List<Block> toFind = new ArrayList<>();
while (args.has()) {
toFind.add(args.getDatatypeFor(BlockById.class));
}
BetterBlockPos origin = ctx.playerFeet();
toFind.stream()
.flatMap(block ->
ctx.worldData().getCachedWorld().getLocationsOf(

View File

@@ -52,24 +52,19 @@ public class FollowCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMin(1);
FollowGroup group;
FollowList list;
List<Entity> entities = new ArrayList<>();
List<Class<? extends Entity>> classes = new ArrayList<>();
if (args.hasExactlyOne()) {
baritone.getFollowProcess().follow((group = args.getEnum(FollowGroup.class)).filter);
} else {
args.requireMin(2);
group = null;
list = args.getEnum(FollowList.class);
while (args.has()) {
//noinspection unchecked
Object gotten = args.getDatatypeFor(list.datatype);
if (gotten instanceof Class) {
//noinspection unchecked
classes.add((Class<? extends Entity>) gotten);
@@ -77,19 +72,16 @@ public class FollowCommand extends Command {
entities.add((Entity) gotten);
}
}
baritone.getFollowProcess().follow(
classes.isEmpty()
? entities::contains
: e -> classes.stream().anyMatch(c -> c.isInstance(e))
);
}
if (nonNull(group)) {
logDirect(String.format("Following all %s", group.name().toLowerCase(Locale.US)));
} else {
logDirect("Following these types of entities:");
if (classes.isEmpty()) {
entities.stream()
.map(Entity::toString)
@@ -114,21 +106,17 @@ public class FollowCommand extends Command {
.stream();
} else {
Class<? extends IDatatype> followType;
try {
followType = args.getEnum(FollowList.class).datatype;
} catch (NullPointerException e) {
return Stream.empty();
}
while (args.has(2)) {
if (isNull(args.peekDatatypeOrNull(followType))) {
return Stream.empty();
}
args.get();
}
return args.tabCompleteDatatype(followType);
}
}
@@ -156,7 +144,6 @@ public class FollowCommand extends Command {
PLAYERS(EntityPlayer.class::isInstance); /* ,
FRIENDLY(entity -> entity.getAttackTarget() != HELPER.mc.player),
HOSTILE(FRIENDLY.filter.negate()); */
final Predicate<Entity> filter;
FollowGroup(Predicate<Entity> filter) {
@@ -167,7 +154,6 @@ public class FollowCommand extends Command {
private enum FollowList {
ENTITY(EntityClassById.class),
PLAYER(PlayerByUsername.class);
final Class<? extends IDatatypeFor> datatype;
FollowList(Class<? extends IDatatypeFor> datatype) {

View File

@@ -36,9 +36,7 @@ public class GcCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
System.gc();
logDirect("ok called System.gc()");
}

View File

@@ -44,10 +44,8 @@ public class GoalCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
ICustomGoalProcess goalProcess = baritone.getCustomGoalProcess();
if (args.has() && asList("reset", "clear", "none").contains(args.peekString())) {
args.requireMax(1);
if (nonNull(goalProcess.getGoal())) {
goalProcess.setGoal(null);
logDirect("Cleared goal");
@@ -66,7 +64,6 @@ public class GoalCommand extends Command {
@Override
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
TabCompleteHelper helper = new TabCompleteHelper();
if (args.hasExactlyOne()) {
helper.append(Stream.of("reset", "clear", "none", "~"));
} else {
@@ -75,16 +72,13 @@ public class GoalCommand extends Command {
if (isNull(args.peekDatatypeOrNull(RelativeCoordinate.class))) {
break;
}
args.get();
if (!args.has(2)) {
helper.append("~");
}
}
}
}
return helper.filterPrefix(args.getString()).stream();
}

View File

@@ -49,7 +49,6 @@ public class HelpCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(1);
if (!args.has() || args.is(Integer.class)) {
Paginator.paginate(
args, new Paginator<>(
@@ -61,20 +60,16 @@ public class HelpCommand extends Command {
command -> {
String names = String.join("/", command.names);
String name = command.names.get(0);
ITextComponent shortDescComponent = new TextComponentString(" - " + command.getShortDesc());
shortDescComponent.getStyle().setColor(TextFormatting.DARK_GRAY);
ITextComponent namesComponent = new TextComponentString(names);
namesComponent.getStyle().setColor(TextFormatting.WHITE);
ITextComponent hoverComponent = new TextComponentString("");
hoverComponent.getStyle().setColor(TextFormatting.GRAY);
hoverComponent.appendSibling(namesComponent);
hoverComponent.appendText("\n" + command.getShortDesc());
hoverComponent.appendText("\n\nClick to view full help");
String clickCommand = FORCE_COMMAND_PREFIX + String.format("%s %s", label, command.names.get(0));
ITextComponent component = new TextComponentString(name);
component.getStyle().setColor(TextFormatting.GRAY);
component.appendSibling(shortDescComponent);
@@ -88,22 +83,18 @@ public class HelpCommand extends Command {
} else {
String commandName = args.getString().toLowerCase();
Command command = getCommand(commandName);
if (isNull(command)) {
throw new CommandNotFoundException(commandName);
}
logDirect(String.format("%s - %s", String.join(" / ", command.names), command.getShortDesc()));
logDirect("");
command.getLongDesc().forEach(this::logDirect);
logDirect("");
ITextComponent returnComponent = new TextComponentString("Click to return to the help menu");
returnComponent.getStyle().setClickEvent(new ClickEvent(
ClickEvent.Action.RUN_COMMAND,
FORCE_COMMAND_PREFIX + label
));
logDirect(returnComponent);
}
}
@@ -113,7 +104,6 @@ public class HelpCommand extends Command {
if (args.hasExactlyOne()) {
return new TabCompleteHelper().addCommands().filterPrefix(args.getString()).stream();
}
return Stream.empty();
}

View File

@@ -41,20 +41,16 @@ public class InvertCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
Goal goal;
if (isNull(goal = customGoalProcess.getGoal())) {
throw new CommandInvalidStateException("No goal");
}
if (goal instanceof GoalInverted) {
goal = ((GoalInverted) goal).origin;
} else {
goal = new GoalInverted(goal);
}
customGoalProcess.setGoal(goal);
logDirect(String.format("Goal: %s", goal.toString()));
}

View File

@@ -43,11 +43,9 @@ public class MineCommand extends Command {
int quantity = args.getAsOrDefault(Integer.class, 0);
args.requireMin(1);
List<BlockOptionalMeta> boms = new ArrayList<>();
while (args.has()) {
boms.add(args.getDatatypeFor(ForBlockOptionalMeta.class));
}
WorldScanner.INSTANCE.repack(ctx);
baritone.getMineProcess().mine(quantity, boms.toArray(new BlockOptionalMeta[0]));
logDirect(String.format("Mining %s", boms.toString()));

View File

@@ -45,14 +45,12 @@ public class PathCommand extends Command {
protected void executed(String label, ArgConsumer args, Settings settings) {
ICustomGoalProcess customGoalProcess = baritone.getCustomGoalProcess();
Goal goal;
if (args.has()) {
args.requireMax(3);
goal = args.getDatatype(RelativeGoal.class).apply(ctx.playerFeet());
} else if (isNull(goal = customGoalProcess.getGoal())) {
throw new CommandInvalidStateException("No goal");
}
args.requireMax(0);
WorldScanner.INSTANCE.repack(ctx);
customGoalProcess.setGoalAndPath(goal);
@@ -66,9 +64,7 @@ public class PathCommand extends Command {
if (isNull(args.peekDatatypeOrNull(RelativeCoordinate.class))) {
break;
}
args.get();
if (!args.has(2)) {
return new TabCompleteHelper()
.append("~")
@@ -77,7 +73,6 @@ public class PathCommand extends Command {
}
}
}
return Stream.empty();
}

View File

@@ -49,7 +49,6 @@ public class PauseResumeCommands {
this.baritone = baritone;
// array for mutability, non-field so reflection can't touch it
final boolean[] paused = {false};
baritone.getPathingControlManager().registerProcess(
new IBaritoneProcess() {
@Override
@@ -81,16 +80,13 @@ public class PauseResumeCommands {
}
}
);
pauseCommand = new Command(baritone, "pause") {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
if (paused[0]) {
throw new CommandInvalidStateException("Already paused");
}
paused[0] = true;
logDirect("Paused");
}
@@ -117,16 +113,13 @@ public class PauseResumeCommands {
);
}
};
resumeCommand = new Command(baritone, "resume") {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
if (!paused[0]) {
throw new CommandInvalidStateException("Not paused");
}
paused[0] = false;
logDirect("Resumed");
}
@@ -151,12 +144,10 @@ public class PauseResumeCommands {
);
}
};
pausedCommand = new Command(baritone, "paused") {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
logDirect(String.format("Baritone is %spaused", paused[0] ? "" : "not "));
}

View File

@@ -41,14 +41,11 @@ public class ProcCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
IPathingControlManager pathingControlManager = baritone.getPathingControlManager();
IBaritoneProcess process = pathingControlManager.mostRecentInControl().orElse(null);
if (isNull(process)) {
throw new CommandInvalidStateException("No process in control");
}
logDirect(String.format(
"Class: %s\n" +
"Priority: %f\n" +

View File

@@ -37,7 +37,6 @@ public class RenderCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
BetterBlockPos origin = ctx.playerFeet();
int renderDistance = (MC.gameSettings.renderDistanceChunks + 1) * 16;
MC.renderGlobal.markBlockRangeForRenderUpdate(
@@ -48,7 +47,6 @@ public class RenderCommand extends Command {
255,
origin.z + renderDistance
);
logDirect("Done");
}

View File

@@ -66,12 +66,10 @@ public class SelCommand extends Command {
if (!Baritone.settings().renderSelectionCorners.value || pos1 == null) {
return;
}
Color color = Baritone.settings().colorSelectionPos1.value;
float opacity = Baritone.settings().selectionOpacity.value;
float lineWidth = Baritone.settings().selectionLineWidth.value;
boolean ignoreDepth = Baritone.settings().renderSelectionIgnoreDepth.value;
IRenderer.startLines(color, opacity, lineWidth, ignoreDepth);
IRenderer.drawAABB(new AxisAlignedBB(pos1, pos1.add(1, 1, 1)));
IRenderer.endLines(ignoreDepth);
@@ -82,20 +80,16 @@ public class SelCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
Action action = Action.getByName(args.getString());
if (action == null) {
throw new CommandInvalidTypeException(args.consumed(), "an action");
}
if (action == Action.POS1 || action == Action.POS2) {
if (action == Action.POS2 && pos1 == null) {
throw new CommandInvalidStateException("Set pos1 first before using pos2");
}
BetterBlockPos playerPos = ctx.playerFeet();
BetterBlockPos pos = args.has() ? args.getDatatypePost(RelativeBlockPos.class, playerPos) : playerPos;
args.requireMax(0);
if (action == Action.POS1) {
pos1 = pos;
logDirect("Position 1 has been set");
@@ -110,13 +104,11 @@ public class SelCommand extends Command {
logDirect(String.format("Removed %d selections", manager.removeAllSelections().length));
} else if (action == Action.UNDO) {
args.requireMax(0);
if (pos1 != null) {
pos1 = null;
logDirect("Undid pos1");
} else {
ISelection[] selections = manager.getSelections();
if (selections.length < 1) {
throw new CommandInvalidStateException("Nothing to undo!");
} else {
@@ -129,33 +121,24 @@ public class SelCommand extends Command {
? new BlockOptionalMeta(Blocks.AIR)
: args.getDatatypeFor(ForBlockOptionalMeta.class);
BlockOptionalMetaLookup replaces = null;
if (action == Action.REPLACE) {
args.requireMin(1);
List<BlockOptionalMeta> replacesList = new ArrayList<>();
replacesList.add(type);
while (args.has(2)) {
replacesList.add(args.getDatatypeFor(ForBlockOptionalMeta.class));
}
type = args.getDatatypeFor(ForBlockOptionalMeta.class);
replaces = new BlockOptionalMetaLookup(replacesList.toArray(new BlockOptionalMeta[0]));
} else {
args.requireMax(0);
}
ISelection[] selections = manager.getSelections();
if (selections.length == 0) {
throw new CommandInvalidStateException("No selections");
}
BetterBlockPos origin = selections[0].min();
CompositeSchematic composite = new CompositeSchematic(0, 0, 0);
for (ISelection selection : selections) {
BetterBlockPos min = selection.min();
origin = new BetterBlockPos(
@@ -164,13 +147,10 @@ public class SelCommand extends Command {
Math.min(origin.z, min.z)
);
}
for (ISelection selection : selections) {
Vec3i size = selection.size();
BetterBlockPos min = selection.min();
ISchematic schematic = new FillSchematic(size.getX(), size.getY(), size.getZ(), type);
if (action == Action.WALLS) {
schematic = new WallsSchematic(schematic);
} else if (action == Action.SHELL) {
@@ -178,31 +158,23 @@ public class SelCommand extends Command {
} else if (action == Action.REPLACE) {
schematic = new ReplaceSchematic(schematic, replaces);
}
composite.put(schematic, min.x - origin.x, min.y - origin.y, min.z - origin.z);
}
baritone.getBuilderProcess().build("Fill", composite, origin);
logDirect("Filling now");
} else if (action == Action.EXPAND || action == Action.CONTRACT || action == Action.SHIFT) {
args.requireExactly(3);
TransformTarget transformTarget = TransformTarget.getByName(args.getString());
if (transformTarget == null) {
throw new CommandInvalidStateException("Invalid transform type");
}
EnumFacing direction = args.getDatatypeFor(ForEnumFacing.class);
int blocks = args.getAs(Integer.class);
ISelection[] selections = manager.getSelections();
if (selections.length < 1) {
throw new CommandInvalidStateException("No selections found");
}
selections = transformTarget.transform(selections);
for (ISelection selection : selections) {
if (action == Action.EXPAND) {
manager.expand(selection, direction, blocks);
@@ -212,7 +184,6 @@ public class SelCommand extends Command {
manager.shift(selection, direction, blocks);
}
}
logDirect(String.format("Transformed %d selections", selections.length));
}
}
@@ -227,7 +198,6 @@ public class SelCommand extends Command {
.stream();
} else {
Action action = Action.getByName(args.getString());
if (action != null) {
if (action == Action.POS1 || action == Action.POS2) {
if (args.hasAtMost(3)) {
@@ -238,7 +208,6 @@ public class SelCommand extends Command {
while (args.has(2)) {
args.get();
}
return args.tabCompleteDatatype(ForBlockOptionalMeta.class);
}
} else if (action == Action.EXPAND || action == Action.CONTRACT || action == Action.SHIFT) {
@@ -250,7 +219,6 @@ public class SelCommand extends Command {
.stream();
} else {
TransformTarget target = TransformTarget.getByName(args.getString());
if (target != null && args.hasExactlyOne()) {
return args.tabCompleteDatatype(ForEnumFacing.class);
}
@@ -258,7 +226,6 @@ public class SelCommand extends Command {
}
}
}
return Stream.empty();
}
@@ -299,20 +266,16 @@ public class SelCommand extends Command {
enum Action {
POS1("pos1", "p1", "1"),
POS2("pos2", "p2", "2"),
CLEAR("clear", "c"),
UNDO("undo", "u"),
SET("set", "fill", "s", "f"),
WALLS("walls", "w"),
SHELL("shell", "shl"),
CLEARAREA("cleararea", "ca"),
REPLACE("replace", "r"),
EXPAND("expand", "ex"),
CONTRACT("contract", "ct"),
SHIFT("shift", "sh");
private final String[] names;
Action(String... names) {
@@ -327,17 +290,14 @@ public class SelCommand extends Command {
}
}
}
return null;
}
public static String[] getAllNames() {
Set<String> names = new HashSet<>();
for (Action action : Action.values()) {
names.addAll(asList(action.names));
}
return names.toArray(new String[0]);
}
}
@@ -346,7 +306,6 @@ public class SelCommand extends Command {
ALL(sels -> sels, "all", "a"),
NEWEST(sels -> new ISelection[]{sels[sels.length - 1]}, "newest", "n"),
OLDEST(sels -> new ISelection[]{sels[0]}, "oldest", "o");
private final Function<ISelection[], ISelection[]> transform;
private final String[] names;
@@ -367,17 +326,14 @@ public class SelCommand extends Command {
}
}
}
return null;
}
public static String[] getAllNames() {
Set<String> names = new HashSet<>();
for (TransformTarget target : TransformTarget.values()) {
names.addAll(asList(target.names));
}
return names.toArray(new String[0]);
}
}

View File

@@ -53,27 +53,23 @@ public class SetCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
String arg = args.has() ? args.getString().toLowerCase(Locale.US) : "list";
if (asList("s", "save").contains(arg)) {
SettingsUtil.save(settings);
logDirect("Settings saved");
return;
}
boolean viewModified = asList("m", "mod", "modified").contains(arg);
boolean viewAll = asList("all", "l", "list").contains(arg);
boolean paginate = viewModified || viewAll;
if (paginate) {
String search = args.has() && args.peekAsOrNull(Integer.class) == null ? args.getString() : "";
args.requireMax(1);
List<? extends Settings.Setting> toPaginate =
(viewModified ? SettingsUtil.modifiedSettings(settings) : settings.allSettings).stream()
.filter(s -> !s.getName().equals("logger"))
.filter(s -> s.getName().toLowerCase(Locale.US).contains(search.toLowerCase(Locale.US)))
.sorted((s1, s2) -> String.CASE_INSENSITIVE_ORDER.compare(s1.getName(), s2.getName()))
.collect(Collectors.toList());
Paginator.paginate(
args,
new Paginator<>(toPaginate),
@@ -88,35 +84,28 @@ public class SetCommand extends Command {
settingTypeToString(setting)
));
typeComponent.getStyle().setColor(TextFormatting.DARK_GRAY);
ITextComponent hoverComponent = new TextComponentString("");
hoverComponent.getStyle().setColor(TextFormatting.GRAY);
hoverComponent.appendText(setting.getName());
hoverComponent.appendText(String.format("\nType: %s", settingTypeToString(setting)));
hoverComponent.appendText(String.format("\n\nValue:\n%s", settingValueToString(setting)));
String commandSuggestion = settings.prefix.value + String.format("set %s ", setting.getName());
ITextComponent component = new TextComponentString(setting.getName());
component.getStyle().setColor(TextFormatting.GRAY);
component.appendSibling(typeComponent);
component.getStyle()
.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent))
.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, commandSuggestion));
return component;
},
FORCE_COMMAND_PREFIX + "set " + arg + " " + search
);
return;
}
args.requireMax(1);
boolean resetting = arg.equalsIgnoreCase("reset");
boolean toggling = arg.equalsIgnoreCase("toggle");
boolean doingSomething = resetting || toggling;
if (resetting) {
if (!args.has()) {
logDirect("Please specify 'all' as an argument to reset to confirm you'd really like to do this");
@@ -126,41 +115,33 @@ public class SetCommand extends Command {
SettingsUtil.modifiedSettings(settings).forEach(Settings.Setting::reset);
logDirect("All settings have been reset to their default values");
SettingsUtil.save(settings);
return;
}
}
if (toggling) {
args.requireMin(1);
}
String settingName = doingSomething ? args.getString() : arg;
Settings.Setting<?> setting = settings.allSettings.stream()
.filter(s -> s.getName().equalsIgnoreCase(settingName))
.findFirst()
.orElse(null);
if (isNull(setting)) {
throw new CommandInvalidTypeException(args.consumed(), "a valid setting");
}
if (!doingSomething && !args.has()) {
logDirect(String.format("Value of setting %s:", setting.getName()));
logDirect(settingValueToString(setting));
} else {
String oldValue = settingValueToString(setting);
if (resetting) {
setting.reset();
} else if (toggling) {
if (setting.getValueClass() != Boolean.class) {
throw new CommandInvalidTypeException(args.consumed(), "a toggleable setting", "some other setting");
}
//noinspection unchecked
((Settings.Setting<Boolean>) setting).value ^= true;
logDirect(String.format(
"Toggled setting %s to %s",
setting.getName(),
@@ -168,7 +149,6 @@ public class SetCommand extends Command {
));
} else {
String newValue = args.getString();
try {
SettingsUtil.parseAndApply(settings, arg, newValue);
} catch (Throwable t) {
@@ -176,7 +156,6 @@ public class SetCommand extends Command {
throw new CommandInvalidTypeException(args.consumed(), "a valid value", t);
}
}
if (!toggling) {
logDirect(String.format(
"Successfully %s %s to %s",
@@ -185,7 +164,6 @@ public class SetCommand extends Command {
settingValueToString(setting)
));
}
ITextComponent oldValueComponent = new TextComponentString(String.format("Old value: %s", oldValue));
oldValueComponent.getStyle()
.setColor(TextFormatting.GRAY)
@@ -197,9 +175,7 @@ public class SetCommand extends Command {
ClickEvent.Action.RUN_COMMAND,
FORCE_COMMAND_PREFIX + String.format("set %s %s", setting.getName(), oldValue)
));
logDirect(oldValueComponent);
if ((setting.getName().equals("chatControl") && !(Boolean) setting.value && !settings.chatControlAnyway.value) ||
setting.getName().equals("chatControlAnyway") && !(Boolean) setting.value && !settings.chatControl.value) {
logDirect("Warning: Chat commands will no longer work. If you want to revert this change, use prefix control (if enabled) or click the old value listed above.", TextFormatting.RED);
@@ -207,7 +183,6 @@ public class SetCommand extends Command {
logDirect("Warning: Prefixed commands will no longer work. If you want to revert this change, use chat control (if enabled) or click the old value listed above.", TextFormatting.RED);
}
}
SettingsUtil.save(settings);
}
@@ -215,7 +190,6 @@ public class SetCommand extends Command {
protected Stream<String> tabCompleted(String label, ArgConsumer args, Settings settings) {
if (args.has()) {
String arg = args.getString();
if (args.hasExactlyOne() && !asList("s", "save").contains(args.peekString().toLowerCase(Locale.US))) {
if (arg.equalsIgnoreCase("reset")) {
return new TabCompleteHelper()
@@ -229,19 +203,15 @@ public class SetCommand extends Command {
.filterPrefix(args.getString())
.stream();
}
Settings.Setting setting = settings.byLowerName.get(arg.toLowerCase(Locale.US));
if (nonNull(setting)) {
if (setting.getType() == Boolean.class) {
TabCompleteHelper helper = new TabCompleteHelper();
if ((Boolean) setting.value) {
helper.append(of("true", "false"));
} else {
helper.append(of("false", "true"));
}
return helper.filterPrefix(args.getString()).stream();
} else {
return Stream.of(settingValueToString(setting));
@@ -256,7 +226,6 @@ public class SetCommand extends Command {
.stream();
}
}
return Stream.empty();
}

View File

@@ -37,13 +37,11 @@ public class ThisWayCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireExactly(1);
GoalXZ goal = GoalXZ.fromDirection(
ctx.playerFeetAsVec(),
ctx.player().rotationYawHead,
args.getAs(Double.class)
);
baritone.getCustomGoalProcess().setGoal(goal);
logDirect(String.format("Goal: %s", goal));
}

View File

@@ -38,12 +38,10 @@ public class TunnelCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
Goal goal = new GoalStrictDirection(
ctx.playerFeet(),
ctx.player().getHorizontalFacing()
);
baritone.getCustomGoalProcess().setGoal(goal);
logDirect(String.format("Goal: %s", goal.toString()));
}

View File

@@ -38,9 +38,7 @@ public class VersionCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
args.requireMax(0);
String version = getClass().getPackage().getImplementationVersion();
if (isNull(version)) {
throw new CommandInvalidStateException("Null version (this is normal in a dev environment)");
} else {

View File

@@ -58,14 +58,11 @@ public class WaypointsCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
Action action = args.has() ? Action.getByName(args.getString()) : Action.LIST;
if (action == null) {
throw new CommandInvalidTypeException(args.consumed(), "an action");
}
BiFunction<IWaypoint, Action, ITextComponent> toComponent = (waypoint, _action) -> {
ITextComponent component = new TextComponentString("");
ITextComponent tagComponent = new TextComponentString(waypoint.getTag().name() + " ");
tagComponent.getStyle().setColor(TextFormatting.GRAY);
String name = waypoint.getName();
@@ -73,7 +70,6 @@ public class WaypointsCommand extends Command {
nameComponent.getStyle().setColor(!name.isEmpty() ? TextFormatting.GRAY : TextFormatting.DARK_GRAY);
ITextComponent timestamp = new TextComponentString(" @ " + new Date(waypoint.getCreationTimestamp()));
timestamp.getStyle().setColor(TextFormatting.DARK_GRAY);
component.appendSibling(tagComponent);
component.appendSibling(nameComponent);
component.appendSibling(timestamp);
@@ -93,24 +89,18 @@ public class WaypointsCommand extends Command {
waypoint.getCreationTimestamp()
))
);
return component;
};
Function<IWaypoint, ITextComponent> transform = waypoint ->
toComponent.apply(waypoint, action == Action.LIST ? Action.INFO : action);
if (action == Action.LIST) {
IWaypoint.Tag tag = args.has() ? IWaypoint.Tag.getByName(args.peekString()) : null;
if (tag != null) {
args.get();
}
IWaypoint[] waypoints = tag != null
? ForWaypoints.getWaypointsByTag(tag)
: ForWaypoints.getWaypoints();
if (waypoints.length > 0) {
args.requireMax(1);
Paginator.paginate(
@@ -140,21 +130,16 @@ public class WaypointsCommand extends Command {
}
} else if (action == Action.SAVE) {
IWaypoint.Tag tag = IWaypoint.Tag.getByName(args.getString());
if (tag == null) {
throw new CommandInvalidStateException(String.format("'%s' is not a tag ", args.consumedString()));
}
String name = args.has() ? args.getString() : "";
BetterBlockPos pos = args.has()
? args.getDatatypePost(RelativeBlockPos.class, ctx.playerFeet())
: ctx.playerFeet();
args.requireMax(0);
IWaypoint waypoint = new Waypoint(name, tag, pos);
ForWaypoints.waypoints().addWaypoint(waypoint);
ITextComponent component = new TextComponentString("Waypoint added: ");
component.getStyle().setColor(TextFormatting.GRAY);
component.appendSibling(toComponent.apply(waypoint, Action.INFO));
@@ -163,28 +148,23 @@ public class WaypointsCommand extends Command {
args.requireMax(1);
IWaypoint.Tag tag = IWaypoint.Tag.getByName(args.getString());
IWaypoint[] waypoints = ForWaypoints.getWaypointsByTag(tag);
for (IWaypoint waypoint : waypoints) {
ForWaypoints.waypoints().removeWaypoint(waypoint);
}
logDirect(String.format("Cleared %d waypoints", waypoints.length));
} else {
IWaypoint[] waypoints = args.getDatatypeFor(ForWaypoints.class);
IWaypoint waypoint = null;
if (args.has() && args.peekString().equals("@")) {
args.requireExactly(2);
args.get();
long timestamp = args.getAs(Long.class);
for (IWaypoint iWaypoint : waypoints) {
if (iWaypoint.getCreationTimestamp() == timestamp) {
waypoint = iWaypoint;
break;
}
}
if (waypoint == null) {
throw new CommandInvalidStateException("Timestamp was specified but no waypoint was found");
}
@@ -196,7 +176,6 @@ public class WaypointsCommand extends Command {
waypoint = waypoints[0];
}
}
if (waypoint == null) {
args.requireMax(1);
Paginator.paginate(
@@ -273,7 +252,6 @@ public class WaypointsCommand extends Command {
.stream();
} else {
Action action = Action.getByName(args.getString());
if (args.hasExactlyOne()) {
if (action == Action.LIST || action == Action.SAVE || action == Action.CLEAR) {
return new TabCompleteHelper()
@@ -291,7 +269,6 @@ public class WaypointsCommand extends Command {
}
}
}
return Stream.empty();
}
@@ -327,7 +304,6 @@ public class WaypointsCommand extends Command {
INFO("info", "show", "i"),
DELETE("delete", "d"),
GOAL("goal", "goto", "g");
private final String[] names;
Action(String... names) {
@@ -342,17 +318,14 @@ public class WaypointsCommand extends Command {
}
}
}
return null;
}
public static String[] getAllNames() {
Set<String> names = new HashSet<>();
for (Action action : Action.values()) {
names.addAll(asList(action.names));
}
return names.toArray(new String[0]);
}
}

View File

@@ -25,6 +25,7 @@ import net.minecraft.util.math.BlockPos;
import java.util.List;
public final class SchematicAdapter implements ISchematic {
private final SchematicWorld schematic;
public SchematicAdapter(SchematicWorld schematicWorld) {