Skip to content

Commit

Permalink
Make the output for dump all tags clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed May 13, 2021
1 parent 767d586 commit 8e6e608
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/java/slimeknights/mantle/command/DumpAllTagsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
import net.minecraft.tags.ITag.Builder;
import net.minecraft.util.JSONUtils;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.ClickEvent.Action;
import net.minecraftforge.common.ForgeTagHandler;
import net.minecraftforge.registries.ForgeRegistry;
import net.minecraftforge.registries.RegistryManager;
Expand Down Expand Up @@ -59,6 +63,15 @@ private static File getOutputFile(CommandContext<CommandSource> context) {
return context.getSource().getServer().getFile(TAG_DUMP_PATH);
}

/**
* Makes a clickable text component for the output folder
* @param file File
* @return Clickable text component
*/
private static ITextComponent getOutputComponent(File file) {
return new StringTextComponent(file.getAbsolutePath()).modifyStyle(style -> style.setUnderlined(true).setClickEvent(new ClickEvent(Action.OPEN_FILE, file.getAbsolutePath())));
}

/** Dumps all tags to the game directory */
private static int runAll(CommandContext<CommandSource> context) throws CommandSyntaxException {
File output = getOutputFile(context);
Expand All @@ -74,7 +87,7 @@ private static int runAll(CommandContext<CommandSource> context) throws CommandS
}
}
// print the output path
context.getSource().sendFeedback(new TranslationTextComponent("command.mantle.dump_all_tags.success", output.getAbsolutePath()), true);
context.getSource().sendFeedback(new TranslationTextComponent("command.mantle.dump_all_tags.success", getOutputComponent(output)), true);
return tagsDumped;
}

Expand All @@ -84,7 +97,7 @@ private static int runType(CommandContext<CommandSource> context) throws Command
TagCollectionArgument.Result type = context.getArgument("type", TagCollectionArgument.Result.class);
int result = runForFolder(context, type.getName(), type.getTagFolder(), output);
// print result
context.getSource().sendFeedback(new TranslationTextComponent("command.mantle.dump_all_tags.type_success", type.getName(), output.getAbsolutePath()), true);
context.getSource().sendFeedback(new TranslationTextComponent("command.mantle.dump_all_tags.type_success", type.getName(), getOutputComponent(output)), true);
return result;
}

Expand Down

0 comments on commit 8e6e608

Please sign in to comment.