Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
import net.fabricmc.loader.api.FabricLoader;
import xyz.bluspring.kilt.injections.client.gui.GuiGraphicsInjection;
import xyz.bluspring.kilt.injections.client.gui.screens.inventory.tooltip.TooltipRenderUtilInjection;
import xyz.bluspring.kilt.mixin.ClientTextTooltipAccessor;
Expand All @@ -48,6 +49,10 @@

@Mixin(GuiGraphics.class)
public abstract class GuiGraphicsInject implements GuiGraphicsInjection, IForgeGuiGraphics {

@Unique
private static final boolean kilt$isIcebergLoaded = FabricLoader.getInstance().isModLoaded("iceberg");

@Shadow @Deprecated protected abstract void flushIfUnmanaged();

@Shadow @Final private PoseStack pose;
Expand Down Expand Up @@ -140,6 +145,12 @@ public void renderTooltip(Font font, List<Component> textComponents, Optional<To

@ModifyArg(method = "renderTooltip(Lnet/minecraft/client/gui/Font;Ljava/util/List;Ljava/util/Optional;II)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;renderTooltipInternal(Lnet/minecraft/client/gui/Font;Ljava/util/List;IILnet/minecraft/client/gui/screens/inventory/tooltip/ClientTooltipPositioner;)V"))
private List<ClientTooltipComponent> kilt$gatherForgeTooltips(List<ClientTooltipComponent> original, @Local(argsOnly = true) List<Component> lines, @Local(argsOnly = true) Optional<TooltipComponent> visualTooltipComponent, @Local(argsOnly = true, ordinal = 0) int mouseX, @Local(argsOnly = true) Font font) {
// Iceberg handles tooltip gathering and wrapping itself, so we should not interfere with it.
// Otherwise, we get duplicate tooltips when text wrapping is applied.
if (kilt$isIcebergLoaded) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This feels unsafe, are we sure this doesn't affect other Forge mods?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

well, I tested IAF and Minecolonies (with its deps) and everything works great

anyway, this only works in environments with Iceberg, and playing with Iceberg is pretty annoying, so users will end up uninstalling it along with any other mods that depend on it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Look into other mods, specifically those that use the RenderTooltipEvent.GatherComponents event. Use the GitHub search to find mods that use this event themselves and make sure this code works as expected there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, will do that on weekends. for now I can approve that it works in a modpack with 418 mods and 4 mods that do something with tooltips:

image

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@kallmetony status?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sorry, I was extremely busy for past few weeks and only got free time now. yep, this looks good for me

return original;
}

var forgeTooltips = new ArrayList<>(ForgeHooksClient.gatherTooltipComponents(this.tooltipStack, lines, visualTooltipComponent, mouseX, guiWidth(), guiHeight(), font));

// Make a copy of the original list for modification, as we also want to be able to support other mods that may be injecting into here.
Expand Down