Skip to content

Commit

Permalink
Fix broken tooltips with EMI
Browse files Browse the repository at this point in the history
  • Loading branch information
Emirlol committed Oct 22, 2024
1 parent 76bbfae commit d67d269
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/de/hysky/skyblocker/mixins/emi/FakeScreenMixin.java
Original file line number Diff line number Diff line change
@@ -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<List<TooltipComponent>> 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());
}
}
3 changes: 2 additions & 1 deletion src/main/resources/skyblocker.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"accessors.WorldRendererAccessor",
"discordipc.ConnectionMixin",
"jgit.SystemReaderMixin",
"rei.ScreenOverlayImplFabricMixin"
"rei.ScreenOverlayImplFabricMixin",
"emi.FakeScreenMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit d67d269

Please sign in to comment.