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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
package de.hysky.skyblocker.skyblock.item.tooltip;
import de.hysky.skyblocker.mixins.accessors.HandledScreenAccessor;
import de.hysky.skyblocker.skyblock.bazaar.ReorderHelper;
import de.hysky.skyblocker.skyblock.chocolatefactory.ChocolateFactorySolver;
import de.hysky.skyblocker.skyblock.item.tooltip.adders.*;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.container.TooltipAdder;
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.Text;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
public class TooltipManager {
private static final TooltipAdder[] adders = new TooltipAdder[]{
new LineSmoothener(), // Applies before anything else
new SupercraftReminder(),
ChocolateFactorySolver.INSTANCE,
new ReorderHelper(),
new NpcPriceTooltip(1),
new BazaarPriceTooltip(2),
new LBinTooltip(3),
new AvgBinTooltip(4),
new EssenceShopPrice(5),
new CraftPriceTooltip(6),
new DungeonQualityTooltip(7),
new MotesTooltip(8),
new ObtainedDateTooltip(9),
new MuseumTooltip(10),
new ColorTooltip(11),
new AccessoryTooltip(12),
};
private static final ArrayList<TooltipAdder> currentScreenAdders = new ArrayList<>();
private TooltipManager() {
}
public static void init() {
ItemTooltipCallback.EVENT.register((stack, tooltipContext, tooltipType, lines) -> {
if (MinecraftClient.getInstance().currentScreen instanceof HandledScreen<?> handledScreen) {
addToTooltip(((HandledScreenAccessor) handledScreen).getFocusedSlot(), stack, lines);
} else {
addToTooltip(null, stack, lines);
}
});
ScreenEvents.AFTER_INIT.register((client, screen, width, height) -> {
onScreenChange(screen);
ScreenEvents.remove(screen).register(ignored -> currentScreenAdders.clear());
});
}
private static void onScreenChange(Screen screen) {
currentScreenAdders.clear();
for (TooltipAdder adder : adders) {
if (adder.isEnabled() && adder.test(screen)) {
currentScreenAdders.add(adder);
}
}
currentScreenAdders.sort(Comparator.comparingInt(TooltipAdder::getPriority));
}
/**
* <p>Adds additional text from all adders that are applicable to the current screen.
* This method is run on each tooltip render, so don't do any heavy calculations here.</p>
*
* <p>If you want to add info to the tooltips of multiple items, consider using a switch statement with {@code focusedSlot.getIndex()}</p>
*
* @param focusedSlot The slot that is currently focused by the cursor.
* @param stack The stack to render the tooltip for.
* @param lines The tooltip lines of the focused item. This includes the display name, as it's a part of the tooltip (at index 0).
* @return The lines list itself after all adders have added their text.
* @deprecated This method is public only for the sake of the mixin. Don't call directly, not that there is any point to it.
*/
@Deprecated
public static List<Text> addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text> lines) {
if (!Utils.isOnSkyblock()) return lines;
for (TooltipAdder adder : currentScreenAdders) {
adder.addToTooltip(focusedSlot, stack, lines);
}
return lines;
}
}
|