Move injection point of TooltipComponentCallback (#3085)

This commit is contained in:
Technici4n 2023-05-30 12:59:06 +01:00 committed by modmuss50
parent daba44536b
commit 8cec7577f3
3 changed files with 16 additions and 12 deletions

View file

@ -16,29 +16,28 @@
package net.fabricmc.fabric.mixin.client.rendering;
import java.util.List;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.client.item.TooltipData;
import net.fabricmc.fabric.api.client.rendering.v1.TooltipComponentCallback;
@Mixin(DrawContext.class)
public class DrawContextMixin {
// Synthetic lambda body in renderTooltip
@Inject(at = @At("HEAD"), method = "method_51442(Ljava/util/List;Lnet/minecraft/client/item/TooltipData;)V", cancellable = true)
private static void injectRenderTooltipLambda(List<TooltipComponent> components, TooltipData data, CallbackInfo ci) {
@Mixin(TooltipComponent.class)
public interface TooltipComponentMixin {
@Inject(
method = "of(Lnet/minecraft/client/item/TooltipData;)Lnet/minecraft/client/gui/tooltip/TooltipComponent;",
at = @At("HEAD"),
cancellable = true
)
private static void convertCustomTooltipData(TooltipData data, CallbackInfoReturnable<TooltipComponent> cir) {
TooltipComponent component = TooltipComponentCallback.EVENT.invoker().getComponent(data);
if (component != null) {
components.add(1, component);
ci.cancel();
cir.setReturnValue(component);
}
}
}

View file

@ -9,13 +9,13 @@
"BuiltinModelItemRendererMixin",
"CapeFeatureRendererMixin",
"DimensionEffectsAccessor",
"DrawContextMixin",
"EntityModelLayersAccessor",
"EntityModelsMixin",
"EntityRenderersMixin",
"InGameHudMixin",
"ItemColorsMixin",
"LivingEntityRendererAccessor",
"TooltipComponentMixin",
"WorldRendererMixin",
"shader.GameRendererMixin",
"shader.ShaderProgramImportProcessorMixin",

View file

@ -16,6 +16,8 @@
package net.fabricmc.fabric.test.rendering.client;
import java.util.Objects;
import net.minecraft.client.gui.tooltip.TooltipComponent;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
@ -35,5 +37,8 @@ public class TooltipComponentTests implements ClientModInitializer {
return null;
});
// Test that TooltipComponent.of works with custom TooltipData
Objects.requireNonNull(TooltipComponent.of(new TooltipComponentTestInit.Data("Hello world!")));
}
}