blob: 8b83b06bdf15491484fd6be615fffc7a11e17c0a (
plain)
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
|
package de.hysky.skyblocker.skyblock.bazaar;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.item.slottext.SlotText;
import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder;
import de.hysky.skyblocker.utils.ItemUtils;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.apache.commons.lang3.math.NumberUtils;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class BazaarHelper extends SlotTextAdder {
private static final Pattern FILLED_PATTERN = Pattern.compile("Filled: \\S+ \\(?([\\d.]+)%\\)?!?");
private static final int RED = 0xe60b1e;
private static final int YELLOW = 0xe6ba0b;
private static final int GREEN = 0x1ee60b;
public BazaarHelper() {
super("(?:Co-op|Your) Bazaar Orders");
}
@Override
public @NotNull List<SlotText> getText(Slot slot) {
if (!SkyblockerConfigManager.get().helpers.bazaar.enableBazaarHelper) return List.of();
// Skip the first row as it's always glass panes.
if (slot.id < 10) return List.of();
// Skip the last 10 items. 11 is subtracted because size is 1-based so the last slot is size - 1.
if (slot.id > slot.inventory.size() - 11) return List.of(); //Note that this also skips the slots in player's inventory (anything above 36/45/54 depending on the order count)
int column = slot.id % 9;
if (column == 0 || column == 8) return List.of(); // Skip the first and last column as those are always glass panes as well.
ItemStack item = slot.getStack();
if (item.isEmpty()) return List.of(); //We've skipped all invalid slots, so we can just check if it's not air here.
Matcher matcher = ItemUtils.getLoreLineIfMatch(item, FILLED_PATTERN);
if (matcher != null) {
List<Text> lore = ItemUtils.getLore(item);
if (!lore.isEmpty() && lore.getLast().getString().equals("Click to claim!")) { //Only show the filled icon when there are items to claim
int filled = NumberUtils.toInt(matcher.group(1));
return SlotText.topLeftList(getFilledIcon(filled));
}
}
if (ItemUtils.getLoreLineIf(item, str -> str.equals("Expired!")) != null) {
return SlotText.topLeftList(getExpiredIcon());
} else if (ItemUtils.getLoreLineIf(item, str -> str.startsWith("Expires in")) != null) {
return SlotText.topLeftList(getExpiringIcon());
}
return List.of();
}
public static @NotNull MutableText getExpiredIcon() {
return Text.literal("⏰").withColor(RED).formatted(Formatting.BOLD);
}
public static @NotNull MutableText getExpiringIcon() {
return Text.literal("⏰").withColor(YELLOW).formatted(Formatting.BOLD);
}
public static @NotNull MutableText getFilledIcon(int filled) {
if (filled < 100) return Text.literal("%").withColor(YELLOW).formatted(Formatting.BOLD);
return Text.literal("✅").withColor(GREEN).formatted(Formatting.BOLD);
}
}
|