Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add glow argument to find command. #659

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import dev.xpple.clientarguments.arguments.CEntitySelector;
import net.earthcomputer.clientcommands.interfaces.IEntity_Glowable;
import net.earthcomputer.clientcommands.task.LongTask;
import net.earthcomputer.clientcommands.task.TaskManager;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
Expand All @@ -25,6 +26,7 @@
public class FindCommand {

private static final Flag<Boolean> FLAG_KEEP_SEARCHING = Flag.ofFlag("keep-searching").build();
private static final Flag<Boolean> FLAG_GLOW = Flag.ofFlag("glow").build();

private static final SimpleCommandExceptionType NO_MATCH_EXCEPTION = new SimpleCommandExceptionType(Component.translatable("commands.cfind.noMatch"));

Expand All @@ -33,10 +35,12 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
.then(argument("filter", entities())
.executes(ctx -> listEntities(ctx.getSource(), ctx.getArgument("filter", CEntitySelector.class)))));
FLAG_KEEP_SEARCHING.addToCommand(dispatcher, cfind, ctx -> true);
FLAG_GLOW.addToCommand(dispatcher, cfind, ctx -> true);
}

private static int listEntities(FabricClientCommandSource source, CEntitySelector selector) throws CommandSyntaxException {
boolean keepSearching = getFlag(source, FLAG_KEEP_SEARCHING);
boolean glow = getFlag(source, FLAG_GLOW);
if (keepSearching) {
String taskName = TaskManager.addTask("cfind", new FindTask(source, selector));

Expand All @@ -56,6 +60,12 @@ private static int listEntities(FabricClientCommandSource source, CEntitySelecto
for (Entity entity : entities) {
sendEntityFoundMessage(source, entity);
}
if (glow) {
for (Entity entity : entities) {
//noinspection DataFlowIssue
((IEntity_Glowable) entity).clientcommands_addGlowingTicket(20 * 30, ChatFormatting.WHITE.getColor());
}
}

return entities.size();
}
Expand Down Expand Up @@ -97,6 +107,11 @@ public void body() {
for (Entity entity : selector.getEntities(this.source)) {
if (foundEntities.add(entity.getUUID())) {
sendEntityFoundMessage(source, entity);
boolean glow = getFlag(source, FLAG_GLOW);
if (glow) {
//noinspection DataFlowIssue
((IEntity_Glowable) entity).clientcommands_addGlowingTicket(20 * 30, ChatFormatting.WHITE.getColor());
}
}
}
} catch (CommandSyntaxException e) {
Expand All @@ -106,5 +121,4 @@ public void body() {
scheduleDelay();
}
}

}
Loading