From d67d26970c43902acc673ba4c893ef03ed60db1c Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Tue, 22 Oct 2024 17:15:56 +0300 Subject: [PATCH] Fix broken tooltips with EMI --- build.gradle | 4 +-- .../mixins/emi/FakeScreenMixin.java | 31 +++++++++++++++++++ src/main/resources/skyblocker.mixins.json | 3 +- 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/main/java/de/hysky/skyblocker/mixins/emi/FakeScreenMixin.java diff --git a/build.gradle b/build.gradle index 712afda2e7..81c0b95efa 100644 --- a/build.gradle +++ b/build.gradle @@ -163,8 +163,8 @@ dependencies { modImplementation "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}" // EMI - modCompileOnly "dev.emi:emi-fabric:${project.emi_version}:api" - //modLocalRuntime "dev.emi:emi-fabric:${project.emi_version}" +// modCompileOnly "dev.emi:emi-fabric:${project.emi_version}:api" + modImplementation "dev.emi:emi-fabric:${project.emi_version}" // JEI (Using modrinth repo since official release is in mojmap and doesn't work) modCompileOnly "maven.modrinth:jei:${project.jei_version}-fabric" diff --git a/src/main/java/de/hysky/skyblocker/mixins/emi/FakeScreenMixin.java b/src/main/java/de/hysky/skyblocker/mixins/emi/FakeScreenMixin.java new file mode 100644 index 0000000000..f7ec8c7c46 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/mixins/emi/FakeScreenMixin.java @@ -0,0 +1,31 @@ +package de.hysky.skyblocker.mixins.emi; + +import de.hysky.skyblocker.utils.render.gui.AlignedTooltipComponent; +import dev.emi.emi.screen.FakeScreen; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.tooltip.OrderedTextTooltipComponent; +import net.minecraft.client.gui.tooltip.TooltipComponent; +import net.minecraft.item.ItemStack; +import net.minecraft.text.MutableText; +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.CallbackInfoReturnable; + +import java.util.List; + +@Mixin(value = FakeScreen.class, remap = false) +public class FakeScreenMixin { + @Inject(method = "getTooltipComponentListFromItem", at = @At(target = "Ljava/util/stream/Stream;collect(Ljava/util/stream/Collector;)Ljava/lang/Object;", value = "INVOKE", shift = At.Shift.AFTER), require = 0, cancellable = true) + private void skyblocker$alignedTooltip(ItemStack stack, CallbackInfoReturnable> cir) { + cir.setReturnValue(Screen.getTooltipFromItem(MinecraftClient.getInstance(), stack).stream().map(text -> { + if (text instanceof MutableText mutableText) { + MutableText firstOfChain = mutableText.getFirstOfChain(); + if (firstOfChain != null) return new AlignedTooltipComponent(firstOfChain); + else if (mutableText.getAlignedText() != null) return new AlignedTooltipComponent(mutableText); + else return new OrderedTextTooltipComponent(mutableText.asOrderedText()); + } else return new OrderedTextTooltipComponent(text.asOrderedText()); + }).toList()); + } +} diff --git a/src/main/resources/skyblocker.mixins.json b/src/main/resources/skyblocker.mixins.json index 8c8c10abbe..3111fb59ae 100644 --- a/src/main/resources/skyblocker.mixins.json +++ b/src/main/resources/skyblocker.mixins.json @@ -59,7 +59,8 @@ "accessors.WorldRendererAccessor", "discordipc.ConnectionMixin", "jgit.SystemReaderMixin", - "rei.ScreenOverlayImplFabricMixin" + "rei.ScreenOverlayImplFabricMixin", + "emi.FakeScreenMixin" ], "injectors": { "defaultRequire": 1