Skip to content

Commit

Permalink
Fix broken tooltips with REI
Browse files Browse the repository at this point in the history
  • Loading branch information
Emirlol committed Oct 29, 2024
1 parent 98de0b2 commit 772e6cf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ dependencies {
modImplementation "com.terraformersmc:modmenu:${project.mod_menu_version}"

// REI
modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}"
//modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"
// modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}"
modImplementation "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"

// EMI
modCompileOnly "dev.emi:emi-fabric:${project.emi_version}:api"
Expand Down Expand Up @@ -286,4 +286,4 @@ publishing {
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package de.hysky.skyblocker.mixins.rei;

import de.hysky.skyblocker.utils.render.gui.AlignedTooltipComponent;
import me.shedaniel.rei.api.client.gui.widgets.Tooltip;
import me.shedaniel.rei.impl.client.gui.fabric.ScreenOverlayImplFabric;
import net.minecraft.client.gui.tooltip.TooltipComponent;
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.stream.Stream;

@Mixin(value = ScreenOverlayImplFabric.class, remap = false)
public class ScreenOverlayImplFabricMixin {
@Inject(method = "lambda$renderTooltipInner$0", at = @At(target = "Lme/shedaniel/rei/api/client/gui/widgets/Tooltip$Entry;isText()Z", value = "INVOKE", shift = At.Shift.AFTER), cancellable = true, require = 0)
private static void renderTooltipInner(Tooltip.Entry component, CallbackInfoReturnable<Stream<TooltipComponent>> cir) {
if (!(component.getAsText() instanceof MutableText mutableText)) return;
MutableText firstOfChain = mutableText.getFirstOfChain();
if (firstOfChain != null) cir.setReturnValue(Stream.of(new AlignedTooltipComponent(firstOfChain)));
else if (mutableText.getAlignedText() != null) cir.setReturnValue(Stream.of(new AlignedTooltipComponent(mutableText)));
// The last branch of defaulting back to OrderedTextTooltipComponent is already handled by REI, so we can just omit it here
}
}
3 changes: 2 additions & 1 deletion src/main/resources/skyblocker.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"accessors.SlotAccessor",
"accessors.WorldRendererAccessor",
"discordipc.ConnectionMixin",
"jgit.SystemReaderMixin"
"jgit.SystemReaderMixin",
"rei.ScreenOverlayImplFabricMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 772e6cf

Please sign in to comment.