diff --git a/src/main/java/io/github/misode/packtest/PackTest.java b/src/main/java/io/github/misode/packtest/PackTest.java index aec828a..e61fbf2 100644 --- a/src/main/java/io/github/misode/packtest/PackTest.java +++ b/src/main/java/io/github/misode/packtest/PackTest.java @@ -92,6 +92,7 @@ private static void registerCommands(CommandDispatcher dispa AssertCommand.register(dispatcher, buildContext); AwaitCommand.register(dispatcher, buildContext); FailCommand.register(dispatcher, buildContext); + LogCommand.register(dispatcher, buildContext); DummyCommand.register(dispatcher); SucceedCommand.register(dispatcher); } diff --git a/src/main/java/io/github/misode/packtest/PackTestExecutor.java b/src/main/java/io/github/misode/packtest/PackTestExecutor.java index 3f2f3e5..f9f1a94 100644 --- a/src/main/java/io/github/misode/packtest/PackTestExecutor.java +++ b/src/main/java/io/github/misode/packtest/PackTestExecutor.java @@ -11,6 +11,7 @@ import net.minecraft.commands.execution.ExecutionContext; import net.minecraft.gametest.framework.GameTestHelper; import net.minecraft.network.chat.Component; +import net.minecraft.resources.Identifier; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; @@ -32,10 +33,12 @@ public class PackTestExecutor { private final long chatSequence = ChatRecorder.sequence(); private int line = 0; private boolean done = false; + public final Identifier testId; - public PackTestExecutor(GameTestHelper helper, int timeout) { + public PackTestExecutor(GameTestHelper helper, int timeout, Identifier testId) { this.helper = helper; this.timeout = timeout; + this.testId = testId; } public static PackTestExecutor current() throws CommandSyntaxException { diff --git a/src/main/java/io/github/misode/packtest/PackTestFunction.java b/src/main/java/io/github/misode/packtest/PackTestFunction.java index 973dd78..5c08ffa 100644 --- a/src/main/java/io/github/misode/packtest/PackTestFunction.java +++ b/src/main/java/io/github/misode/packtest/PackTestFunction.java @@ -9,12 +9,13 @@ import net.minecraft.commands.Commands; import net.minecraft.commands.functions.CommandFunction; import net.minecraft.gametest.framework.*; +import net.minecraft.resources.Identifier; import java.util.*; public record PackTestFunction(List steps, PackTestDirectives directives) { - public void run(GameTestHelper helper) { - PackTestExecutor executor = new PackTestExecutor(helper, this.directives.maxTicks()); + public void run(GameTestHelper helper, Identifier id) { + PackTestExecutor executor = new PackTestExecutor(helper, this.directives.maxTicks(), id); executor.run(this); } diff --git a/src/main/java/io/github/misode/packtest/PackTestRegistries.java b/src/main/java/io/github/misode/packtest/PackTestRegistries.java index 7287c34..65d01d6 100644 --- a/src/main/java/io/github/misode/packtest/PackTestRegistries.java +++ b/src/main/java/io/github/misode/packtest/PackTestRegistries.java @@ -73,7 +73,7 @@ public void register(RegistryAccess.Frozen loaded, Map test.run(helper, id), RegistrationInfo.BUILT_IN); registeredFunctionKeys.add(functionKey); } catch (Exception e) { PackTest.LOGGER.error("Failed to load test {}", id, e); diff --git a/src/main/java/io/github/misode/packtest/commands/LogCommand.java b/src/main/java/io/github/misode/packtest/commands/LogCommand.java new file mode 100644 index 0000000..190fa5a --- /dev/null +++ b/src/main/java/io/github/misode/packtest/commands/LogCommand.java @@ -0,0 +1,33 @@ +package io.github.misode.packtest.commands; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import io.github.misode.packtest.PackTest; +import io.github.misode.packtest.PackTestExecutor; +import net.minecraft.commands.CommandBuildContext; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; +import net.minecraft.commands.arguments.ComponentArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentUtils; + +public class LogCommand { + public static void register(CommandDispatcher dispatcher, CommandBuildContext context) { + dispatcher.register(Commands.literal("log") + .requires(Commands.hasPermission(Commands.LEVEL_GAMEMASTERS)) + .then(Commands.argument("message", ComponentArgument.textComponent(context)) + .executes(LogCommand::log))); + } + + private static int log(CommandContext context) throws CommandSyntaxException { + Component resolvedMessage; + try { + resolvedMessage = ComponentArgument.getResolvedComponent(context, "message"); + } catch (CommandSyntaxException e) { + resolvedMessage = ComponentUtils.fromMessage(e.getRawMessage()); + } + PackTest.LOGGER.info("{} logged: {}", PackTestExecutor.current().testId, resolvedMessage.getString()); + return 0; + } +} \ No newline at end of file