Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ abstract class GuiMixin {
@Final
private Minecraft minecraft;

@Shadow
private Runnable deferredSubtitles;

@Inject(method = "render", at = @At(value = "TAIL"))
public void render(GuiGraphics drawContext, DeltaTracker tickCounter, CallbackInfo callbackInfo) {
HudRenderCallback.EVENT.invoker().onHudRender(drawContext, tickCounter);
Expand Down Expand Up @@ -161,7 +164,19 @@ private void wrapPlayerList(Gui instance, GuiGraphics context, DeltaTracker tick
}

@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 😄

private void wrapSubtitlesHud(Gui instance, GuiGraphics context, boolean bl, Operation<Void> renderVanilla, @Local(argsOnly = true) DeltaTracker tickCounter) {
HudElementRegistryImpl.getRoot(VanillaHudElements.SUBTITLES).render(context, tickCounter, (ctx, tc) -> renderVanilla.call(instance, ctx, bl));
private void wrapSubtitlesHud(Gui instance, GuiGraphics context, boolean deferRendering, Operation<Void> renderVanilla, @Local(argsOnly = true) DeltaTracker tickCounter) {
if (deferRendering) {
Runnable originalDeferred = this.deferredSubtitles;
renderVanilla.call(instance, context, true);
Runnable newDeferred = this.deferredSubtitles;

if (newDeferred != null && newDeferred != originalDeferred) {
this.deferredSubtitles = () -> HudElementRegistryImpl.getRoot(VanillaHudElements.SUBTITLES)
.render(context, tickCounter, (ctx, tc) -> newDeferred.run());
}
} else {
HudElementRegistryImpl.getRoot(VanillaHudElements.SUBTITLES)
.render(context, tickCounter, (ctx, tc) -> renderVanilla.call(instance, ctx, false));
}
}
}
Loading