Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/io/github/misode/packtest/PackTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ private static void registerCommands(CommandDispatcher<CommandSourceStack> dispa
AssertCommand.register(dispatcher, buildContext);
AwaitCommand.register(dispatcher, buildContext);
FailCommand.register(dispatcher, buildContext);
LogCommand.register(dispatcher, buildContext);
DummyCommand.register(dispatcher);
SucceedCommand.register(dispatcher);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/github/misode/packtest/PackTestFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Step> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void register(RegistryAccess.Frozen loaded, Map<Identifier, PackTestFunct
instances.register(instanceKey, new FunctionGameTestInstance(functionKey, testData), RegistrationInfo.BUILT_IN);
}

functions.register(functionKey, test::run, RegistrationInfo.BUILT_IN);
functions.register(functionKey, helper -> test.run(helper, id), RegistrationInfo.BUILT_IN);
registeredFunctionKeys.add(functionKey);
} catch (Exception e) {
PackTest.LOGGER.error("Failed to load test {}", id, e);
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/io/github/misode/packtest/commands/LogCommand.java
Original file line number Diff line number Diff line change
@@ -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<CommandSourceStack> 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<CommandSourceStack> 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;
}
}
Loading