diff --git a/docs/setup/Debugging.md b/docs/setup/Debugging.md index 2f70ec8..c2367f0 100644 --- a/docs/setup/Debugging.md +++ b/docs/setup/Debugging.md @@ -31,6 +31,7 @@ This is especially useful when using file expansion. One common issue is that you removed an option but still use it somewhere. The log will usually reference that option and the source. You can use the dumped scope as a reference for what actually exists for your condition. +Aditionally, you can use `/rpoc execute` to execute muScript snippets (be aware that you will need to prefix your entries with your pack id when doing so) ## Ensure you are using the correct dots Respackopts only supports normal dots. If you write commas or colons by accident, diff --git a/src/client/java/io/gitlab/jfronny/respackopts/RpoClientCommand.java b/src/client/java/io/gitlab/jfronny/respackopts/RpoClientCommand.java index 3479f2b..1e50539 100644 --- a/src/client/java/io/gitlab/jfronny/respackopts/RpoClientCommand.java +++ b/src/client/java/io/gitlab/jfronny/respackopts/RpoClientCommand.java @@ -4,6 +4,8 @@ import com.mojang.brigadier.Command; import com.mojang.brigadier.arguments.StringArgumentType; import io.gitlab.jfronny.commons.throwable.ThrowingConsumer; import io.gitlab.jfronny.commons.throwable.ThrowingSupplier; +import io.gitlab.jfronny.muscript.compiler.Parser; +import io.gitlab.jfronny.muscript.error.LocationalException; import io.gitlab.jfronny.respackopts.util.MetaCache; import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; @@ -47,6 +49,17 @@ public class RpoClientCommand { ctx.getSource().sendFeedback(dump(() -> MinecraftClient.getInstance().getResourceManager().open(id), id.getNamespace() + "/" + id.getPath())); return 1; }; + Command execute = ctx -> { + String snippet = StringArgumentType.getString(ctx, "snippet"); + try { + String result = Parser.parse(snippet, "snippet").asStringExpr().get(MetaCache.getScope(null)); + ctx.getSource().sendFeedback(Text.translatable("respackopts.snippet.success", result)); + } catch (LocationalException | Parser.ParseException e) { + Respackopts.LOGGER.error("Could not execute snippet", e); + ctx.getSource().sendError(Text.translatable("respackopts.snippet.failed", e.getMessage())); + } + return 1; + }; Command reload = ctx -> { MetaCache.clear(); CompletableFuture.allOf(RespackoptsClient.forceReloadResources(), RespackoptsClient.reloadIntegratedServerData()) @@ -65,6 +78,7 @@ public class RpoClientCommand { .then(literal("scope").executes(dumpScope)) .then(literal("glsl").executes(dumpGlsl)) .then(literal("asset").then(argument("asset", IdentifierArgumentType.identifier()).executes(dumpAsset)))) + .then(literal("execute").then(argument("snippet", StringArgumentType.greedyString()).executes(execute))) .then(literal("version").executes(getVersion)) .then(literal("reload").executes(reload))); }); diff --git a/src/main/resources/assets/respackopts/lang/en_us.json b/src/main/resources/assets/respackopts/lang/en_us.json index 5844b1e..060cd75 100644 --- a/src/main/resources/assets/respackopts/lang/en_us.json +++ b/src/main/resources/assets/respackopts/lang/en_us.json @@ -12,5 +12,7 @@ "respackopts.reloadSucceeded": "Successfully reloaded resources and data", "respackopts.reloadFailed": "Could not reload all resources, look at your log for details", "respackopts.versionText": "Version %s using the respackotps meta version %s", - "respackopts.invalidId": "Invalid Identifier" + "respackopts.invalidId": "Invalid Identifier", + "respackopts.snippet.success": "Executed snippet and got: %s", + "respackopts.snippet.failed": "Snippet could not be executed: %s" } \ No newline at end of file