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.
This commit is contained in:
parent
e6ee5fc6b8
commit
ef4e19002b
@ -22,7 +22,9 @@ import baritone.api.command.Command;
|
|||||||
import baritone.api.command.argument.IArgConsumer;
|
import baritone.api.command.argument.IArgConsumer;
|
||||||
import baritone.api.command.datatypes.BlockById;
|
import baritone.api.command.datatypes.BlockById;
|
||||||
import baritone.api.command.exception.CommandException;
|
import baritone.api.command.exception.CommandException;
|
||||||
|
import baritone.api.command.helpers.TabCompleteHelper;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
|
import baritone.cache.CachedChunk;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.TextComponentString;
|
import net.minecraft.util.text.TextComponentString;
|
||||||
@ -45,12 +47,13 @@ public class FindCommand extends Command {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(String label, IArgConsumer args) throws CommandException {
|
public void execute(String label, IArgConsumer args) throws CommandException {
|
||||||
|
args.requireMin(1);
|
||||||
List<Block> toFind = new ArrayList<>();
|
List<Block> toFind = new ArrayList<>();
|
||||||
while (args.hasAny()) {
|
while (args.hasAny()) {
|
||||||
toFind.add(args.getDatatypeFor(BlockById.INSTANCE));
|
toFind.add(args.getDatatypeFor(BlockById.INSTANCE));
|
||||||
}
|
}
|
||||||
BetterBlockPos origin = ctx.playerFeet();
|
BetterBlockPos origin = ctx.playerFeet();
|
||||||
toFind.stream()
|
ITextComponent[] components = toFind.stream()
|
||||||
.flatMap(block ->
|
.flatMap(block ->
|
||||||
ctx.worldData().getCachedWorld().getLocationsOf(
|
ctx.worldData().getCachedWorld().getLocationsOf(
|
||||||
Block.REGISTRY.getNameForObject(block).getPath(),
|
Block.REGISTRY.getNameForObject(block).getPath(),
|
||||||
@ -62,7 +65,12 @@ public class FindCommand extends Command {
|
|||||||
)
|
)
|
||||||
.map(BetterBlockPos::new)
|
.map(BetterBlockPos::new)
|
||||||
.map(this::positionToComponent)
|
.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) {
|
private ITextComponent positionToComponent(BetterBlockPos pos) {
|
||||||
@ -79,8 +87,16 @@ public class FindCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Stream<String> tabComplete(String label, IArgConsumer args) {
|
public Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException {
|
||||||
return args.tabCompleteDatatype(BlockById.INSTANCE);
|
return new TabCompleteHelper()
|
||||||
|
.append(
|
||||||
|
CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.stream()
|
||||||
|
.map(Block.REGISTRY::getNameForObject)
|
||||||
|
.map(Object::toString)
|
||||||
|
)
|
||||||
|
.filterPrefixNamespaced(args.getString())
|
||||||
|
.sortAlphabetically()
|
||||||
|
.stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -92,9 +108,10 @@ public class FindCommand extends Command {
|
|||||||
public List<String> getLongDesc() {
|
public List<String> getLongDesc() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
"The find command searches through Baritone's cache and attempts to find the location of the block.",
|
"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:",
|
"Usage:",
|
||||||
"> find <block> - Find positions of a certain block"
|
"> find <block> [...] - Try finding the listed blocks"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user