From e6ee5fc6b84c17164633607a43aed12477839cde Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sat, 5 Mar 2022 17:56:20 +0100 Subject: [PATCH 1/7] Make positions from #find clickable --- .../command/defaults/FindCommand.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/baritone/command/defaults/FindCommand.java b/src/main/java/baritone/command/defaults/FindCommand.java index 65eb9b5c3..b20857b4c 100644 --- a/src/main/java/baritone/command/defaults/FindCommand.java +++ b/src/main/java/baritone/command/defaults/FindCommand.java @@ -24,12 +24,19 @@ import baritone.api.command.datatypes.BlockById; import baritone.api.command.exception.CommandException; import baritone.api.utils.BetterBlockPos; import net.minecraft.block.Block; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.event.ClickEvent; +import net.minecraft.util.text.event.HoverEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Stream; +import static baritone.api.command.IBaritoneChatControl.FORCE_COMMAND_PREFIX; + public class FindCommand extends Command { public FindCommand(IBaritone baritone) { @@ -54,10 +61,23 @@ public class FindCommand extends Command { ).stream() ) .map(BetterBlockPos::new) - .map(BetterBlockPos::toString) + .map(this::positionToComponent) .forEach(this::logDirect); } + private ITextComponent positionToComponent(BetterBlockPos pos) { + String positionText = String.format("%s %s %s", pos.x, pos.y, pos.z); + String command = String.format("%sgoal %s", FORCE_COMMAND_PREFIX, positionText); + ITextComponent baseComponent = new TextComponentString(pos.toString()); + ITextComponent hoverComponent = new TextComponentString("Click to set goal to this position"); + baseComponent.getStyle() + .setColor(TextFormatting.GRAY) + .setInsertion(positionText) + .setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)) + .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverComponent)); + return baseComponent; + } + @Override public Stream tabComplete(String label, IArgConsumer args) { return args.tabCompleteDatatype(BlockById.INSTANCE); From ef4e19002b9f6453907cc59928d0837a0911200c Mon Sep 17 00:00:00 2001 From: ZacSharp <68165024+ZacSharp@users.noreply.github.com> Date: Sat, 5 Mar 2022 21:04:24 +0100 Subject: [PATCH 2/7] Provide more information for #find Always log something to chat so people don't think it's broken and make sure they know about the restriction to cached blocks. --- .../command/defaults/FindCommand.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/command/defaults/FindCommand.java b/src/main/java/baritone/command/defaults/FindCommand.java index b20857b4c..b20f14e98 100644 --- a/src/main/java/baritone/command/defaults/FindCommand.java +++ b/src/main/java/baritone/command/defaults/FindCommand.java @@ -22,7 +22,9 @@ import baritone.api.command.Command; import baritone.api.command.argument.IArgConsumer; import baritone.api.command.datatypes.BlockById; import baritone.api.command.exception.CommandException; +import baritone.api.command.helpers.TabCompleteHelper; import baritone.api.utils.BetterBlockPos; +import baritone.cache.CachedChunk; import net.minecraft.block.Block; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; @@ -45,12 +47,13 @@ public class FindCommand extends Command { @Override public void execute(String label, IArgConsumer args) throws CommandException { + args.requireMin(1); List toFind = new ArrayList<>(); while (args.hasAny()) { toFind.add(args.getDatatypeFor(BlockById.INSTANCE)); } BetterBlockPos origin = ctx.playerFeet(); - toFind.stream() + ITextComponent[] components = toFind.stream() .flatMap(block -> ctx.worldData().getCachedWorld().getLocationsOf( Block.REGISTRY.getNameForObject(block).getPath(), @@ -62,7 +65,12 @@ public class FindCommand extends Command { ) .map(BetterBlockPos::new) .map(this::positionToComponent) - .forEach(this::logDirect); + .toArray(ITextComponent[]::new); + if (components.length > 0) { + Arrays.asList(components).forEach(this::logDirect); + } else { + logDirect("No positions known, are you sure the blocks are cached?"); + } } private ITextComponent positionToComponent(BetterBlockPos pos) { @@ -79,8 +87,16 @@ public class FindCommand extends Command { } @Override - public Stream tabComplete(String label, IArgConsumer args) { - return args.tabCompleteDatatype(BlockById.INSTANCE); + public Stream tabComplete(String label, IArgConsumer args) throws CommandException { + return new TabCompleteHelper() + .append( + CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.stream() + .map(Block.REGISTRY::getNameForObject) + .map(Object::toString) + ) + .filterPrefixNamespaced(args.getString()) + .sortAlphabetically() + .stream(); } @Override @@ -92,9 +108,10 @@ public class FindCommand extends Command { public List getLongDesc() { return Arrays.asList( "The find command searches through Baritone's cache and attempts to find the location of the block.", + "Tab completion will suggest only cached blocks and uncached blocks can not be found.", "", "Usage:", - "> find - Find positions of a certain block" + "> find [...] - Try finding the listed blocks" ); } } From 2741fc2683be6f49edbd4fdfdfce6ab5d3593217 Mon Sep 17 00:00:00 2001 From: Echocage Date: Mon, 27 Jun 2022 15:06:27 -0500 Subject: [PATCH 3/7] Swapped the order of checks within canSprintFromDescendInto --- src/main/java/baritone/pathing/path/PathExecutor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 7e4f76a3b..0ff113df8 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -536,12 +536,12 @@ public class PathExecutor implements IPathExecutor, Helper { } private static boolean canSprintFromDescendInto(IPlayerContext ctx, IMovement current, IMovement next) { - if (next instanceof MovementDescend && next.getDirection().equals(current.getDirection())) { - return true; - } if (!MovementHelper.canWalkOn(ctx, current.getDest().add(current.getDirection()))) { return false; } + if (next instanceof MovementDescend && next.getDirection().equals(current.getDirection())) { + return true; + } if (next instanceof MovementTraverse && next.getDirection().down().equals(current.getDirection())) { return true; } From 57c4f9e1033cad41353c4bc74cee158d2041025a Mon Sep 17 00:00:00 2001 From: Echocage Date: Mon, 27 Jun 2022 18:38:54 -0500 Subject: [PATCH 4/7] Undid previous change, updated to instead check the next and the next_next block --- src/main/java/baritone/pathing/path/PathExecutor.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 0ff113df8..0ff7a3ac0 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -385,7 +385,7 @@ public class PathExecutor implements IPathExecutor, Helper { return false; } - if (pathPosition < path.length() - 2) { + if (pathPosition < path.length() - 3) { IMovement next = path.movements().get(pathPosition + 1); if (next instanceof MovementAscend && current.getDirection().up().equals(next.getDirection().down())) { // a descend then an ascend in the same direction @@ -396,7 +396,8 @@ public class PathExecutor implements IPathExecutor, Helper { logDebug("Skipping descend to straight ascend"); return true; } - if (canSprintFromDescendInto(ctx, current, next)) { + if (canSprintFromDescendInto(ctx, current, next) && + canSprintFromDescendInto(ctx, next, path.movements().get(pathPosition + 2))) { if (ctx.playerFeet().equals(current.getDest())) { pathPosition++; onChangeInPathPosition(); @@ -536,12 +537,12 @@ public class PathExecutor implements IPathExecutor, Helper { } private static boolean canSprintFromDescendInto(IPlayerContext ctx, IMovement current, IMovement next) { - if (!MovementHelper.canWalkOn(ctx, current.getDest().add(current.getDirection()))) { - return false; - } if (next instanceof MovementDescend && next.getDirection().equals(current.getDirection())) { return true; } + if (!MovementHelper.canWalkOn(ctx, current.getDest().add(current.getDirection()))) { + return false; + } if (next instanceof MovementTraverse && next.getDirection().down().equals(current.getDirection())) { return true; } From 441dceb73174cfc376eaf455ba5673b3679a8102 Mon Sep 17 00:00:00 2001 From: Echocage Date: Wed, 29 Jun 2022 17:54:28 -0500 Subject: [PATCH 5/7] Narrowed scope and we now only call canSprintFromDescendInto when our next & next_next movements are both MovementDescends --- .../baritone/pathing/path/PathExecutor.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/baritone/pathing/path/PathExecutor.java b/src/main/java/baritone/pathing/path/PathExecutor.java index 0ff7a3ac0..17fa788db 100644 --- a/src/main/java/baritone/pathing/path/PathExecutor.java +++ b/src/main/java/baritone/pathing/path/PathExecutor.java @@ -73,8 +73,8 @@ public class PathExecutor implements IPathExecutor, Helper { private HashSet toPlace = new HashSet<>(); private HashSet toWalkInto = new HashSet<>(); - private PathingBehavior behavior; - private IPlayerContext ctx; + private final PathingBehavior behavior; + private final IPlayerContext ctx; private boolean sprintNextTick; @@ -385,7 +385,7 @@ public class PathExecutor implements IPathExecutor, Helper { return false; } - if (pathPosition < path.length() - 3) { + if (pathPosition < path.length() - 2) { IMovement next = path.movements().get(pathPosition + 1); if (next instanceof MovementAscend && current.getDirection().up().equals(next.getDirection().down())) { // a descend then an ascend in the same direction @@ -396,13 +396,21 @@ public class PathExecutor implements IPathExecutor, Helper { logDebug("Skipping descend to straight ascend"); return true; } - if (canSprintFromDescendInto(ctx, current, next) && - canSprintFromDescendInto(ctx, next, path.movements().get(pathPosition + 2))) { + if (canSprintFromDescendInto(ctx, current, next)) { + + if (next instanceof MovementDescend && pathPosition < path.length() - 3) { + IMovement next_next = path.movements().get(pathPosition + 2); + if (next_next instanceof MovementDescend && !canSprintFromDescendInto(ctx, next, next_next)) { + return false; + } + + } if (ctx.playerFeet().equals(current.getDest())) { pathPosition++; onChangeInPathPosition(); onTick(); } + return true; } //logDebug("Turning off sprinting " + movement + " " + next + " " + movement.getDirection() + " " + next.getDirection().down() + " " + next.getDirection().down().equals(movement.getDirection())); From 51275b3a65c83851f0d9177408bc896a25e31df8 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 9 Jul 2022 22:06:39 -0700 Subject: [PATCH 6/7] make #paws be an alias for #pause --- .../baritone/command/defaults/ExecutionControlCommands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/command/defaults/ExecutionControlCommands.java b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java index 8a53e7d41..5b3f85db6 100644 --- a/src/main/java/baritone/command/defaults/ExecutionControlCommands.java +++ b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java @@ -79,7 +79,7 @@ public class ExecutionControlCommands { } } ); - pauseCommand = new Command(baritone, "pause", "p") { + pauseCommand = new Command(baritone, "pause", "p", "paws") { @Override public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0); From 4e2095d25114dd88fa01baf21a805d3f6e1b8ee9 Mon Sep 17 00:00:00 2001 From: Leijurv Date: Sat, 9 Jul 2022 22:15:20 -0700 Subject: [PATCH 7/7] almost forgot --- .../baritone/command/defaults/ExecutionControlCommands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/baritone/command/defaults/ExecutionControlCommands.java b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java index 5b3f85db6..eaab75286 100644 --- a/src/main/java/baritone/command/defaults/ExecutionControlCommands.java +++ b/src/main/java/baritone/command/defaults/ExecutionControlCommands.java @@ -112,7 +112,7 @@ public class ExecutionControlCommands { ); } }; - resumeCommand = new Command(baritone, "resume", "r", "unpause") { + resumeCommand = new Command(baritone, "resume", "r", "unpause", "unpaws") { @Override public void execute(String label, IArgConsumer args) throws CommandException { args.requireMax(0);