Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,4 @@ private void wrapChat(Gui instance, GuiGraphics context, DeltaTracker tickCounte
private void wrapPlayerList(Gui instance, GuiGraphics context, DeltaTracker tickCounter, Operation<Void> renderVanilla) {
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"))
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));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.mixin.client.rendering;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.DeltaTracker;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.SubtitleOverlay;

import net.fabricmc.fabric.api.client.rendering.v1.hud.VanillaHudElements;
import net.fabricmc.fabric.impl.client.rendering.hud.HudElementRegistryImpl;

@Mixin(SubtitleOverlay.class)
public class SubtitleOverlayMixin {
@Unique
private boolean fabric_renderingThroughHud = false;

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"GuiRendererMixin",
"GuiAccessor",
"GuiMixin",
"SubtitleOverlayMixin",
"LivingEntityRendererAccessor",
"LivingEntityRendererMixin",
"ModelMixin",
Expand Down
Loading