Add a way to render tooltips from Formatted text and TooltipComponents elements (#10056) (#10291)

Co-authored-by: James Mitchell <tehgeek@gmail.com>
This commit is contained in:
JonathingandJames Mitchell authored and GitHub committed 2025-01-04 14:35:14 -08:00
1 parent 915d8a8f7d
commit 97e6b96cbb
2 files changed
+13 -2

No files matched your search

@@ -830,11 +830,15 @@ public class ForgeHooksClient {
}
public static List<ClientTooltipComponent> gatherTooltipComponents(ItemStack stack, List<? extends FormattedText> textElements, Optional<TooltipComponent> itemComponent, int mouseX, int screenWidth, int screenHeight, Font fallbackFont) {
Font font = getTooltipFont(stack, fallbackFont);
List<Either<FormattedText, TooltipComponent>> elements = textElements.stream()
.map((Function<FormattedText, Either<FormattedText, TooltipComponent>>) Either::left)
.collect(Collectors.toCollection(ArrayList::new));
itemComponent.ifPresent(c -> elements.add(1, Either.right(c)));
return gatherTooltipComponentsFromElements(stack, elements, mouseX, screenWidth, screenHeight, fallbackFont);
}
public static List<ClientTooltipComponent> gatherTooltipComponentsFromElements(ItemStack stack, List<Either<FormattedText, TooltipComponent>> elements, int mouseX, int screenWidth, int screenHeight, Font fallbackFont) {
Font font = getTooltipFont(stack, fallbackFont);
var event = new RenderTooltipEvent.GatherComponents(stack, screenWidth, screenHeight, elements, -1);
MinecraftForge.EVENT_BUS.post(event);