-
Notifications
You must be signed in to change notification settings - Fork 0
/
TooltipEventHandler.java
71 lines (58 loc) · 2.6 KB
/
TooltipEventHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package org.auioc.mcmod.arnicalib.client.event.handler;
import org.auioc.mcmod.arnicalib.ArnicaLib;
import org.auioc.mcmod.arnicalib.client.config.AHClientConfig;
import org.auioc.mcmod.arnicalib.utils.game.TextUtils;
import org.lwjgl.glfw.GLFW;
import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
@OnlyIn(Dist.CLIENT)
public class TooltipEventHandler {
private static Minecraft mc = Minecraft.getInstance();
public static void handle(ItemTooltipEvent event) {
if (!AHClientConfig.EnableAdvancedTooltip.get()) return;
if (AHClientConfig.AdvancedTooltipOnlyOnDebug.get() && !isDebugMode()) return;
if (AHClientConfig.AdvancedTooltipOnlyOnShift.get() && !isShiftKeyDown()) return;
ItemStack itemStack = event.getItemStack();
if (itemStack.isEmpty()) return;
var darkGary = Style.EMPTY.withColor(ChatFormatting.DARK_GRAY);
if (itemStack.hasTag()) {
addLine(
event,
TextUtils.translatable(ArnicaLib.i18n("advanced_tooltip.nbt"))
.setStyle(darkGary)
.append(
TextUtils.empty()
.setStyle(Style.EMPTY.withColor(ChatFormatting.WHITE))
.append(NbtUtils.toPrettyComponent(itemStack.getTag()))
)
);
}
var tags = itemStack.getTags().toList();
if (tags.size() > 0) {
addLine(event, TextUtils.translatable(ArnicaLib.i18n("advanced_tooltip.tag")).setStyle(darkGary));
for (TagKey<Item> tag : tags) {
addLine(event, TextUtils.literal(" " + tag.location()).setStyle(darkGary));
}
}
}
private static void addLine(ItemTooltipEvent event, Component tooltip) {
event.getToolTip().add(tooltip);
}
private static boolean isDebugMode() {
return mc.options.advancedItemTooltips;
}
private static boolean isShiftKeyDown() {
return InputConstants.isKeyDown(mc.getWindow().getWindow(), GLFW.GLFW_KEY_LEFT_SHIFT) ||
InputConstants.isKeyDown(mc.getWindow().getWindow(), GLFW.GLFW_KEY_RIGHT_SHIFT);
}
}