feat: /rpoc execute to test muScript snippet
This commit is contained in:
parent
e5f450eb23
commit
5cd0d91dd6
|
@ -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,
|
||||
|
|
|
@ -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<FabricClientCommandSource> 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<FabricClientCommandSource> 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)));
|
||||
});
|
||||
|
|
|
@ -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"
|
||||
}
|
Loading…
Reference in New Issue