From 4a22255b47b120642fc92f61c21d15a09e2e1b30 Mon Sep 17 00:00:00 2001 From: Des Herriott Date: Tue, 28 Nov 2023 16:06:56 +0000 Subject: [PATCH] fix: only show tooltip for smart filter item in inventory screen Avoid spurious tooltips when used a filter item in FTB Quests --- .../ftbfiltersystem/client/FTBFilterSystemClient.java | 9 +++++++-- .../ftbfiltersystem/registry/item/SmartFilterItem.java | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/FTBFilterSystemClient.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/FTBFilterSystemClient.java index 606f0a8..f893c27 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/FTBFilterSystemClient.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/client/FTBFilterSystemClient.java @@ -2,16 +2,17 @@ import dev.architectury.event.events.client.ClientLifecycleEvent; import dev.ftb.mods.ftbfiltersystem.api.FTBFilterSystemAPI; -import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractFilterConfigScreen; -import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import dev.ftb.mods.ftbfiltersystem.api.client.FTBFilterSystemClientAPI; import dev.ftb.mods.ftbfiltersystem.api.client.FilterScreenFactory; +import dev.ftb.mods.ftbfiltersystem.api.client.gui.AbstractFilterConfigScreen; import dev.ftb.mods.ftbfiltersystem.api.event.client.ClientFilterRegistrationEvent; +import dev.ftb.mods.ftbfiltersystem.api.filter.SmartFilter; import dev.ftb.mods.ftbfiltersystem.client.gui.*; import dev.ftb.mods.ftbfiltersystem.filter.*; import dev.ftb.mods.ftbfiltersystem.registry.FilterRegistry; import dev.ftb.mods.ftbfiltersystem.registry.item.SmartFilterItem; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.inventory.EffectRenderingInventoryScreen; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; import net.minecraft.world.item.ItemStack; @@ -72,6 +73,10 @@ public void openFilterConfigScreen(T filter, FilterScree } } + public static boolean shouldShowItemTooltip() { + return Minecraft.getInstance().screen instanceof EffectRenderingInventoryScreen; + } + //------------------------------------------------------------ // API implementation below here diff --git a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java index 235386c..c6c967e 100644 --- a/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java +++ b/common/src/main/java/dev/ftb/mods/ftbfiltersystem/registry/item/SmartFilterItem.java @@ -61,6 +61,9 @@ public InteractionResultHolder use(Level level, Player player, Intera @Override public void appendHoverText(ItemStack itemStack, @Nullable Level level, List list, TooltipFlag tooltipFlag) { + if (level == null || level.isClientSide && !FTBFilterSystemClient.shouldShowItemTooltip()) { + return; // avoids spurious tooltips in places like FTB Quests where a filter could be a matching display item + } list.add(Component.translatable("item.ftbfiltersystem.smart_filter.tooltip.1").withStyle(ChatFormatting.GRAY)); list.add(Component.translatable("item.ftbfiltersystem.smart_filter.tooltip.2").withStyle(ChatFormatting.GRAY)); }