diff --git a/src/main/java/snownee/jade/Jade.java b/src/main/java/snownee/jade/Jade.java index 98ac1cd0..8c1fccdd 100644 --- a/src/main/java/snownee/jade/Jade.java +++ b/src/main/java/snownee/jade/Jade.java @@ -110,10 +110,10 @@ public static void loadComplete() { configs = list.build(); rootConfig().history.checkNewUser(CommonProxy.getConfigDirectory().getAbsolutePath().hashCode()); rootConfig().fixData(); + WailaConfig.init(); for (JsonConfig config : configs) { config.save(); } - WailaConfig.init(); JadeClient.refreshKeyState(); } } diff --git a/src/main/java/snownee/jade/JadeClient.java b/src/main/java/snownee/jade/JadeClient.java index 68722ce4..0a454911 100644 --- a/src/main/java/snownee/jade/JadeClient.java +++ b/src/main/java/snownee/jade/JadeClient.java @@ -120,11 +120,6 @@ public static void onKeyPressed(int action) { if (mode == IWailaConfig.DisplayMode.TOGGLE) { general.setDisplayTooltip(!general.shouldDisplayTooltip()); if (!general.shouldDisplayTooltip() && Jade.history().hintOverlayToggle) { -// SystemToast.add( -// Minecraft.getInstance().getToasts(), -// JADE_TUTORIAL, -// Component.translatable("toast.jade.toggle_hint.1"), -// Component.translatable("toast.jade.toggle_hint.2", showOverlay.getTranslatedKeyMessage())); Minecraft.getInstance().getChatListener().handleSystemMessage( Component.translatable("toast.jade.toggle_hint.1"), false); @@ -192,7 +187,7 @@ public static void hideModNameIn(Item.TooltipContext context) { } public static void appendModName(List tooltip, ItemStack stack, Item.TooltipContext tooltipContext, TooltipFlag flag) { - if (hideModName.getIfPresent(tooltipContext) != null || !IWailaConfig.get().general().showItemModNameTooltip()) { + if (!IWailaConfig.get().general().showItemModNameTooltip() || hideModName.getIfPresent(tooltipContext) != null) { return; } if (Minecraft.getInstance().screen instanceof CreativeModeInventoryScreen screen && screen.hoveredSlot != null && diff --git a/src/main/java/snownee/jade/mixin/CreativeModeInventoryScreenMixin.java b/src/main/java/snownee/jade/mixin/CreativeModeInventoryScreenMixin.java new file mode 100644 index 00000000..3312561f --- /dev/null +++ b/src/main/java/snownee/jade/mixin/CreativeModeInventoryScreenMixin.java @@ -0,0 +1,71 @@ +package snownee.jade.mixin; + +import java.util.List; +import java.util.Locale; + +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 com.google.common.collect.Lists; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalIntRef; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; + +import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen; +import net.minecraft.network.chat.Component; +import net.minecraft.world.item.ItemStack; +import snownee.jade.Jade; +import snownee.jade.api.config.IWailaConfig; +import snownee.jade.api.theme.IThemeHelper; +import snownee.jade.util.ModIdentification; + +@Mixin(CreativeModeInventoryScreen.class) +public class CreativeModeInventoryScreenMixin { + @WrapOperation(method = "getTooltipFromContainerItem", at = @At(value = "INVOKE", target = "Ljava/util/List;add(ILjava/lang/Object;)V")) + private void jade$collectTabName( + List instance, + int i, + Object e, + Operation original, + @Share("index") LocalIntRef index, + @Share("names") LocalRef> tabNames) { + original.call(instance, i, e); + if (!IWailaConfig.get().general().showItemModNameTooltip()) { + return; + } + index.set(i); + String tabName = ((Component) e).getString().toLowerCase(Locale.ENGLISH); + if (tabNames.get() == null) { + Jade.LOGGER.info("set tabName: {}", tabName); + tabNames.set(Lists.newArrayList(tabName)); + } else { + tabNames.get().add(tabName); + } + } + + @Inject(method = "getTooltipFromContainerItem", at = @At(value = "RETURN", ordinal = 1)) + private void jade$addModName( + ItemStack itemStack, + CallbackInfoReturnable> cir, + @Local List tooltip, + @Share("index") LocalIntRef index, + @Share("names") LocalRef> tabNames) { + Jade.LOGGER.info("tabName: {}", tabNames.get()); + if (!IWailaConfig.get().general().showItemModNameTooltip() || tabNames.get() == null) { + return; + } + String modName = ModIdentification.getModName(itemStack); + String modNameLower = modName.toLowerCase(Locale.ENGLISH); + for (String tabName : tabNames.get()) { + if (tabName.startsWith(modNameLower)) { + return; + } + } + tooltip.add(index.get(), IThemeHelper.get().modName(modName)); + } +} diff --git a/src/main/resources/jade.mixins.json b/src/main/resources/jade.mixins.json index 1353f854..b765abef 100644 --- a/src/main/resources/jade.mixins.json +++ b/src/main/resources/jade.mixins.json @@ -13,6 +13,7 @@ "client": [ "BossHealthOverlayMixin", "ClientLevelMixin", + "CreativeModeInventoryScreenMixin", "KeyAccess", "SessionSearchTreesMixin", "StringRenderOutputMixin",