Skip to content

Commit

Permalink
Add render condition for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthegreat1 committed Jan 28, 2025
1 parent 2db586d commit 36da421
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class HudLayerTests implements ClientModInitializer, FabricClientGameTest
private static final String BEFORE_DEMO_TIMER = "test_before_demo_timer";
private static final String BEFORE_CHAT = "test_before_chat";
private static final String AFTER_SUBTITLES = "test_after_subtitles";
private static boolean shouldRender = false;

@Override
public void onInitializeClient() {
Expand All @@ -56,38 +57,44 @@ public void onInitializeClient() {
}

private static void renderBeforeMiscOverlay(DrawContext context, RenderTickCounter tickCounter) {
if (!shouldRender) return;
// Render a blue rectangle at the top right of the screen, and it should be blocked by misc overlays such as vignette, spyglass, and powder snow
context.fill(context.getScaledWindowWidth() - 200, 0, context.getScaledWindowWidth(), 30, Colors.BLUE);
context.drawTextWithShadow(MinecraftClient.getInstance().textRenderer, "1. Blue rectangle blocked by overlays", context.getScaledWindowWidth() - 196, 10, Colors.WHITE);
context.drawTextWithShadow(MinecraftClient.getInstance().textRenderer, "such as powder snow", context.getScaledWindowWidth() - 111, 20, Colors.WHITE);
}

private static void renderAfterMiscOverlay(DrawContext context, RenderTickCounter tickCounter) {
if (!shouldRender) return;
// Render a red square in the center of the screen underneath the crosshair
context.fill(context.getScaledWindowWidth() / 2 - 10, context.getScaledWindowHeight() / 2 - 10, context.getScaledWindowWidth() / 2 + 10, context.getScaledWindowHeight() / 2 + 10, Colors.RED);
context.drawCenteredTextWithShadow(MinecraftClient.getInstance().textRenderer, "2. Red square underneath crosshair", context.getScaledWindowWidth() / 2, context.getScaledWindowHeight() / 2 + 10, Colors.WHITE);
}

private static void renderAfterExperienceLevel(DrawContext context, RenderTickCounter tickCounter) {
if (!shouldRender) return;
// Render a green rectangle at the bottom of the screen, and it should block the hotbar and status bars
context.fill(context.getScaledWindowWidth() / 2 - 50, context.getScaledWindowHeight() - 50, context.getScaledWindowWidth() / 2 + 50, context.getScaledWindowHeight() - 10, Colors.GREEN);
context.drawCenteredTextWithShadow(MinecraftClient.getInstance().textRenderer, "3. This green rectangle should block the hotbar and status bars.", context.getScaledWindowWidth() / 2, context.getScaledWindowHeight() - 40, Colors.WHITE);
}

private static void renderBeforeDemoTimer(DrawContext context, RenderTickCounter tickCounter) {
if (!shouldRender) return;
// Render a yellow rectangle at the right of the screen, and it should be above the sleep overlay but below the scoreboard
context.fill(context.getScaledWindowWidth() - 240, context.getScaledWindowHeight() / 2 - 10, context.getScaledWindowWidth(), context.getScaledWindowHeight() / 2 + 10, Colors.YELLOW);
context.drawTextWithShadow(MinecraftClient.getInstance().textRenderer, "4. This yellow rectangle should be above", context.getScaledWindowWidth() - 236, context.getScaledWindowHeight() / 2 - 10, Colors.WHITE);
context.drawTextWithShadow(MinecraftClient.getInstance().textRenderer, "the sleep overlay but below the scoreboard.", context.getScaledWindowWidth() - 236, context.getScaledWindowHeight() / 2, Colors.WHITE);
}

private static void renderBeforeChat(DrawContext context, RenderTickCounter tickCounter) {
if (!shouldRender) return;
// Render a blue rectangle at the bottom left of the screen, and it should be blocked by the chat
context.fill(0, context.getScaledWindowHeight() - 40, 300, context.getScaledWindowHeight() - 50, Colors.BLUE);
context.drawTextWithShadow(MinecraftClient.getInstance().textRenderer, "5. This blue rectangle should be blocked by the chat.", 0, context.getScaledWindowHeight() - 50, Colors.WHITE);
}

private static void renderAfterSubtitles(DrawContext context, RenderTickCounter tickCounter) {
if (!shouldRender) return;
// Render a yellow rectangle at the top of the screen, and it should block the player list
context.fill(context.getScaledWindowWidth() / 2 - 150, 0, context.getScaledWindowWidth() / 2 + 150, 15, Colors.YELLOW);
context.drawCenteredTextWithShadow(MinecraftClient.getInstance().textRenderer, "6. This yellow rectangle should block the player list.", context.getScaledWindowWidth() / 2, 0, Colors.WHITE);
Expand All @@ -101,6 +108,7 @@ public void runTest(ClientGameTestContext context) {
client.options.hudHidden = false;
client.options.getGuiScale().setValue(2);
});
shouldRender = true;

try (TestSingleplayerContext singleplayer = context.worldBuilder().create()) {
// Set up the test world
Expand Down Expand Up @@ -133,5 +141,7 @@ public void runTest(ClientGameTestContext context) {
context.waitTick();
context.assertScreenshotEquals(TestScreenshotComparisonOptions.of("hud_layer_" + AFTER_SUBTITLES).withRegion(554, 0, 600, 30).save());
}

shouldRender = false;
}
}

0 comments on commit 36da421

Please sign in to comment.