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.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right actually; WrapMethod is cleaner here and does accomplish what we wanted.

@modmuss50 modmuss50 removed the status: merge me please Pull requests that are ready to merge label Nov 23, 2025
@ekulxam
Copy link
Contributor

ekulxam commented Dec 6, 2025

@Liam-Broome are you still working on this? If not, then I'd like to implement the requested changes myself. No worries if you're busy.

@Liam-Broome
Copy link
Contributor Author

@ekulxam - Feel free to take over 😀

@ekulxam
Copy link
Contributor

ekulxam commented Dec 8, 2025

@Liam-Broome I've made a pull request to your fork Liam-Broome#1

Copy link
Contributor

@cputnam-a11y cputnam-a11y left a comment

Choose a reason for hiding this comment

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

I still don't really understand the actual issue here, but the mixins do look much cleaner now

@modmuss50 modmuss50 added the status: merge me please Pull requests that are ready to merge label Jan 1, 2026
@modmuss50 modmuss50 merged commit 7edacff into FabricMC:1.21.11 Jan 5, 2026
4 checks passed
modmuss50 pushed a commit that referenced this pull request Jan 5, 2026
#5012)

* [Issue] - Enhance subtitle overlay rendering in GuiMixin.

* Fix indentation in GuiMixin subtitle rendering

* Refactor subtitle overlay rendering to new mixin

* Clean up formatting in SubtitleOverlayMixin

* Cleanup SubtitleOverlayMixin

* Fix checkstyle

---------

Co-authored-by: modmuss <[email protected]>
Co-authored-by: SkyNotTheLimit <[email protected]>
(cherry picked from commit 7edacff)

# Conflicts:
#	fabric-rendering-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/GuiMixin.java
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