From 8e4cce107291b65ac6f4a6b16d895e196a694db9 Mon Sep 17 00:00:00 2001 From: Mona <59416038+meowora@users.noreply.github.com> Date: Sat, 26 Jul 2025 01:13:55 +0200 Subject: fix: some mixin injections preventing things in cases they shouldn't (#1495) * fix: some mixin injections preventing things in cases they shouldn't * isblank * changes * coding is so difficult :c --- .../skyblocker/mixins/HandledScreenMixin.java | 59 +++++++++++++++++----- 1 file changed, 45 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java b/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java index b3812afc..11aa83ea 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java @@ -1,6 +1,8 @@ package de.hysky.skyblocker.mixins; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Local; import de.hysky.skyblocker.config.SkyblockerConfig; import de.hysky.skyblocker.config.SkyblockerConfigManager; @@ -23,18 +25,24 @@ import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.container.ContainerSolver; import de.hysky.skyblocker.utils.container.ContainerSolverManager; import net.fabricmc.fabric.api.client.screen.v1.Screens; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.gui.widget.ClickableWidget; import net.minecraft.client.render.RenderLayer; import net.minecraft.inventory.SimpleInventory; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.item.tooltip.TooltipData; +import net.minecraft.item.tooltip.TooltipType; import net.minecraft.screen.GenericContainerScreenHandler; import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.SlotActionType; import net.minecraft.text.Text; +import net.minecraft.util.Identifier; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; @@ -194,28 +202,45 @@ public abstract class HandledScreenMixin extends Screen @SuppressWarnings("DataFlowIssue") // makes intellij be quiet about this.focusedSlot maybe being null. It's already null checked in mixined method. - @Inject(method = "drawMouseoverTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;Ljava/util/Optional;IILnet/minecraft/util/Identifier;)V"), cancellable = true) - public void skyblocker$drawMouseOverTooltip(DrawContext context, int x, int y, CallbackInfo ci, @Local(ordinal = 0) ItemStack stack) { - if (!Utils.isOnSkyblock()) return; + @WrapOperation(method = "drawMouseoverTooltip", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTooltip(Lnet/minecraft/client/font/TextRenderer;Ljava/util/List;Ljava/util/Optional;IILnet/minecraft/util/Identifier;)V")) + public void skyblocker$drawMouseOverTooltip( + DrawContext instance, + TextRenderer textRenderer, + List text, + Optional data, + int x, + int y, + Identifier texture, + Operation original, + @Local(ordinal = 0) ItemStack stack + ) { + if (!Utils.isOnSkyblock() || text.isEmpty()) { + original.call(instance, textRenderer, text, data, x, y, texture); + return; + } + + var name = text.getFirst().getString(); // Hide Empty Tooltips - if (SkyblockerConfigManager.get().uiAndVisuals.hideEmptyTooltips && stack.getName().getString().equals(" ")) { - ci.cancel(); + if (SkyblockerConfigManager.get().uiAndVisuals.hideEmptyTooltips && name.isBlank()) { + return; } // Backpack Preview boolean shiftDown = SkyblockerConfigManager.get().uiAndVisuals.backpackPreviewWithoutShift ^ Screen.hasShiftDown(); - if (shiftDown && getTitle().getString().equals("Storage") && focusedSlot.inventory != client.player.getInventory() && BackpackPreview.renderPreview(context, this, focusedSlot.getIndex(), x, y)) { - ci.cancel(); + if (shiftDown && getTitle().getString().equals("Storage") && focusedSlot.inventory != client.player.getInventory() && BackpackPreview.renderPreview(instance, this, focusedSlot.getIndex(), x, y)) { + return; } // Compactor Preview if (SkyblockerConfigManager.get().uiAndVisuals.compactorDeletorPreview) { Matcher matcher = CompactorDeletorPreview.NAME.matcher(ItemUtils.getItemId(stack)); - if (matcher.matches() && CompactorDeletorPreview.drawPreview(context, stack, getTooltipFromItem(stack), matcher.group("type"), matcher.group("size"), x, y)) { - ci.cancel(); + if (matcher.matches() && CompactorDeletorPreview.drawPreview(instance, stack, getTooltipFromItem(stack), matcher.group("type"), matcher.group("size"), x, y)) { + return; } } + + original.call(instance, textRenderer, text, data, x, y, texture); } @ModifyVariable(method = "drawMouseoverTooltip", at = @At(value = "STORE")) @@ -272,8 +297,16 @@ public abstract class HandledScreenMixin extends Screen ContainerSolver currentSolver = ContainerSolverManager.getCurrentSolver(); ItemStack stack = skyblocker$experimentSolvers$getStack(slot, slot.getStack(), currentSolver); + boolean isTitleEmptyOrFiller = FILLER_ITEMS.contains(stack.getName().getString()); + if (isTitleEmptyOrFiller) { + var tooltip = stack.getTooltip(Item.TooltipContext.DEFAULT, MinecraftClient.getInstance().player, TooltipType.BASIC).stream().map(Text::getString).toList(); + String lore = String.join("\n", tooltip); + isTitleEmptyOrFiller = lore.isBlank() || FILLER_ITEMS.contains(tooltip.getFirst()); + } + + // Prevent clicks on filler items - if (SkyblockerConfigManager.get().uiAndVisuals.hideEmptyTooltips && FILLER_ITEMS.contains(stack.getName().getString()) && + if (SkyblockerConfigManager.get().uiAndVisuals.hideEmptyTooltips && isTitleEmptyOrFiller && // Allow clicks in Ultrasequencer and Superpairs (!UltrasequencerSolver.INSTANCE.test(title) || SkyblockerConfigManager.get().helpers.experiments.enableUltrasequencerSolver)) { ci.cancel(); @@ -315,10 +348,8 @@ public abstract class HandledScreenMixin extends Screen } } - case GenericContainerScreenHandler genericContainerScreenHandler when title.equals(MuseumItemCache.DONATION_CONFIRMATION_SCREEN_TITLE) -> { - //Museum Item Cache donation tracking - MuseumItemCache.handleClick(slot, slotId, genericContainerScreenHandler.slots); - } + //Museum Item Cache donation tracking + case GenericContainerScreenHandler genericContainerScreenHandler when title.equals(MuseumItemCache.DONATION_CONFIRMATION_SCREEN_TITLE) -> MuseumItemCache.handleClick(slot, slotId, genericContainerScreenHandler.slots); case null, default -> {} } -- cgit