Skip to content

Commit f7290e2

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 8eef52b + 6c63feb commit f7290e2

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

src/main/java/dev/dfonline/codeclient/Commands.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,48 @@ else if(field.getType().isEnum()) {
372372
return -1;
373373
})));
374374

375+
dispatcher.register(literal("search")
376+
.then(argument("query",greedyString()).suggests((context,builder) -> suggestJump(JumpType.ANY, context, builder)).executes(context -> {
377+
if(CodeClient.location instanceof Dev dev) {
378+
var query = context.getArgument("query", String.class);
379+
var results = dev.scanForSigns(JumpType.ANY.pattern,Pattern.compile("^.*"+Pattern.quote(query)+".*$", Pattern.CASE_INSENSITIVE));
380+
381+
if (results == null || results.isEmpty()) {
382+
Utility.sendMessage(Text.translatable("codeclient.search.no_results"), ChatType.INFO);
383+
return 0;
384+
}
385+
386+
var message = Text.translatable("codeclient.search.results");
387+
results.forEach((pos,text) -> {
388+
var type = text.getMessage(0, false).getString();
389+
var name = text.getMessage(1, false).getString();
390+
391+
String sub = null;
392+
if (JumpType.PLAYER_EVENT.pattern.matcher(type).matches()) sub = "player";
393+
else if (JumpType.ENTITY_EVENT.pattern.matcher(type).matches()) sub = "entity";
394+
else if (JumpType.FUNCTION.pattern.matcher(type).matches()) sub = "func";
395+
else if (JumpType.PROCESS.pattern.matcher(type).matches()) sub = "proc";
396+
else return;
397+
398+
var action = Text.empty().append(" [⏼]").setStyle(Style.EMPTY
399+
.withColor(Formatting.GREEN)
400+
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, String.format("/jump %s %s", sub, name)))
401+
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("codeclient.search.hover.teleport", pos.getX(), pos.getY(), pos.getZ())))
402+
);
403+
var entry = Text.empty().append("\n • ").formatted(Formatting.GREEN)
404+
.append(Text.empty().append(name).formatted(Formatting.WHITE))
405+
.append(action);
406+
message.append(entry);
407+
});
408+
409+
Utility.sendMessage(message, ChatType.SUCCESS);
410+
} else {
411+
Utility.sendMessage(Text.translatable("codeclient.warning.dev_mode"), ChatType.FAIL);
412+
}
413+
return 0;
414+
})
415+
));
416+
375417
LiteralCommandNode<FabricClientCommandSource> jumpCommand = dispatcher.register(literal("jump")
376418
.then(literal("player").then(argument("name", greedyString()).suggests((context, builder) -> suggestJump(JumpType.PLAYER_EVENT, context, builder)).executes(context -> {
377419
var name = context.getArgument("name", String.class);
@@ -616,7 +658,8 @@ private static enum JumpType {
616658
PLAYER_EVENT("PLAYER EVENT"),
617659
ENTITY_EVENT("ENTITY EVENT"),
618660
FUNCTION("FUNCTION"),
619-
PROCESS("PROCESS");
661+
PROCESS("PROCESS"),
662+
ANY("(((PLAYER)|(ENTITY)) EVENT)|(FUNCTION)|(PROCESS)");
620663

621664
public final Pattern pattern;
622665
JumpType(String scan) {

src/main/resources/assets/codeclient/lang/en_us.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
"codeclient.warning.dev_mode": "You must be in dev mode!",
6868
"codeclient.warning.creative_mode": "You must be in creative mode!",
6969

70+
"codeclient.search.results": "Search Results:",
71+
"codeclient.search.no_results": "No results.",
72+
"codeclient.search.hover.teleport": "Click to teleport\nx: %s, y: %s, z: %s",
73+
7074
"codeclient.files.template_fail": "Couldn't load templates.",
7175
"codeclient.files.hold_template": "You need to hold a template to save.",
7276
"codeclient.files.empty_dir": "Please use an empty folder to save into.",

0 commit comments

Comments
 (0)