Skip to content

Commit

Permalink
improve: smarter item mod name tooltip (currently not working) (close:
Browse files Browse the repository at this point in the history
  • Loading branch information
Snownee committed Nov 23, 2024
1 parent 7ae136b commit f197063
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/snownee/jade/Jade.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ public static void loadComplete() {
configs = list.build();
rootConfig().history.checkNewUser(CommonProxy.getConfigDirectory().getAbsolutePath().hashCode());
rootConfig().fixData();
WailaConfig.init();
for (JsonConfig<? extends WailaConfig> config : configs) {
config.save();
}
WailaConfig.init();
JadeClient.refreshKeyState();
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/snownee/jade/JadeClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -192,7 +187,7 @@ public static void hideModNameIn(Item.TooltipContext context) {
}

public static void appendModName(List<Component> 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 &&
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Component> instance,
int i,
Object e,
Operation<Void> original,
@Share("index") LocalIntRef index,
@Share("names") LocalRef<List<String>> 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<List<Component>> cir,
@Local List<Component> tooltip,
@Share("index") LocalIntRef index,
@Share("names") LocalRef<List<String>> 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));
}
}
1 change: 1 addition & 0 deletions src/main/resources/jade.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"client": [
"BossHealthOverlayMixin",
"ClientLevelMixin",
"CreativeModeInventoryScreenMixin",
"KeyAccess",
"SessionSearchTreesMixin",
"StringRenderOutputMixin",
Expand Down

0 comments on commit f197063

Please sign in to comment.