Skip to content

Commit

Permalink
Update EMI and change Inject to ModifyReceiver in FakeScreenMixin
Browse files Browse the repository at this point in the history
  • Loading branch information
Emirlol committed Oct 22, 2024
1 parent d67d269 commit e4add25
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod_menu_version = 11.0.0-beta.1
## REI (https://modrinth.com/mod/rei/versions?l=fabric)
rei_version = 16.0.783
## EMI (https://modrinth.com/mod/emi/versions)
emi_version = 1.1.10+1.21
emi_version = 1.1.16+1.21.1
## JEI (https://modrinth.com/mod/jei/versions)
jei_version = 19.8.4.113

Expand Down
19 changes: 10 additions & 9 deletions src/main/java/de/hysky/skyblocker/mixins/emi/FakeScreenMixin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.hysky.skyblocker.mixins.emi;

import com.llamalad7.mixinextras.injector.ModifyReceiver;
import com.llamalad7.mixinextras.sugar.Local;
import de.hysky.skyblocker.utils.render.gui.AlignedTooltipComponent;
import dev.emi.emi.screen.FakeScreen;
import net.minecraft.client.MinecraftClient;
Expand All @@ -10,22 +12,21 @@
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;
import java.util.stream.Collector;
import java.util.stream.Stream;

@Mixin(value = FakeScreen.class, remap = false)
@Mixin(value = FakeScreen.class)
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 -> {
@ModifyReceiver(method = "getTooltipComponentListFromItem", at = @At(target = "Ljava/util/stream/Stream;collect(Ljava/util/stream/Collector;)Ljava/lang/Object;", value = "INVOKE"), require = 0)
private <A> Stream<TooltipComponent> skyblocker$alignedTooltip(Stream<TooltipComponent> instance, Collector<? super TooltipComponent, A, List<TooltipComponent>> arCollector, @Local(argsOnly = true) ItemStack stack) {
return 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());
} return new OrderedTextTooltipComponent(text.asOrderedText());
});
}
}

0 comments on commit e4add25

Please sign in to comment.