Skip to content

Commit

Permalink
Make self-test more robust against ticking multiple times (#1729)
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte authored Dec 3, 2024
1 parent 731d226 commit d6085a9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/main/java/net/neoforged/neoforge/common/util/SelfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ public static void initClient() {
if (Minecraft.getInstance().getOverlay() instanceof LoadingOverlay) {
return;
}
writeSelfTestReport(clientSelfTestDestination);
Minecraft.getInstance().stop();
if (Minecraft.getInstance().isRunning()) {
writeSelfTestReport(clientSelfTestDestination);
Minecraft.getInstance().stop();
}
});
}
}
Expand All @@ -53,8 +55,10 @@ public static void initCommon() {
System.exit(1);
}
NeoForge.EVENT_BUS.addListener((ServerTickEvent.Pre e) -> {
writeSelfTestReport(serverSelfTestDestination);
e.getServer().halt(false);
if (e.getServer().isRunning()) {
writeSelfTestReport(serverSelfTestDestination);
e.getServer().halt(false);
}
});
}
}
Expand All @@ -66,11 +70,10 @@ public static void initCommon() {
private static void writeSelfTestReport(String path) {
try {
Files.createFile(Paths.get(path));
LOGGER.info("Wrote self-test report to '{}'", path);
} catch (IOException e) {
LOGGER.error("Failed to write self-test to '{}'", path, e);
System.exit(1);
}

LOGGER.info("Write self-test report to '{}'", path);
}
}

0 comments on commit d6085a9

Please sign in to comment.