Skip to content

Conversation

@Liam-Broome
Copy link
Contributor

Fixes issue #4933 where HudElementRegistry.replaceElement(VanillaHudElements.SUBTITLES, ...) did not work correctly during normal gameplay, only when the game was paused. This prevented mods from properly scaling, positioning, or otherwise modifying subtitle rendering during active play.

Screen.Recording.2025-11-19.at.16.17.20.mov

@Liam-Broome Liam-Broome changed the title [Issue] - Enhance subtitle overlay rendering in GuiMixin. [Issue] - Fix HudElementRegistry.replaceElement() for subtitles during gameplay. Nov 19, 2025
@Liam-Broome
Copy link
Contributor Author

Liam-Broome commented Nov 19, 2025

The test build / client_test failing seems to be an infrastructural issue. I can see that the PR previous to this also has this issue.

@maityyy
Copy link
Contributor

maityyy commented Nov 20, 2025

The test build / client_test failing seems to be an infrastructural issue. I can see that the PR previous to this also has this issue.

yes, MC-304369

@modmuss50 modmuss50 added the bug Something isn't working label Nov 20, 2025
@modmuss50 modmuss50 added the status: merge me please Pull requests that are ready to merge label Nov 21, 2025
@ekulxam
Copy link
Contributor

ekulxam commented Nov 22, 2025

Wait don't merge yet

HudElementRegistryImpl.getRoot(VanillaHudElements.PLAYER_LIST).render(context, tickCounter, (ctx, tc) -> renderVanilla.call(instance, ctx, tc));
}

@WrapOperation(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Gui;renderSubtitleOverlay(Lnet/minecraft/client/gui/GuiGraphics;Z)V"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree with this mixin, see https://discord.com/channels/507304429255393322/807617700734042122/1440940666829013103.

I think it would better to instead mixin into the renderSubtitleOverlay method (and the lambda) to wrap the subtitleOverlay#render (as shown in the image).
As stated by @cassiancc, we can obtain the DeltaTracker/RenderTickCounter from the client so my suggested change may actually be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ekulxam - I have made some changes, thanks for the feedback 😄

Comment on lines +38 to +61
@Inject(method = "render", at = @At("HEAD"), cancellable = true)
private void wrapSubtitleRender(GuiGraphics context, CallbackInfo ci) {
if (!fabric_renderingThroughHud) {
DeltaTracker deltaTracker = Minecraft.getInstance().getDeltaTracker();

ci.cancel();

HudElementRegistryImpl.getRoot(VanillaHudElements.SUBTITLES)
.render(context, deltaTracker, (ctx, tc) -> {
fabric_renderingThroughHud = true;

try {
fabric_callOriginalRender(ctx);
} finally {
fabric_renderingThroughHud = false;
}
});
}
}

@Unique
private void fabric_callOriginalRender(GuiGraphics context) {
((SubtitleOverlay) (Object) this).render(context);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this need to be recursive? I would think that this should be a WrapMethod.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I said to wrap it and not inject. It should actually be a WrapOperation into both the lambda and the renderSubtitleOverlay method with the render call as the target.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working status: merge me please Pull requests that are ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HudElementRegistry#replaceElement does not work properly to Closed Captions in MC 1.21.9/10

5 participants