From 2956287ae4b953f35809d3ff93e77ce406d714e8 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Thu, 1 Aug 2024 11:40:51 -0700 Subject: [PATCH 01/17] move code generation colors to constant values --- .../compat/mods/jei/InfoParserTab.java | 3 +- .../infoparser/InfoParserTranslationKey.java | 3 +- .../ingredient/GroovyScriptCodeConverter.java | 74 ++++++++++++------- .../helper/ingredient/NbtHelper.java | 65 ++++++++-------- 4 files changed, 85 insertions(+), 60 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java index 836f6d190..227a6e58e 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java @@ -3,6 +3,7 @@ import com.cleanroommc.groovyscript.api.infocommand.InfoParserPackage; import com.cleanroommc.groovyscript.compat.vanilla.command.infoparser.GenericInfoParser; import com.cleanroommc.groovyscript.core.mixin.jei.ModRegistryAccessor; +import com.cleanroommc.groovyscript.helper.ingredient.GroovyScriptCodeConverter; import mezz.jei.api.recipe.IRecipeCategory; import net.minecraft.item.ItemStack; import net.minecraft.util.text.TextFormatting; @@ -29,7 +30,7 @@ public String name() { @Override public String text(@NotNull IRecipeCategory entry, boolean colored, boolean prettyNbt) { - return colored ? TextFormatting.YELLOW + entry.getUid() : entry.getUid(); + return colored ? GroovyScriptCodeConverter.STRING + entry.getUid() : entry.getUid(); } @Override diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java index a611bb5e5..c5cd3d25a 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java @@ -1,6 +1,7 @@ package com.cleanroommc.groovyscript.compat.vanilla.command.infoparser; import com.cleanroommc.groovyscript.api.infocommand.InfoParserPackage; +import com.cleanroommc.groovyscript.helper.ingredient.GroovyScriptCodeConverter; import net.minecraft.util.text.TextFormatting; import org.jetbrains.annotations.NotNull; @@ -20,7 +21,7 @@ public String name() { @Override public String text(@NotNull String entry, boolean colored, boolean prettyNbt) { - return colored ? TextFormatting.YELLOW + entry : entry; + return colored ? GroovyScriptCodeConverter.STRING + entry : entry; } @Override diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java index cc8fdafa4..0b5cacdbf 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java @@ -26,22 +26,40 @@ public class GroovyScriptCodeConverter { + public static final TextFormatting BASE = TextFormatting.GRAY; + public static final TextFormatting NUMBER = TextFormatting.YELLOW; + public static final TextFormatting STRING = TextFormatting.AQUA; + public static final TextFormatting HANDLER = TextFormatting.DARK_GREEN; + public static final TextFormatting NEW = TextFormatting.LIGHT_PURPLE; + public static final TextFormatting CLASS = TextFormatting.GOLD; + public static String formatNumber(int number, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.YELLOW); + if (colored) builder.append(NUMBER); builder.append(number); return builder.toString(); } + public static String formatString(String target, boolean colored) { + StringBuilder builder = new StringBuilder(); + if (colored) builder.append(BASE); + builder.append("'"); + if (colored) builder.append(STRING); + builder.append(target); + if (colored) builder.append(BASE); + builder.append("'"); + return builder.toString(); + } + public static String formatGenericHandler(String handler, String target, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.DARK_GREEN); + if (colored) builder.append(HANDLER); builder.append(handler); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); builder.append("('"); - if (colored) builder.append(TextFormatting.AQUA); + if (colored) builder.append(STRING); builder.append(target); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); builder.append("')"); return builder.toString(); } @@ -49,7 +67,7 @@ public static String formatGenericHandler(String handler, String target, boolean public static String formatMultiple(int amount, boolean colored) { StringBuilder builder = new StringBuilder(); if (amount > 1) { - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); builder.append(" * "); builder.append(formatNumber(amount, colored)); } @@ -58,14 +76,14 @@ public static String formatMultiple(int amount, boolean colored) { public static String formatInstantiation(String clazz, List params, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.LIGHT_PURPLE); + if (colored) builder.append(NEW); builder.append("new "); - if (colored) builder.append(TextFormatting.GOLD); + if (colored) builder.append(CLASS); builder.append(clazz); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); builder.append("("); - builder.append(String.join((colored ? TextFormatting.GRAY.toString() : "") + ", ", params)); - if (colored) builder.append(TextFormatting.GRAY); + builder.append(String.join((colored ? BASE.toString() : "") + ", ", params)); + if (colored) builder.append(BASE); builder.append(")"); return builder.toString(); } @@ -84,7 +102,7 @@ public static String formatNBTTag(NBTTagCompound tag, boolean colored, boolean p if (tag != null) { builder.append(".withNbt("); builder.append(NbtHelper.toGroovyCode(tag, prettyNbt, colored)); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); builder.append(")"); } return builder.toString(); @@ -92,27 +110,27 @@ public static String formatNBTTag(NBTTagCompound tag, boolean colored, boolean p private static String getSingleItemStack(ItemStack itemStack, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.DARK_GREEN); + if (colored) builder.append(HANDLER); builder.append("item"); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); builder.append("('"); - if (colored) builder.append(TextFormatting.AQUA); + if (colored) builder.append(STRING); builder.append(itemStack.getItem().getRegistryName()); // code is more complex than strictly needed here to allow using the wildcard if (itemStack.getMetadata() == Short.MAX_VALUE) { builder.append(":"); builder.append("*"); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); builder.append("'"); } else if (itemStack.getMetadata() == 0) { - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); builder.append("'"); } else { - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); builder.append("'"); builder.append(", "); builder.append(formatNumber(itemStack.getMetadata(), colored)); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); } builder.append(")"); return builder.toString(); @@ -186,26 +204,26 @@ public static String asGroovyCode(Block state, boolean colored) { @SuppressWarnings("all") public static String asGroovyCode(IBlockState state, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.DARK_GREEN); + if (colored) builder.append(HANDLER); builder.append("blockstate"); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); builder.append("('"); - if (colored) builder.append(TextFormatting.AQUA); + if (colored) builder.append(STRING); builder.append(state.getBlock().getRegistryName()); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); builder.append("'"); if (!state.getProperties().isEmpty()) { for (Map.Entry, Comparable> entry : state.getProperties().entrySet()) { IProperty property = entry.getKey(); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); builder.append(", ").append("'"); - if (colored) builder.append(TextFormatting.YELLOW); + if (colored) builder.append(NUMBER); builder.append(property.getName()); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); builder.append("="); - if (colored) builder.append(TextFormatting.YELLOW); + if (colored) builder.append(NUMBER); builder.append(property.getName(entry.getValue())); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(BASE); builder.append("'"); } } diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java index 11fa22791..67eb6a239 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java @@ -3,7 +3,6 @@ import com.cleanroommc.groovyscript.sandbox.expand.LambdaClosure; import groovy.lang.Closure; import net.minecraft.nbt.*; -import net.minecraft.util.text.TextFormatting; import net.minecraftforge.common.util.Constants; import java.util.List; @@ -81,67 +80,73 @@ public static NBTBase toNbt(Object o) { public static String toGroovyCode(NBTTagByte nbt, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.CLASS); builder.append("(byte) "); - if (colored) builder.append(TextFormatting.GOLD); + if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); builder.append(nbt.getByte()); return builder.toString(); } public static String toGroovyCode(NBTTagShort nbt, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.CLASS); builder.append("(short) "); - if (colored) builder.append(TextFormatting.GOLD); + if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); builder.append(nbt.getShort()); return builder.toString(); } public static String toGroovyCode(NBTTagInt nbt, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.GREEN); + if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); builder.append(nbt.getInt()); return builder.toString(); } public static String toGroovyCode(NBTTagLong nbt, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.GREEN); - builder.append(nbt.getLong()).append("L"); + if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); + builder.append(nbt.getLong()); + if (colored) builder.append(GroovyScriptCodeConverter.CLASS); + builder.append("L"); return builder.toString(); } public static String toGroovyCode(NBTTagFloat nbt, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.GREEN); - builder.append(nbt.getFloat()).append("F"); + if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); + builder.append(nbt.getFloat()); + if (colored) builder.append(GroovyScriptCodeConverter.CLASS); + builder.append("F"); return builder.toString(); } public static String toGroovyCode(NBTTagDouble nbt, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.GREEN); - builder.append(nbt.getDouble()).append("D"); + if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); + builder.append(nbt.getDouble()); + if (colored) builder.append(GroovyScriptCodeConverter.CLASS); + builder.append("D"); return builder.toString(); } public static String toGroovyCode(NBTTagByteArray nbt, int indent, boolean pretty, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.BASE); builder.append('['); if (!nbt.isEmpty()) { newLine(builder, indent, pretty); for (byte value : nbt.getByteArray()) { - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.CLASS); builder.append("(byte) "); - if (colored) builder.append(TextFormatting.GOLD); + if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); builder.append(value); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.BASE); builder.append(", "); } builder.delete(builder.length() - 2, builder.length()); newLine(builder, indent, pretty); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.BASE); } builder.append(']'); return builder.toString(); @@ -149,26 +154,26 @@ public static String toGroovyCode(NBTTagByteArray nbt, int indent, boolean prett public static String toGroovyCode(NBTTagString nbt, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.GREEN); + if (colored) builder.append(GroovyScriptCodeConverter.STRING); builder.append('\'').append(nbt.getString()).append('\''); return builder.toString(); } public static String toGroovyCode(NBTTagList nbt, int indent, boolean pretty, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.BASE); builder.append('['); if (!nbt.isEmpty()) { int internalIndent = indent + 1; for (NBTBase nbtBase : nbt) { newLine(builder, internalIndent, pretty); builder.append(toGroovyCode(nbtBase, internalIndent, pretty, colored)); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.BASE); builder.append(", "); } builder.delete(builder.length() - 2, builder.length()); newLine(builder, indent, pretty); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.BASE); } builder.append(']'); return builder.toString(); @@ -180,23 +185,23 @@ public static String toGroovyCode(NBTTagCompound nbt, boolean pretty, boolean co public static String toGroovyCode(NBTTagCompound nbt, int indent, boolean pretty, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.BASE); builder.append('['); if (!nbt.isEmpty()) { int internalIndent = indent + 1; for (String key : nbt.getKeySet()) { newLine(builder, internalIndent, pretty); - if (colored) builder.append(TextFormatting.GREEN); + if (colored) builder.append(GroovyScriptCodeConverter.NEW); builder.append('\'').append(key).append('\''); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.BASE); builder.append(": "); builder.append(toGroovyCode(nbt.getTag(key), internalIndent, pretty, colored)); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.BASE); builder.append(", "); } builder.delete(builder.length() - 2, builder.length()); newLine(builder, indent, pretty); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.BASE); } builder.append(']'); return builder.toString(); @@ -204,19 +209,19 @@ public static String toGroovyCode(NBTTagCompound nbt, int indent, boolean pretty public static String toGroovyCode(NBTTagIntArray nbt, int indent, boolean pretty, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.BASE); builder.append('['); if (!nbt.isEmpty()) { newLine(builder, indent, pretty); for (int value : nbt.getIntArray()) { - if (colored) builder.append(TextFormatting.GOLD); + if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); builder.append(value); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.BASE); builder.append(", "); } builder.delete(builder.length() - 2, builder.length()); newLine(builder, indent, pretty); - if (colored) builder.append(TextFormatting.GRAY); + if (colored) builder.append(GroovyScriptCodeConverter.BASE); } builder.append(']'); return builder.toString(); From 22f7a5cd4c5204a046b282b505a11818e4c1447e Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Mon, 7 Oct 2024 02:42:51 -0700 Subject: [PATCH 02/17] extract to StyleConstant, apply to many places --- .../groovyscript/GroovyScript.java | 10 ++- .../api/infocommand/InfoParser.java | 2 + .../groovyscript/command/BaseInfoCommand.java | 5 +- .../groovyscript/command/GSCommand.java | 29 ++++--- .../command/GSMekanismCommand.java | 4 +- .../compat/mods/jei/InfoParserTab.java | 5 +- .../command/infoparser/GenericInfoParser.java | 5 +- .../command/infoparser/InfoParserNBT.java | 4 +- .../infoparser/InfoParserTranslationKey.java | 5 +- .../core/mixin/groovy/ModuleNodeMixin.java | 2 - .../groovyscript/helper/StyleConstant.java | 87 +++++++++++++++++++ .../ingredient/GroovyScriptCodeConverter.java | 71 +++++++-------- .../helper/ingredient/NbtHelper.java | 59 ++++++------- .../network/StartLanguageServerPacket.java | 6 +- 14 files changed, 192 insertions(+), 102 deletions(-) create mode 100644 src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java diff --git a/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java b/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java index 7ac410fe7..4490aff8b 100644 --- a/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java +++ b/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java @@ -14,6 +14,7 @@ import com.cleanroommc.groovyscript.documentation.linkgenerator.LinkGeneratorHooks; import com.cleanroommc.groovyscript.event.EventHandler; import com.cleanroommc.groovyscript.helper.JsonHelper; +import com.cleanroommc.groovyscript.helper.StyleConstant; import com.cleanroommc.groovyscript.mapper.ObjectMapper; import com.cleanroommc.groovyscript.mapper.ObjectMapperManager; import com.cleanroommc.groovyscript.network.CReload; @@ -277,21 +278,22 @@ public static void postScriptRunResult(ICommandSender sender, boolean onlyLogFai if (!onlyLogFails) { if (running) { String s = packmode ? "changes packmode" : "reloaded scripts"; + sender.sendMessage(new TextComponentString("Successfully " + s).setStyle(StyleConstant.SUCCESS_STYLE).appendSibling(new TextComponentString(" in " + time + "ms"))); sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "Successfully " + s + TextFormatting.WHITE + " in " + time + "ms")); } else { - sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "No syntax errors found :)")); + sender.sendMessage(new TextComponentString("No syntax errors found :)").setStyle(StyleConstant.SUCCESS_STYLE)); } } } else { String executing = running ? "running" : "checking"; - sender.sendMessage(new TextComponentString(TextFormatting.RED + "Found " + errors.size() + " errors while " + executing + " scripts")); + sender.sendMessage(new TextComponentString("Found " + errors.size() + " errors while " + executing + " scripts").setStyle(StyleConstant.ERROR_STYLE)); int n = errors.size(); if (errors.size() >= 10) { - sender.sendMessage(new TextComponentString("Displaying the first 7 errors:")); + sender.sendMessage(new TextComponentString("Displaying the first 7 errors:").setStyle(StyleConstant.TITLE_STYLE)); n = 7; } for (int i = 0; i < n; i++) { - sender.sendMessage(new TextComponentString(TextFormatting.RED + errors.get(i))); + sender.sendMessage(new TextComponentString(errors.get(i)).setStyle(StyleConstant.ERROR_STYLE)); } GSCommand.postLogFiles(sender); } diff --git a/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParser.java b/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParser.java index 3c252e47d..7b9975be8 100644 --- a/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParser.java +++ b/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParser.java @@ -7,7 +7,9 @@ public interface InfoParser { /** * The style for any parser header - bold and light purple. + * @deprecated use {@link com.cleanroommc.groovyscript.helper.StyleConstant#TITLE_STYLE} */ + @Deprecated Style headerStyle = new Style().setColor(TextFormatting.WHITE).setBold(true); /** diff --git a/src/main/java/com/cleanroommc/groovyscript/command/BaseInfoCommand.java b/src/main/java/com/cleanroommc/groovyscript/command/BaseInfoCommand.java index 8dfd860b9..b9214fec2 100644 --- a/src/main/java/com/cleanroommc/groovyscript/command/BaseInfoCommand.java +++ b/src/main/java/com/cleanroommc/groovyscript/command/BaseInfoCommand.java @@ -3,6 +3,7 @@ import com.cleanroommc.groovyscript.api.infocommand.InfoParserPackage; import com.cleanroommc.groovyscript.api.infocommand.InfoParserRegistry; import com.cleanroommc.groovyscript.event.GsHandEvent; +import com.cleanroommc.groovyscript.helper.StyleConstant; import com.google.common.base.Predicates; import net.minecraft.command.CommandBase; import net.minecraft.command.ICommandSender; @@ -109,9 +110,9 @@ public int getRequiredPermissionLevel() { protected void print(EntityPlayer player, List messages, List argList) { if (messages.isEmpty()) { if (argList.isEmpty()) { - player.sendMessage(new TextComponentString(String.format("Couldn't find %s!", targetDescription())).setStyle(new Style().setColor(TextFormatting.RED))); + player.sendMessage(new TextComponentString(String.format("Couldn't find %s!", targetDescription())).setStyle(StyleConstant.ERROR_STYLE)); } else { - player.sendMessage(new TextComponentString(String.format("Couldn't find %s matching the given arguments!", targetDescription())).setStyle(new Style().setColor(TextFormatting.RED))); + player.sendMessage(new TextComponentString(String.format("Couldn't find %s matching the given arguments!", targetDescription())).setStyle(StyleConstant.ERROR_STYLE)); player.sendMessage(new TextComponentString("The following arguments were provided: " + String.join(", ", argList))); } } else { diff --git a/src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java b/src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java index 452012aeb..e6f0020c5 100644 --- a/src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java +++ b/src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java @@ -5,6 +5,7 @@ import com.cleanroommc.groovyscript.compat.mods.ModSupport; import com.cleanroommc.groovyscript.compat.mods.jei.JeiPlugin; import com.cleanroommc.groovyscript.documentation.Documentation; +import com.cleanroommc.groovyscript.helper.StyleConstant; import com.cleanroommc.groovyscript.network.NetworkHandler; import com.cleanroommc.groovyscript.network.SReloadScripts; import com.cleanroommc.groovyscript.network.StartLanguageServerPacket; @@ -70,12 +71,10 @@ public GSCommand() { addSubcommand(new InfoLookingCommand()); addSubcommand(new InfoSelfCommand()); + addSubcommand(new SimpleCommand("wiki", (server, sender, args) -> sender.sendMessage( - new TextComponentString("GroovyScript wiki").setStyle(new Style().setColor(TextFormatting.GOLD).setHoverEvent( - new HoverEvent(HoverEvent.Action.SHOW_TEXT, - new TextComponentString("Click to open wiki in browser"))).setClickEvent( - new ClickEvent(ClickEvent.Action.OPEN_URL, "https://cleanroommc.com/groovy-script/")))), "doc", "docs", - "documentation")); + getTextForUrl("GroovyScript wiki", "Click to open wiki in browser", new TextComponentString("https://cleanroommc.com/groovy-script/"))), + "doc", "docs", "documentation")); addSubcommand(new SimpleCommand("generateWiki", (server, sender, args) -> { Documentation.generateWiki(); @@ -104,9 +103,9 @@ public GSCommand() { addSubcommand(new SimpleCommand("deleteScriptCache", (server, sender, args) -> { if (GroovyScript.getSandbox().deleteScriptCache()) { - sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "Deleted groovy script cache")); + sender.sendMessage(new TextComponentString("Deleted groovy script cache").setStyle(StyleConstant.SUCCESS_STYLE)); } else { - sender.sendMessage(new TextComponentString(TextFormatting.RED + "An error occurred while deleting groovy script cache")); + sender.sendMessage(new TextComponentString("An error occurred while deleting groovy script cache").setStyle(StyleConstant.ERROR_STYLE)); } })); @@ -118,7 +117,7 @@ public GSCommand() { addSubcommand(new SimpleCommand("cleanLog", (server, sender, args) -> { GroovyLogImpl.LOG.cleanLog(); - sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "Cleaned Groovy log")); + sender.sendMessage(new TextComponentString("Cleaned Groovy log").setStyle(StyleConstant.SUCCESS_STYLE)); })); if (ModSupport.MEKANISM.isLoaded()) { @@ -153,9 +152,17 @@ public static void postLogFiles(ICommandSender sender) { } public static ITextComponent getTextForFile(String name, String path, ITextComponent hoverText) { - return new TextComponentString(TextFormatting.UNDERLINE + (TextFormatting.GOLD + name)) - .setStyle(new Style() - .setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, path)) + return getTextForClickEvent(name, new ClickEvent(ClickEvent.Action.OPEN_FILE, path), hoverText); + } + + public static ITextComponent getTextForUrl(String name, String url, ITextComponent hoverText) { + return getTextForClickEvent(name, new ClickEvent(ClickEvent.Action.OPEN_URL, url), hoverText); + } + + public static ITextComponent getTextForClickEvent(String name, ClickEvent clickEvent, ITextComponent hoverText) { + return new TextComponentString(name) + .setStyle(new Style().setColor(TextFormatting.GOLD).setUnderlined(true) + .setClickEvent(clickEvent) .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText))); } diff --git a/src/main/java/com/cleanroommc/groovyscript/command/GSMekanismCommand.java b/src/main/java/com/cleanroommc/groovyscript/command/GSMekanismCommand.java index 11b82fe6e..526e0f894 100644 --- a/src/main/java/com/cleanroommc/groovyscript/command/GSMekanismCommand.java +++ b/src/main/java/com/cleanroommc/groovyscript/command/GSMekanismCommand.java @@ -2,6 +2,7 @@ import com.cleanroommc.groovyscript.compat.mods.ModSupport; import com.cleanroommc.groovyscript.compat.mods.mekanism.Mekanism; +import com.cleanroommc.groovyscript.helper.StyleConstant; import mekanism.api.gas.Gas; import mekanism.api.gas.GasRegistry; import mekanism.api.infuse.InfuseRegistry; @@ -10,7 +11,6 @@ import net.minecraft.command.ICommandSender; import net.minecraft.server.MinecraftServer; import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextFormatting; import net.minecraftforge.server.command.CommandTreeBase; import org.jetbrains.annotations.NotNull; @@ -39,7 +39,7 @@ public GSMekanismCommand() { @Override public void execute(@NotNull MinecraftServer server, @NotNull ICommandSender sender, String @NotNull [] args) throws CommandException { if (!ModSupport.MEKANISM.isLoaded()) { - sender.sendMessage(new TextComponentString(TextFormatting.RED + "Mekanism is not loaded!")); + sender.sendMessage(new TextComponentString("Mekanism is not loaded!").setStyle(StyleConstant.ERROR_STYLE)); return; } super.execute(server, sender, args); diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java index 227a6e58e..1ae977347 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java @@ -3,10 +3,9 @@ import com.cleanroommc.groovyscript.api.infocommand.InfoParserPackage; import com.cleanroommc.groovyscript.compat.vanilla.command.infoparser.GenericInfoParser; import com.cleanroommc.groovyscript.core.mixin.jei.ModRegistryAccessor; -import com.cleanroommc.groovyscript.helper.ingredient.GroovyScriptCodeConverter; +import com.cleanroommc.groovyscript.helper.StyleConstant; import mezz.jei.api.recipe.IRecipeCategory; import net.minecraft.item.ItemStack; -import net.minecraft.util.text.TextFormatting; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -30,7 +29,7 @@ public String name() { @Override public String text(@NotNull IRecipeCategory entry, boolean colored, boolean prettyNbt) { - return colored ? GroovyScriptCodeConverter.STRING + entry.getUid() : entry.getUid(); + return colored ? StyleConstant.STRING + entry.getUid() : entry.getUid(); } @Override diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java index fc4a74eb7..17436e7b7 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java @@ -3,6 +3,7 @@ import com.cleanroommc.groovyscript.api.infocommand.InfoParser; import com.cleanroommc.groovyscript.api.infocommand.InfoParserPackage; import com.cleanroommc.groovyscript.command.TextCopyable; +import com.cleanroommc.groovyscript.helper.StyleConstant; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentString; @@ -63,14 +64,14 @@ public ITextComponent hoverTitle() { } /** - * The formatted header of the parser. Uses the {@link #headerStyle}, with hover text from {@link #hoverTitle()}. + * The formatted header of the parser. Uses the {@link StyleConstant#TITLE_STYLE}, with hover text from {@link #hoverTitle()}. * * @param plural if the name should be in {@link #plural()} or singular {@link #name()} form. * @return the header for the parser */ public ITextComponent header(boolean plural) { String name = plural ? plural() : name(); - Style style = headerStyle.createShallowCopy().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverTitle())); + Style style = StyleConstant.TITLE_STYLE.createShallowCopy().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverTitle())); return new TextComponentString(name + ":").setStyle(style); } diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserNBT.java b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserNBT.java index b742d7b7c..380971134 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserNBT.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserNBT.java @@ -1,11 +1,11 @@ package com.cleanroommc.groovyscript.compat.vanilla.command.infoparser; import com.cleanroommc.groovyscript.api.infocommand.InfoParserPackage; +import com.cleanroommc.groovyscript.helper.StyleConstant; import com.cleanroommc.groovyscript.helper.ingredient.NbtHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TextFormatting; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; @@ -34,7 +34,7 @@ public String plural() { } private String trimText() { - return TextFormatting.RED + "(trimmed)"; + return StyleConstant.ERROR + "(trimmed)"; } /** diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java index c5cd3d25a..e65e0e02f 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java @@ -1,8 +1,7 @@ package com.cleanroommc.groovyscript.compat.vanilla.command.infoparser; import com.cleanroommc.groovyscript.api.infocommand.InfoParserPackage; -import com.cleanroommc.groovyscript.helper.ingredient.GroovyScriptCodeConverter; -import net.minecraft.util.text.TextFormatting; +import com.cleanroommc.groovyscript.helper.StyleConstant; import org.jetbrains.annotations.NotNull; public class InfoParserTranslationKey extends GenericInfoParser { @@ -21,7 +20,7 @@ public String name() { @Override public String text(@NotNull String entry, boolean colored, boolean prettyNbt) { - return colored ? GroovyScriptCodeConverter.STRING + entry : entry; + return colored ? StyleConstant.STRING + entry : entry; } @Override diff --git a/src/main/java/com/cleanroommc/groovyscript/core/mixin/groovy/ModuleNodeMixin.java b/src/main/java/com/cleanroommc/groovyscript/core/mixin/groovy/ModuleNodeMixin.java index f053d5485..a000fd171 100644 --- a/src/main/java/com/cleanroommc/groovyscript/core/mixin/groovy/ModuleNodeMixin.java +++ b/src/main/java/com/cleanroommc/groovyscript/core/mixin/groovy/ModuleNodeMixin.java @@ -13,8 +13,6 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.io.File; - @Mixin(value = ModuleNode.class, remap = false) public abstract class ModuleNodeMixin { diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java b/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java new file mode 100644 index 000000000..44371454e --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java @@ -0,0 +1,87 @@ +package com.cleanroommc.groovyscript.helper; + +import net.minecraft.util.text.Style; +import net.minecraft.util.text.TextFormatting; + +/** + * Constant values for formatting colors for the Minecraft chat. + *

+ * Primarily used to format the object mappers into valid code fragments via + * {@link com.cleanroommc.groovyscript.helper.ingredient.GroovyScriptCodeConverter GroovyScriptCodeConverter} + */ +public class StyleConstant { + + /** + * Used for any text that should not be a different color: + * the default text color + */ + public static final TextFormatting BASE = TextFormatting.GRAY; + + /** + * Used for the digits of numbers: + * {@code 0xFF00FF}, {@code 5.0}f + */ + public static final TextFormatting NUMBER = TextFormatting.YELLOW; + + /** + * Used for text within strings: + * '{@code hello}', "{@code world}" + */ + public static final TextFormatting STRING = TextFormatting.AQUA; + + /** + * Used for the object mapper name: + * {@code item}('minecraft:clay'), {@code fluid}('water') + */ + public static final TextFormatting MAPPER = TextFormatting.DARK_GREEN; + + /** + * Used for creating a new object: + * {@code new} Object() + */ + public static final TextFormatting NEW = TextFormatting.LIGHT_PURPLE; + + /** + * Used for class types, casts, and declarations: + * {@code (byte)}, new {@code Object}(), 1.5{@code F} + */ + public static final TextFormatting CLASS = TextFormatting.GOLD; + + /** + * Used for the text of a state where a different outcome could be a warning or an error, + * but this evaluation was not and has succeeded. + */ + public static final TextFormatting SUCCESS = TextFormatting.GREEN; + + /** + * Used for the text of warnings + */ + public static final TextFormatting WARNING = TextFormatting.YELLOW; + + /** + * Used for the text of errors + */ + public static final TextFormatting ERROR = TextFormatting.RED; + + /** + * Used for titles to make them emphasised and keep them distinct from the surrounding text + */ + public static final Style TITLE_STYLE = new Style().setColor(TextFormatting.WHITE).setBold(true); + + /** + * Used for the text of a state where the other outcome could be a warning or an error, + * but this evaluation was not, and works as expected. + */ + public static final Style SUCCESS_STYLE = new Style().setColor(SUCCESS); + + /** + * Used for the text of warnings + */ + public static final Style WARNING_STYLE = new Style().setColor(WARNING); + + /** + * Used for the text of errors + */ + public static final Style ERROR_STYLE = new Style().setColor(ERROR); + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java index 0b5cacdbf..2fe2cca1f 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java @@ -1,6 +1,7 @@ package com.cleanroommc.groovyscript.helper.ingredient; import com.cleanroommc.groovyscript.core.mixin.CreativeTabsAccessor; +import com.cleanroommc.groovyscript.helper.StyleConstant; import com.google.common.collect.Lists; import net.minecraft.block.Block; import net.minecraft.block.properties.IProperty; @@ -14,7 +15,6 @@ import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ResourceLocation; -import net.minecraft.util.text.TextFormatting; import net.minecraft.world.DimensionType; import net.minecraft.world.biome.Biome; import net.minecraftforge.fluids.FluidStack; @@ -26,40 +26,33 @@ public class GroovyScriptCodeConverter { - public static final TextFormatting BASE = TextFormatting.GRAY; - public static final TextFormatting NUMBER = TextFormatting.YELLOW; - public static final TextFormatting STRING = TextFormatting.AQUA; - public static final TextFormatting HANDLER = TextFormatting.DARK_GREEN; - public static final TextFormatting NEW = TextFormatting.LIGHT_PURPLE; - public static final TextFormatting CLASS = TextFormatting.GOLD; - public static String formatNumber(int number, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(NUMBER); + if (colored) builder.append(StyleConstant.NUMBER); builder.append(number); return builder.toString(); } public static String formatString(String target, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append("'"); - if (colored) builder.append(STRING); + if (colored) builder.append(StyleConstant.STRING); builder.append(target); - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append("'"); return builder.toString(); } public static String formatGenericHandler(String handler, String target, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(HANDLER); + if (colored) builder.append(StyleConstant.MAPPER); builder.append(handler); - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append("('"); - if (colored) builder.append(STRING); + if (colored) builder.append(StyleConstant.STRING); builder.append(target); - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append("')"); return builder.toString(); } @@ -67,7 +60,7 @@ public static String formatGenericHandler(String handler, String target, boolean public static String formatMultiple(int amount, boolean colored) { StringBuilder builder = new StringBuilder(); if (amount > 1) { - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append(" * "); builder.append(formatNumber(amount, colored)); } @@ -76,14 +69,14 @@ public static String formatMultiple(int amount, boolean colored) { public static String formatInstantiation(String clazz, List params, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(NEW); + if (colored) builder.append(StyleConstant.NEW); builder.append("new "); - if (colored) builder.append(CLASS); + if (colored) builder.append(StyleConstant.CLASS); builder.append(clazz); - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append("("); - builder.append(String.join((colored ? BASE.toString() : "") + ", ", params)); - if (colored) builder.append(BASE); + builder.append(String.join(colored ? StyleConstant.BASE + ", " : ", ", params)); + if (colored) builder.append(StyleConstant.BASE); builder.append(")"); return builder.toString(); } @@ -102,7 +95,7 @@ public static String formatNBTTag(NBTTagCompound tag, boolean colored, boolean p if (tag != null) { builder.append(".withNbt("); builder.append(NbtHelper.toGroovyCode(tag, prettyNbt, colored)); - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append(")"); } return builder.toString(); @@ -110,27 +103,27 @@ public static String formatNBTTag(NBTTagCompound tag, boolean colored, boolean p private static String getSingleItemStack(ItemStack itemStack, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(HANDLER); + if (colored) builder.append(StyleConstant.MAPPER); builder.append("item"); - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append("('"); - if (colored) builder.append(STRING); + if (colored) builder.append(StyleConstant.STRING); builder.append(itemStack.getItem().getRegistryName()); // code is more complex than strictly needed here to allow using the wildcard if (itemStack.getMetadata() == Short.MAX_VALUE) { builder.append(":"); builder.append("*"); - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append("'"); } else if (itemStack.getMetadata() == 0) { - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append("'"); } else { - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append("'"); builder.append(", "); builder.append(formatNumber(itemStack.getMetadata(), colored)); - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); } builder.append(")"); return builder.toString(); @@ -204,26 +197,26 @@ public static String asGroovyCode(Block state, boolean colored) { @SuppressWarnings("all") public static String asGroovyCode(IBlockState state, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(HANDLER); + if (colored) builder.append(StyleConstant.MAPPER); builder.append("blockstate"); - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append("('"); - if (colored) builder.append(STRING); + if (colored) builder.append(StyleConstant.STRING); builder.append(state.getBlock().getRegistryName()); - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append("'"); if (!state.getProperties().isEmpty()) { for (Map.Entry, Comparable> entry : state.getProperties().entrySet()) { IProperty property = entry.getKey(); - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append(", ").append("'"); - if (colored) builder.append(NUMBER); + if (colored) builder.append(StyleConstant.NUMBER); builder.append(property.getName()); - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append("="); - if (colored) builder.append(NUMBER); + if (colored) builder.append(StyleConstant.NUMBER); builder.append(property.getName(entry.getValue())); - if (colored) builder.append(BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append("'"); } } diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java index 67eb6a239..ff5138083 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java @@ -1,5 +1,6 @@ package com.cleanroommc.groovyscript.helper.ingredient; +import com.cleanroommc.groovyscript.helper.StyleConstant; import com.cleanroommc.groovyscript.sandbox.expand.LambdaClosure; import groovy.lang.Closure; import net.minecraft.nbt.*; @@ -80,73 +81,73 @@ public static NBTBase toNbt(Object o) { public static String toGroovyCode(NBTTagByte nbt, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(GroovyScriptCodeConverter.CLASS); + if (colored) builder.append(StyleConstant.CLASS); builder.append("(byte) "); - if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); + if (colored) builder.append(StyleConstant.NUMBER); builder.append(nbt.getByte()); return builder.toString(); } public static String toGroovyCode(NBTTagShort nbt, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(GroovyScriptCodeConverter.CLASS); + if (colored) builder.append(StyleConstant.CLASS); builder.append("(short) "); - if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); + if (colored) builder.append(StyleConstant.NUMBER); builder.append(nbt.getShort()); return builder.toString(); } public static String toGroovyCode(NBTTagInt nbt, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); + if (colored) builder.append(StyleConstant.NUMBER); builder.append(nbt.getInt()); return builder.toString(); } public static String toGroovyCode(NBTTagLong nbt, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); + if (colored) builder.append(StyleConstant.NUMBER); builder.append(nbt.getLong()); - if (colored) builder.append(GroovyScriptCodeConverter.CLASS); + if (colored) builder.append(StyleConstant.CLASS); builder.append("L"); return builder.toString(); } public static String toGroovyCode(NBTTagFloat nbt, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); + if (colored) builder.append(StyleConstant.NUMBER); builder.append(nbt.getFloat()); - if (colored) builder.append(GroovyScriptCodeConverter.CLASS); + if (colored) builder.append(StyleConstant.CLASS); builder.append("F"); return builder.toString(); } public static String toGroovyCode(NBTTagDouble nbt, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); + if (colored) builder.append(StyleConstant.NUMBER); builder.append(nbt.getDouble()); - if (colored) builder.append(GroovyScriptCodeConverter.CLASS); + if (colored) builder.append(StyleConstant.CLASS); builder.append("D"); return builder.toString(); } public static String toGroovyCode(NBTTagByteArray nbt, int indent, boolean pretty, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(GroovyScriptCodeConverter.BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append('['); if (!nbt.isEmpty()) { newLine(builder, indent, pretty); for (byte value : nbt.getByteArray()) { - if (colored) builder.append(GroovyScriptCodeConverter.CLASS); + if (colored) builder.append(StyleConstant.CLASS); builder.append("(byte) "); - if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); + if (colored) builder.append(StyleConstant.NUMBER); builder.append(value); - if (colored) builder.append(GroovyScriptCodeConverter.BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append(", "); } builder.delete(builder.length() - 2, builder.length()); newLine(builder, indent, pretty); - if (colored) builder.append(GroovyScriptCodeConverter.BASE); + if (colored) builder.append(StyleConstant.BASE); } builder.append(']'); return builder.toString(); @@ -154,26 +155,26 @@ public static String toGroovyCode(NBTTagByteArray nbt, int indent, boolean prett public static String toGroovyCode(NBTTagString nbt, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(GroovyScriptCodeConverter.STRING); + if (colored) builder.append(StyleConstant.STRING); builder.append('\'').append(nbt.getString()).append('\''); return builder.toString(); } public static String toGroovyCode(NBTTagList nbt, int indent, boolean pretty, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(GroovyScriptCodeConverter.BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append('['); if (!nbt.isEmpty()) { int internalIndent = indent + 1; for (NBTBase nbtBase : nbt) { newLine(builder, internalIndent, pretty); builder.append(toGroovyCode(nbtBase, internalIndent, pretty, colored)); - if (colored) builder.append(GroovyScriptCodeConverter.BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append(", "); } builder.delete(builder.length() - 2, builder.length()); newLine(builder, indent, pretty); - if (colored) builder.append(GroovyScriptCodeConverter.BASE); + if (colored) builder.append(StyleConstant.BASE); } builder.append(']'); return builder.toString(); @@ -185,23 +186,23 @@ public static String toGroovyCode(NBTTagCompound nbt, boolean pretty, boolean co public static String toGroovyCode(NBTTagCompound nbt, int indent, boolean pretty, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(GroovyScriptCodeConverter.BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append('['); if (!nbt.isEmpty()) { int internalIndent = indent + 1; for (String key : nbt.getKeySet()) { newLine(builder, internalIndent, pretty); - if (colored) builder.append(GroovyScriptCodeConverter.NEW); + if (colored) builder.append(StyleConstant.NEW); builder.append('\'').append(key).append('\''); - if (colored) builder.append(GroovyScriptCodeConverter.BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append(": "); builder.append(toGroovyCode(nbt.getTag(key), internalIndent, pretty, colored)); - if (colored) builder.append(GroovyScriptCodeConverter.BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append(", "); } builder.delete(builder.length() - 2, builder.length()); newLine(builder, indent, pretty); - if (colored) builder.append(GroovyScriptCodeConverter.BASE); + if (colored) builder.append(StyleConstant.BASE); } builder.append(']'); return builder.toString(); @@ -209,19 +210,19 @@ public static String toGroovyCode(NBTTagCompound nbt, int indent, boolean pretty public static String toGroovyCode(NBTTagIntArray nbt, int indent, boolean pretty, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(GroovyScriptCodeConverter.BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append('['); if (!nbt.isEmpty()) { newLine(builder, indent, pretty); for (int value : nbt.getIntArray()) { - if (colored) builder.append(GroovyScriptCodeConverter.NUMBER); + if (colored) builder.append(StyleConstant.NUMBER); builder.append(value); - if (colored) builder.append(GroovyScriptCodeConverter.BASE); + if (colored) builder.append(StyleConstant.BASE); builder.append(", "); } builder.delete(builder.length() - 2, builder.length()); newLine(builder, indent, pretty); - if (colored) builder.append(GroovyScriptCodeConverter.BASE); + if (colored) builder.append(StyleConstant.BASE); } builder.append(']'); return builder.toString(); diff --git a/src/main/java/com/cleanroommc/groovyscript/network/StartLanguageServerPacket.java b/src/main/java/com/cleanroommc/groovyscript/network/StartLanguageServerPacket.java index fe6dfb5a5..1e4aec523 100644 --- a/src/main/java/com/cleanroommc/groovyscript/network/StartLanguageServerPacket.java +++ b/src/main/java/com/cleanroommc/groovyscript/network/StartLanguageServerPacket.java @@ -1,11 +1,11 @@ package com.cleanroommc.groovyscript.network; import com.cleanroommc.groovyscript.GroovyScript; +import com.cleanroommc.groovyscript.helper.StyleConstant; import net.minecraft.client.Minecraft; import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.network.PacketBuffer; import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextFormatting; public class StartLanguageServerPacket implements IPacket { @@ -18,9 +18,9 @@ public void decode(PacketBuffer buf) {} @Override public IPacket executeClient(NetHandlerPlayClient handler) { if (GroovyScript.runLanguageServer()) { - Minecraft.getMinecraft().player.sendMessage(new TextComponentString(TextFormatting.GREEN + "Starting language server")); + Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Starting language server").setStyle(StyleConstant.SUCCESS_STYLE)); } else { - Minecraft.getMinecraft().player.sendMessage(new TextComponentString(TextFormatting.YELLOW + "Language server is already running")); + Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Language server is already running").setStyle(StyleConstant.WARNING_STYLE)); } return null; } From 7692e2e9cd1cffb35dbca71fa1654355a75552ae Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Thu, 10 Oct 2024 10:22:01 -0700 Subject: [PATCH 03/17] fix minor mistakes --- src/main/java/com/cleanroommc/groovyscript/GroovyScript.java | 1 - .../cleanroommc/groovyscript/api/infocommand/InfoParser.java | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java b/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java index 4490aff8b..d140d1974 100644 --- a/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java +++ b/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java @@ -279,7 +279,6 @@ public static void postScriptRunResult(ICommandSender sender, boolean onlyLogFai if (running) { String s = packmode ? "changes packmode" : "reloaded scripts"; sender.sendMessage(new TextComponentString("Successfully " + s).setStyle(StyleConstant.SUCCESS_STYLE).appendSibling(new TextComponentString(" in " + time + "ms"))); - sender.sendMessage(new TextComponentString(TextFormatting.GREEN + "Successfully " + s + TextFormatting.WHITE + " in " + time + "ms")); } else { sender.sendMessage(new TextComponentString("No syntax errors found :)").setStyle(StyleConstant.SUCCESS_STYLE)); } diff --git a/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParser.java b/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParser.java index 7b9975be8..5ce749d77 100644 --- a/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParser.java +++ b/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParser.java @@ -1,16 +1,17 @@ package com.cleanroommc.groovyscript.api.infocommand; +import com.cleanroommc.groovyscript.helper.StyleConstant; import net.minecraft.util.text.Style; -import net.minecraft.util.text.TextFormatting; public interface InfoParser { /** * The style for any parser header - bold and light purple. + * * @deprecated use {@link com.cleanroommc.groovyscript.helper.StyleConstant#TITLE_STYLE} */ @Deprecated - Style headerStyle = new Style().setColor(TextFormatting.WHITE).setBold(true); + Style headerStyle = StyleConstant.TITLE_STYLE; /** * Priority of the parser for determining the order they are logged in chat, From ac02797d2618192cedae61b6d94395fcae68aba4 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Thu, 10 Oct 2024 12:47:35 -0700 Subject: [PATCH 04/17] change nbt key coloration --- .../groovyscript/helper/ingredient/NbtHelper.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java index ff5138083..de84d7801 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java @@ -192,9 +192,12 @@ public static String toGroovyCode(NBTTagCompound nbt, int indent, boolean pretty int internalIndent = indent + 1; for (String key : nbt.getKeySet()) { newLine(builder, internalIndent, pretty); - if (colored) builder.append(StyleConstant.NEW); - builder.append('\'').append(key).append('\''); if (colored) builder.append(StyleConstant.BASE); + builder.append("'"); + if (colored) builder.append(StyleConstant.STRING); + builder.append(key); + if (colored) builder.append(StyleConstant.BASE); + builder.append("'"); builder.append(": "); builder.append(toGroovyCode(nbt.getTag(key), internalIndent, pretty, colored)); if (colored) builder.append(StyleConstant.BASE); From 4343b734f75d31f1b6e763fae2343513d8043305 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Thu, 10 Oct 2024 12:47:47 -0700 Subject: [PATCH 05/17] color nbt tag string properly --- .../groovyscript/helper/ingredient/NbtHelper.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java index de84d7801..45e9c5a06 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java @@ -155,8 +155,12 @@ public static String toGroovyCode(NBTTagByteArray nbt, int indent, boolean prett public static String toGroovyCode(NBTTagString nbt, boolean colored) { StringBuilder builder = new StringBuilder(); + if (colored) builder.append(StyleConstant.BASE); + builder.append("'"); if (colored) builder.append(StyleConstant.STRING); - builder.append('\'').append(nbt.getString()).append('\''); + builder.append(nbt.getString()); + if (colored) builder.append(StyleConstant.BASE); + builder.append("'"); return builder.toString(); } From 89c1be7e18a1a19ced3b8bde90bf7489db05d9f2 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:14:32 -0700 Subject: [PATCH 06/17] adjust blockstate appearance --- .../helper/ingredient/GroovyScriptCodeConverter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java index 2fe2cca1f..9ec16f1e8 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java @@ -210,11 +210,11 @@ public static String asGroovyCode(IBlockState state, boolean colored) { IProperty property = entry.getKey(); if (colored) builder.append(StyleConstant.BASE); builder.append(", ").append("'"); - if (colored) builder.append(StyleConstant.NUMBER); + if (colored) builder.append(StyleConstant.NEW); builder.append(property.getName()); if (colored) builder.append(StyleConstant.BASE); builder.append("="); - if (colored) builder.append(StyleConstant.NUMBER); + if (colored) builder.append(StyleConstant.CLASS); builder.append(property.getName(entry.getValue())); if (colored) builder.append(StyleConstant.BASE); builder.append("'"); From c1826cf98bc4b0f4f1ffade7b9448ccaa2f68249 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:19:57 -0700 Subject: [PATCH 07/17] change color for mapper and string, improve javadoc --- .../groovyscript/helper/StyleConstant.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java b/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java index 44371454e..91b604101 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java @@ -19,31 +19,31 @@ public class StyleConstant { /** * Used for the digits of numbers: - * {@code 0xFF00FF}, {@code 5.0}f + * 0xFF00FF, 5.0f, 347 */ public static final TextFormatting NUMBER = TextFormatting.YELLOW; /** * Used for text within strings: - * '{@code hello}', "{@code world}" + * 'hello', "world" */ - public static final TextFormatting STRING = TextFormatting.AQUA; + public static final TextFormatting STRING = TextFormatting.GREEN; /** * Used for the object mapper name: - * {@code item}('minecraft:clay'), {@code fluid}('water') + * item('minecraft:clay'), fluid('water') */ - public static final TextFormatting MAPPER = TextFormatting.DARK_GREEN; + public static final TextFormatting MAPPER = TextFormatting.AQUA; /** * Used for creating a new object: - * {@code new} Object() + * new Object(), key=value */ public static final TextFormatting NEW = TextFormatting.LIGHT_PURPLE; /** * Used for class types, casts, and declarations: - * {@code (byte)}, new {@code Object}(), 1.5{@code F} + * (byte), new Object(), 1.5F */ public static final TextFormatting CLASS = TextFormatting.GOLD; From 1a891acd92b90e2675b4699bfdcb7e7cf21fe369 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:22:40 -0700 Subject: [PATCH 08/17] fix JEI tab not working based on stack size --- .../groovyscript/compat/mods/jei/InfoParserTab.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java index 1ae977347..abfbccdd9 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java @@ -6,6 +6,7 @@ import com.cleanroommc.groovyscript.helper.StyleConstant; import mezz.jei.api.recipe.IRecipeCategory; import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -41,7 +42,7 @@ public void parse(InfoParserPackage info) { List allowed = ((ModRegistryAccessor) JeiPlugin.modRegistry).getRecipeCatalysts() .entrySet() .stream() - .filter(entry -> entry.getValue().stream().anyMatch(x -> x instanceof ItemStack stack && ItemStack.areItemStacksEqual(stack, info.getStack()))) + .filter(entry -> entry.getValue().stream().anyMatch(x -> x instanceof ItemStack stack && OreDictionary.itemMatches(stack, info.getStack(), false))) .map(Map.Entry::getKey) .collect(Collectors.toList()); List list = JeiPlugin.recipeRegistry.getRecipeCategories(allowed); From 534378a7095f5b9099b8dff15598d97be3ddaca0 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Thu, 10 Oct 2024 13:23:01 -0700 Subject: [PATCH 09/17] make NBT letters be lowercase --- .../groovyscript/helper/ingredient/NbtHelper.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java index 45e9c5a06..f2a6787ac 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/NbtHelper.java @@ -109,7 +109,7 @@ public static String toGroovyCode(NBTTagLong nbt, boolean colored) { if (colored) builder.append(StyleConstant.NUMBER); builder.append(nbt.getLong()); if (colored) builder.append(StyleConstant.CLASS); - builder.append("L"); + builder.append("l"); return builder.toString(); } @@ -118,7 +118,7 @@ public static String toGroovyCode(NBTTagFloat nbt, boolean colored) { if (colored) builder.append(StyleConstant.NUMBER); builder.append(nbt.getFloat()); if (colored) builder.append(StyleConstant.CLASS); - builder.append("F"); + builder.append("f"); return builder.toString(); } @@ -127,7 +127,7 @@ public static String toGroovyCode(NBTTagDouble nbt, boolean colored) { if (colored) builder.append(StyleConstant.NUMBER); builder.append(nbt.getDouble()); if (colored) builder.append(StyleConstant.CLASS); - builder.append("D"); + builder.append("d"); return builder.toString(); } From b2dd64de5cd5a295f33cc78cd29871c98d600af2 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Fri, 11 Oct 2024 02:49:40 -0700 Subject: [PATCH 10/17] convert mapper color to be method color --- .../groovyscript/helper/StyleConstant.java | 6 ++--- .../ingredient/GroovyScriptCodeConverter.java | 22 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java b/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java index 91b604101..07ffad008 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java @@ -30,10 +30,10 @@ public class StyleConstant { public static final TextFormatting STRING = TextFormatting.GREEN; /** - * Used for the object mapper name: - * item('minecraft:clay'), fluid('water') + * Used for method names, most commonly the object mapper name: + * call(), item('minecraft:clay'), fluid('water') */ - public static final TextFormatting MAPPER = TextFormatting.AQUA; + public static final TextFormatting METHOD = TextFormatting.AQUA; /** * Used for creating a new object: diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java index 9ec16f1e8..04741c784 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/ingredient/GroovyScriptCodeConverter.java @@ -46,7 +46,7 @@ public static String formatString(String target, boolean colored) { public static String formatGenericHandler(String handler, String target, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(StyleConstant.MAPPER); + if (colored) builder.append(StyleConstant.METHOD); builder.append(handler); if (colored) builder.append(StyleConstant.BASE); builder.append("('"); @@ -58,12 +58,11 @@ public static String formatGenericHandler(String handler, String target, boolean } public static String formatMultiple(int amount, boolean colored) { + if (amount <= 1) return ""; StringBuilder builder = new StringBuilder(); - if (amount > 1) { - if (colored) builder.append(StyleConstant.BASE); - builder.append(" * "); - builder.append(formatNumber(amount, colored)); - } + if (colored) builder.append(StyleConstant.BASE); + builder.append(" * "); + builder.append(formatNumber(amount, colored)); return builder.toString(); } @@ -93,7 +92,12 @@ public static String formatForgeRegistryImpl(String handler, IForgeRegistryEntry public static String formatNBTTag(NBTTagCompound tag, boolean colored, boolean prettyNbt) { StringBuilder builder = new StringBuilder(); if (tag != null) { - builder.append(".withNbt("); + if (colored) builder.append(StyleConstant.BASE); + builder.append("."); + if (colored) builder.append(StyleConstant.METHOD); + builder.append("withNbt"); + if (colored) builder.append(StyleConstant.BASE); + builder.append("("); builder.append(NbtHelper.toGroovyCode(tag, prettyNbt, colored)); if (colored) builder.append(StyleConstant.BASE); builder.append(")"); @@ -103,7 +107,7 @@ public static String formatNBTTag(NBTTagCompound tag, boolean colored, boolean p private static String getSingleItemStack(ItemStack itemStack, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(StyleConstant.MAPPER); + if (colored) builder.append(StyleConstant.METHOD); builder.append("item"); if (colored) builder.append(StyleConstant.BASE); builder.append("('"); @@ -197,7 +201,7 @@ public static String asGroovyCode(Block state, boolean colored) { @SuppressWarnings("all") public static String asGroovyCode(IBlockState state, boolean colored) { StringBuilder builder = new StringBuilder(); - if (colored) builder.append(StyleConstant.MAPPER); + if (colored) builder.append(StyleConstant.METHOD); builder.append("blockstate"); if (colored) builder.append(StyleConstant.BASE); builder.append("('"); From bde77516a601b0b13e2d49023184bab02d996328 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Fri, 11 Oct 2024 07:40:54 -0700 Subject: [PATCH 11/17] convert style to methods --- .../cleanroommc/groovyscript/GroovyScript.java | 10 +++++----- .../api/infocommand/InfoParser.java | 4 ++-- .../groovyscript/command/BaseInfoCommand.java | 6 +++--- .../groovyscript/command/GSCommand.java | 6 +++--- .../groovyscript/command/GSMekanismCommand.java | 2 +- .../command/infoparser/GenericInfoParser.java | 4 ++-- .../groovyscript/helper/StyleConstant.java | 17 +++++++++++++---- .../network/StartLanguageServerPacket.java | 4 ++-- 8 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java b/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java index d140d1974..1dd10ea44 100644 --- a/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java +++ b/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java @@ -278,21 +278,21 @@ public static void postScriptRunResult(ICommandSender sender, boolean onlyLogFai if (!onlyLogFails) { if (running) { String s = packmode ? "changes packmode" : "reloaded scripts"; - sender.sendMessage(new TextComponentString("Successfully " + s).setStyle(StyleConstant.SUCCESS_STYLE).appendSibling(new TextComponentString(" in " + time + "ms"))); + sender.sendMessage(new TextComponentString("Successfully " + s).setStyle(StyleConstant.getSuccessStyle()).appendSibling(new TextComponentString(" in " + time + "ms"))); } else { - sender.sendMessage(new TextComponentString("No syntax errors found :)").setStyle(StyleConstant.SUCCESS_STYLE)); + sender.sendMessage(new TextComponentString("No syntax errors found :)").setStyle(StyleConstant.getSuccessStyle())); } } } else { String executing = running ? "running" : "checking"; - sender.sendMessage(new TextComponentString("Found " + errors.size() + " errors while " + executing + " scripts").setStyle(StyleConstant.ERROR_STYLE)); + sender.sendMessage(new TextComponentString("Found " + errors.size() + " errors while " + executing + " scripts").setStyle(StyleConstant.getErrorStyle())); int n = errors.size(); if (errors.size() >= 10) { - sender.sendMessage(new TextComponentString("Displaying the first 7 errors:").setStyle(StyleConstant.TITLE_STYLE)); + sender.sendMessage(new TextComponentString("Displaying the first 7 errors:").setStyle(StyleConstant.getTitleStyle())); n = 7; } for (int i = 0; i < n; i++) { - sender.sendMessage(new TextComponentString(errors.get(i)).setStyle(StyleConstant.ERROR_STYLE)); + sender.sendMessage(new TextComponentString(errors.get(i)).setStyle(StyleConstant.getErrorStyle())); } GSCommand.postLogFiles(sender); } diff --git a/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParser.java b/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParser.java index 5ce749d77..a02cf8135 100644 --- a/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParser.java +++ b/src/main/java/com/cleanroommc/groovyscript/api/infocommand/InfoParser.java @@ -8,10 +8,10 @@ public interface InfoParser { /** * The style for any parser header - bold and light purple. * - * @deprecated use {@link com.cleanroommc.groovyscript.helper.StyleConstant#TITLE_STYLE} + * @deprecated use {@link com.cleanroommc.groovyscript.helper.StyleConstant#getTitleStyle()} */ @Deprecated - Style headerStyle = StyleConstant.TITLE_STYLE; + Style headerStyle = StyleConstant.getTitleStyle(); /** * Priority of the parser for determining the order they are logged in chat, diff --git a/src/main/java/com/cleanroommc/groovyscript/command/BaseInfoCommand.java b/src/main/java/com/cleanroommc/groovyscript/command/BaseInfoCommand.java index b9214fec2..167d87bfd 100644 --- a/src/main/java/com/cleanroommc/groovyscript/command/BaseInfoCommand.java +++ b/src/main/java/com/cleanroommc/groovyscript/command/BaseInfoCommand.java @@ -110,14 +110,14 @@ public int getRequiredPermissionLevel() { protected void print(EntityPlayer player, List messages, List argList) { if (messages.isEmpty()) { if (argList.isEmpty()) { - player.sendMessage(new TextComponentString(String.format("Couldn't find %s!", targetDescription())).setStyle(StyleConstant.ERROR_STYLE)); + player.sendMessage(new TextComponentString(String.format("Couldn't find %s!", targetDescription())).setStyle(StyleConstant.getErrorStyle())); } else { - player.sendMessage(new TextComponentString(String.format("Couldn't find %s matching the given arguments!", targetDescription())).setStyle(StyleConstant.ERROR_STYLE)); + player.sendMessage(new TextComponentString(String.format("Couldn't find %s matching the given arguments!", targetDescription())).setStyle(StyleConstant.getErrorStyle())); player.sendMessage(new TextComponentString("The following arguments were provided: " + String.join(", ", argList))); } } else { // have a horizontal bar to improve readability when running multiple consecutive info commands - player.sendMessage(new TextComponentString("================================").setStyle(new Style().setColor(TextFormatting.GOLD))); + player.sendMessage(new TextComponentString("================================").setStyle(StyleConstant.getEmphasisStyle())); messages.forEach(player::sendMessage); } } diff --git a/src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java b/src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java index e6f0020c5..ffccd64b5 100644 --- a/src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java +++ b/src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java @@ -103,9 +103,9 @@ public GSCommand() { addSubcommand(new SimpleCommand("deleteScriptCache", (server, sender, args) -> { if (GroovyScript.getSandbox().deleteScriptCache()) { - sender.sendMessage(new TextComponentString("Deleted groovy script cache").setStyle(StyleConstant.SUCCESS_STYLE)); + sender.sendMessage(new TextComponentString("Deleted groovy script cache").setStyle(StyleConstant.getSuccessStyle())); } else { - sender.sendMessage(new TextComponentString("An error occurred while deleting groovy script cache").setStyle(StyleConstant.ERROR_STYLE)); + sender.sendMessage(new TextComponentString("An error occurred while deleting groovy script cache").setStyle(StyleConstant.getErrorStyle())); } })); @@ -117,7 +117,7 @@ public GSCommand() { addSubcommand(new SimpleCommand("cleanLog", (server, sender, args) -> { GroovyLogImpl.LOG.cleanLog(); - sender.sendMessage(new TextComponentString("Cleaned Groovy log").setStyle(StyleConstant.SUCCESS_STYLE)); + sender.sendMessage(new TextComponentString("Cleaned Groovy log").setStyle(StyleConstant.getSuccessStyle())); })); if (ModSupport.MEKANISM.isLoaded()) { diff --git a/src/main/java/com/cleanroommc/groovyscript/command/GSMekanismCommand.java b/src/main/java/com/cleanroommc/groovyscript/command/GSMekanismCommand.java index 526e0f894..ccfc8b5a1 100644 --- a/src/main/java/com/cleanroommc/groovyscript/command/GSMekanismCommand.java +++ b/src/main/java/com/cleanroommc/groovyscript/command/GSMekanismCommand.java @@ -39,7 +39,7 @@ public GSMekanismCommand() { @Override public void execute(@NotNull MinecraftServer server, @NotNull ICommandSender sender, String @NotNull [] args) throws CommandException { if (!ModSupport.MEKANISM.isLoaded()) { - sender.sendMessage(new TextComponentString("Mekanism is not loaded!").setStyle(StyleConstant.ERROR_STYLE)); + sender.sendMessage(new TextComponentString("Mekanism is not loaded!").setStyle(StyleConstant.getErrorStyle())); return; } super.execute(server, sender, args); diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java index 17436e7b7..b7f661973 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java @@ -64,14 +64,14 @@ public ITextComponent hoverTitle() { } /** - * The formatted header of the parser. Uses the {@link StyleConstant#TITLE_STYLE}, with hover text from {@link #hoverTitle()}. + * The formatted header of the parser. Uses the {@link StyleConstant#getTitleStyle()}, with hover text from {@link #hoverTitle()}. * * @param plural if the name should be in {@link #plural()} or singular {@link #name()} form. * @return the header for the parser */ public ITextComponent header(boolean plural) { String name = plural ? plural() : name(); - Style style = StyleConstant.TITLE_STYLE.createShallowCopy().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverTitle())); + Style style = StyleConstant.getTitleStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverTitle())); return new TextComponentString(name + ":").setStyle(style); } diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java b/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java index 07ffad008..e1937b687 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java @@ -66,22 +66,31 @@ public class StyleConstant { /** * Used for titles to make them emphasised and keep them distinct from the surrounding text */ - public static final Style TITLE_STYLE = new Style().setColor(TextFormatting.WHITE).setBold(true); + public static Style getTitleStyle() { + return new Style().setColor(TextFormatting.WHITE).setBold(true); + } + /** * Used for the text of a state where the other outcome could be a warning or an error, * but this evaluation was not, and works as expected. */ - public static final Style SUCCESS_STYLE = new Style().setColor(SUCCESS); + public static Style getSuccessStyle() { + return new Style().setColor(SUCCESS); + } /** * Used for the text of warnings */ - public static final Style WARNING_STYLE = new Style().setColor(WARNING); + public static Style getWarningStyle() { + return new Style().setColor(WARNING); + } /** * Used for the text of errors */ - public static final Style ERROR_STYLE = new Style().setColor(ERROR); + public static Style getErrorStyle() { + return new Style().setColor(ERROR); + } } diff --git a/src/main/java/com/cleanroommc/groovyscript/network/StartLanguageServerPacket.java b/src/main/java/com/cleanroommc/groovyscript/network/StartLanguageServerPacket.java index 1e4aec523..35fdcb4f4 100644 --- a/src/main/java/com/cleanroommc/groovyscript/network/StartLanguageServerPacket.java +++ b/src/main/java/com/cleanroommc/groovyscript/network/StartLanguageServerPacket.java @@ -18,9 +18,9 @@ public void decode(PacketBuffer buf) {} @Override public IPacket executeClient(NetHandlerPlayClient handler) { if (GroovyScript.runLanguageServer()) { - Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Starting language server").setStyle(StyleConstant.SUCCESS_STYLE)); + Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Starting language server").setStyle(StyleConstant.getSuccessStyle())); } else { - Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Language server is already running").setStyle(StyleConstant.WARNING_STYLE)); + Minecraft.getMinecraft().player.sendMessage(new TextComponentString("Language server is already running").setStyle(StyleConstant.getWarningStyle())); } return null; } From bd7a7cdfa751a2fd1fea63dbc1c7072ef46146ea Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Fri, 11 Oct 2024 08:45:12 -0700 Subject: [PATCH 12/17] make copy text be colored --- .../groovyscript/GroovyScript.java | 7 +++--- .../groovyscript/command/BaseInfoCommand.java | 2 -- .../groovyscript/command/GSCommand.java | 4 +-- .../groovyscript/command/TextCopyable.java | 25 ++++++++----------- .../command/infoparser/GenericInfoParser.java | 2 +- .../command/infoparser/InfoParserNBT.java | 2 +- .../groovyscript/helper/StyleConstant.java | 7 ++++++ .../assets/groovyscript/lang/en_us.lang | 2 +- 8 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java b/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java index 1dd10ea44..d0a53de37 100644 --- a/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java +++ b/src/main/java/com/cleanroommc/groovyscript/GroovyScript.java @@ -181,9 +181,10 @@ public static long runGroovyScriptsInLoader(LoadStage loadStage) { public void onPostInit(FMLPostInitializationEvent event) { CustomClickAction.registerAction("copy", value -> { GuiScreen.setClipboardString(value); - Minecraft.getMinecraft().player.sendMessage(new TextComponentTranslation("groovyscript.command.copy.copied_start") - .appendSibling(new TextComponentString(value).setStyle(new Style().setColor(TextFormatting.GOLD))) - .appendSibling(new TextComponentTranslation("groovyscript.command.copy.copied_end"))); + var message = new TextComponentTranslation("groovyscript.command.copy.copied_start").setStyle(StyleConstant.getEmphasisStyle()) + .appendSibling(new TextComponentString(value).setStyle(new Style().setColor(TextFormatting.RESET))) + .appendSibling(new TextComponentTranslation("groovyscript.command.copy.copied_end").setStyle(StyleConstant.getEmphasisStyle())); + Minecraft.getMinecraft().player.sendMessage(message); }); } diff --git a/src/main/java/com/cleanroommc/groovyscript/command/BaseInfoCommand.java b/src/main/java/com/cleanroommc/groovyscript/command/BaseInfoCommand.java index 167d87bfd..75b809c05 100644 --- a/src/main/java/com/cleanroommc/groovyscript/command/BaseInfoCommand.java +++ b/src/main/java/com/cleanroommc/groovyscript/command/BaseInfoCommand.java @@ -16,9 +16,7 @@ import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.Style; import net.minecraft.util.text.TextComponentString; -import net.minecraft.util.text.TextFormatting; import net.minecraftforge.common.MinecraftForge; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java b/src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java index ffccd64b5..2998fa18e 100644 --- a/src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java +++ b/src/main/java/com/cleanroommc/groovyscript/command/GSCommand.java @@ -16,9 +16,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.MinecraftServer; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.Style; 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 net.minecraftforge.server.command.CommandTreeBase; @@ -161,7 +159,7 @@ public static ITextComponent getTextForUrl(String name, String url, ITextCompone public static ITextComponent getTextForClickEvent(String name, ClickEvent clickEvent, ITextComponent hoverText) { return new TextComponentString(name) - .setStyle(new Style().setColor(TextFormatting.GOLD).setUnderlined(true) + .setStyle(StyleConstant.getEmphasisStyle().setUnderlined(true) .setClickEvent(clickEvent) .setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText))); } diff --git a/src/main/java/com/cleanroommc/groovyscript/command/TextCopyable.java b/src/main/java/com/cleanroommc/groovyscript/command/TextCopyable.java index 9ee1d124a..8eec7a575 100644 --- a/src/main/java/com/cleanroommc/groovyscript/command/TextCopyable.java +++ b/src/main/java/com/cleanroommc/groovyscript/command/TextCopyable.java @@ -1,27 +1,28 @@ package com.cleanroommc.groovyscript.command; +import com.cleanroommc.groovyscript.helper.StyleConstant; import net.minecraft.util.text.*; import net.minecraft.util.text.event.HoverEvent; public class TextCopyable { - public static Builder string(java.lang.String copyText, java.lang.String msg) { + public static Builder string(String copyText, String msg) { return new Builder(copyText, msg); } - public static Builder translation(java.lang.String copyText, java.lang.String msg, Object... args) { + public static Builder translation(String copyText, String msg, Object... args) { return new Builder(copyText, msg).translate(args); } public static class Builder { - private final java.lang.String copyText; - private final java.lang.String msg; + private final String copyText; + private final String msg; private Object[] args; private ITextComponent hoverMsg; - public Builder(java.lang.String copyText, java.lang.String msg) { - this.copyText = TextFormatting.getTextWithoutFormattingCodes(copyText); + public Builder(String copyText, String msg) { + this.copyText = copyText; this.msg = msg; } @@ -33,16 +34,12 @@ public Builder translate(Object... args) { public ITextComponent build() { Style style = new Style(); if (hoverMsg == null) { - hoverMsg = new TextComponentTranslation("groovyscript.command.copy.hover") - .appendSibling(new TextComponentString(" " + copyText).setStyle(new Style().setColor(TextFormatting.GOLD))); + hoverMsg = new TextComponentTranslation("groovyscript.command.copy.hover").setStyle(StyleConstant.getEmphasisStyle()) + .appendSibling(new TextComponentString(" " + copyText)); } style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverMsg)); - style.setClickEvent(CustomClickAction.makeCopyEvent(copyText)); - ITextComponent textComponent; - if (args == null) - textComponent = new TextComponentString(msg); - else - textComponent = new TextComponentTranslation(msg, args); + style.setClickEvent(CustomClickAction.makeCopyEvent(TextFormatting.getTextWithoutFormattingCodes(copyText))); + ITextComponent textComponent = args == null ? new TextComponentString(msg) : new TextComponentTranslation(msg, args); textComponent.setStyle(style); return textComponent; } diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java index b7f661973..4f7e42a41 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java @@ -117,7 +117,7 @@ public String msg(@NotNull T entry, boolean prettyNbt) { * @return the text that is copied when clicking on the message */ public String copyText(@NotNull T entry, boolean prettyNbt) { - return text(entry, false, prettyNbt); + return text(entry, true, prettyNbt); } /** diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserNBT.java b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserNBT.java index 380971134..ae77882b5 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserNBT.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserNBT.java @@ -57,7 +57,7 @@ public String text(@NotNull NBTTagCompound entry, boolean colored, boolean prett @Override public String copyText(@NotNull NBTTagCompound entry, boolean prettyNbt) { - return NbtHelper.toGroovyCode(entry, prettyNbt, false); + return NbtHelper.toGroovyCode(entry, prettyNbt, true); } @Override diff --git a/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java b/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java index e1937b687..4277d9b17 100644 --- a/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java +++ b/src/main/java/com/cleanroommc/groovyscript/helper/StyleConstant.java @@ -70,6 +70,13 @@ public static Style getTitleStyle() { return new Style().setColor(TextFormatting.WHITE).setBold(true); } + /** + * Used to distinguish text from surrounding text. + * Often used for borders or for critical information. + */ + public static Style getEmphasisStyle() { + return new Style().setColor(TextFormatting.GOLD); + } /** * Used for the text of a state where the other outcome could be a warning or an error, diff --git a/src/main/resources/assets/groovyscript/lang/en_us.lang b/src/main/resources/assets/groovyscript/lang/en_us.lang index 7b6d13ccb..8c05d5f35 100644 --- a/src/main/resources/assets/groovyscript/lang/en_us.lang +++ b/src/main/resources/assets/groovyscript/lang/en_us.lang @@ -1,4 +1,4 @@ -groovyscript.command.copy.hover=Click to copy +groovyscript.command.copy.hover=Click to copy: groovyscript.command.copy.copied_start=Copied [ groovyscript.command.copy.copied_end=] to the clipboard From 28d0e751dc2edb3118e8831bdc66e58a74a762ec Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Fri, 11 Oct 2024 08:45:23 -0700 Subject: [PATCH 13/17] adjust mekanism info commands --- .../cleanroommc/groovyscript/command/GSMekanismCommand.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/command/GSMekanismCommand.java b/src/main/java/com/cleanroommc/groovyscript/command/GSMekanismCommand.java index ccfc8b5a1..54a31e393 100644 --- a/src/main/java/com/cleanroommc/groovyscript/command/GSMekanismCommand.java +++ b/src/main/java/com/cleanroommc/groovyscript/command/GSMekanismCommand.java @@ -24,14 +24,14 @@ public GSMekanismCommand() { sender.sendMessage(new TextComponentString("Mekanism gases:")); for (Gas gas : GasRegistry.getRegisteredGasses()) { String copyText = Mekanism.asGroovyCode(gas, true); - sender.sendMessage(TextCopyable.string(copyText, " - " + gas.getName()).build()); + sender.sendMessage(TextCopyable.string(copyText, " - " + copyText).build()); } }, "gases")); addSubcommand(new SimpleCommand("infusionTypes", (server, sender, args) -> { sender.sendMessage(new TextComponentString("Mekanism infusion types:")); for (InfuseType infuseType : InfuseRegistry.getInfuseMap().values()) { - String copyText = "'" + infuseType.name + "'"; - sender.sendMessage(TextCopyable.string(copyText, " - " + infuseType.name).build()); + String copyText = Mekanism.asGroovyCode(infuseType, true); + sender.sendMessage(TextCopyable.string(copyText, " - " + copyText).build()); } })); } From 1e61d81f71d2650373c97b9df0fdfeff2f4fbcd8 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Sun, 13 Oct 2024 06:13:46 -0700 Subject: [PATCH 14/17] act as if colored is always true for info parsers --- .../cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java | 2 +- .../compat/vanilla/command/infoparser/InfoParserOreDict.java | 2 +- .../vanilla/command/infoparser/InfoParserTranslationKey.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java index abfbccdd9..3244582e9 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java @@ -30,7 +30,7 @@ public String name() { @Override public String text(@NotNull IRecipeCategory entry, boolean colored, boolean prettyNbt) { - return colored ? StyleConstant.STRING + entry.getUid() : entry.getUid(); + return StyleConstant.STRING + entry.getUid(); } @Override diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserOreDict.java b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserOreDict.java index f5a26b6a1..8243f0daa 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserOreDict.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserOreDict.java @@ -30,7 +30,7 @@ public String plural() { @Override public String text(@NotNull String entry, boolean colored, boolean prettyNbt) { - return colored ? GroovyScriptCodeConverter.asGroovyCode(entry, true) : entry; + return GroovyScriptCodeConverter.asGroovyCode(entry, true); } @Override diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java index e65e0e02f..1876d684a 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java @@ -20,7 +20,7 @@ public String name() { @Override public String text(@NotNull String entry, boolean colored, boolean prettyNbt) { - return colored ? StyleConstant.STRING + entry : entry; + return StyleConstant.STRING + entry; } @Override From 6b0f1f4439aae8a5fad73c8c16aedc1dc1614f7e Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Sun, 13 Oct 2024 06:21:14 -0700 Subject: [PATCH 15/17] adjust javadoc --- .../compat/vanilla/command/infoparser/GenericInfoParser.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java index 4f7e42a41..09983d64d 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/GenericInfoParser.java @@ -96,7 +96,7 @@ public void header(List messages, boolean plural) { /** * The text that will display in chat. - * The primary difference from {@link #copyText} is containing formatting codes. + * This may be different from {@link #copyText} for instances in which too much text would be added to chat. * Typically valid GroovyScript code. * * @param entry the entry to be parsed @@ -109,7 +109,7 @@ public String msg(@NotNull T entry, boolean prettyNbt) { /** * The text that will be copied when the entry is clicked on. - * The primary difference from {@link #msg} is lacking formatting codes. + * This may be different from {@link #msg} when it would be trimmed due to being too long. * Typically valid GroovyScript code. * * @param entry the entry to be parsed From 08121973ffca6abb91a3f27f16410c01e87df342 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Sun, 13 Oct 2024 06:23:49 -0700 Subject: [PATCH 16/17] update nbt parser and extract constants --- .../command/infoparser/InfoParserNBT.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserNBT.java b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserNBT.java index ae77882b5..4fdea9bb7 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserNBT.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserNBT.java @@ -13,6 +13,9 @@ public class InfoParserNBT extends GenericInfoParser { public static final InfoParserNBT instance = new InfoParserNBT(); + private static final int MAXIMUM_LENGTH_BEFORE_TRIM = 300; + private static final int MAXIMUM_LINES_BEFORE_TRIM = 8; + @Override public int priority() { return 500; @@ -37,6 +40,11 @@ private String trimText() { return StyleConstant.ERROR + "(trimmed)"; } + @Override + public String text(@NotNull NBTTagCompound entry, boolean colored, boolean prettyNbt) { + return NbtHelper.toGroovyCode(entry, prettyNbt, colored); + } + /** * if the length is above 300 characters, we trim to the first space after that, * and we there's more than 8 lines, we trim to that. @@ -45,21 +53,16 @@ private String trimText() { * if the cut happens just after a section sign it would break the formatting of {@link #trimText}. */ @Override - public String text(@NotNull NBTTagCompound entry, boolean colored, boolean prettyNbt) { - String msg = NbtHelper.toGroovyCode(entry, prettyNbt, true); - if (msg.length() > 300) { - int endIndex = StringUtils.indexOf(msg, " ", 300); - return endIndex == -1 ? msg : msg.substring(0, StringUtils.indexOf(msg, " ", 300)) + trimText(); + public String msg(@NotNull NBTTagCompound entry, boolean prettyNbt) { + String msg = text(entry, true, prettyNbt); + if (msg.length() > MAXIMUM_LENGTH_BEFORE_TRIM) { + int endIndex = StringUtils.indexOf(msg, " ", MAXIMUM_LENGTH_BEFORE_TRIM); + return endIndex == -1 ? msg : msg.substring(0, StringUtils.indexOf(msg, " ", MAXIMUM_LENGTH_BEFORE_TRIM)) + trimText(); } - int trimLocation = StringUtils.ordinalIndexOf(msg, "\n", 8); + int trimLocation = StringUtils.ordinalIndexOf(msg, "\n", MAXIMUM_LINES_BEFORE_TRIM); return trimLocation == -1 ? msg : msg.substring(0, trimLocation) + "\n" + trimText(); } - @Override - public String copyText(@NotNull NBTTagCompound entry, boolean prettyNbt) { - return NbtHelper.toGroovyCode(entry, prettyNbt, true); - } - @Override public ITextComponent information(@NotNull NBTTagCompound entry, boolean prettyNbt) { return information(copyText(entry, prettyNbt), msg(entry, prettyNbt)); From a51dc231cf0fcb69c4ea14510cc98047ea0b6707 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Sun, 13 Oct 2024 14:10:27 -0700 Subject: [PATCH 17/17] restore using colored parameter --- .../cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java | 2 +- .../compat/vanilla/command/infoparser/InfoParserOreDict.java | 2 +- .../vanilla/command/infoparser/InfoParserTranslationKey.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java index 3244582e9..abfbccdd9 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/jei/InfoParserTab.java @@ -30,7 +30,7 @@ public String name() { @Override public String text(@NotNull IRecipeCategory entry, boolean colored, boolean prettyNbt) { - return StyleConstant.STRING + entry.getUid(); + return colored ? StyleConstant.STRING + entry.getUid() : entry.getUid(); } @Override diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserOreDict.java b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserOreDict.java index 8243f0daa..efa07a5b4 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserOreDict.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserOreDict.java @@ -30,7 +30,7 @@ public String plural() { @Override public String text(@NotNull String entry, boolean colored, boolean prettyNbt) { - return GroovyScriptCodeConverter.asGroovyCode(entry, true); + return GroovyScriptCodeConverter.asGroovyCode(entry, colored); } @Override diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java index 1876d684a..e65e0e02f 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/vanilla/command/infoparser/InfoParserTranslationKey.java @@ -20,7 +20,7 @@ public String name() { @Override public String text(@NotNull String entry, boolean colored, boolean prettyNbt) { - return StyleConstant.STRING + entry; + return colored ? StyleConstant.STRING + entry : entry; } @Override