Skip to content

Commit e46b849

Browse files
authored
Merge pull request SkyblockerMod#756 from Emirlol/tooltip-refactor-hotfix
Fix CatacombsLevelAdder not working at max class levels
2 parents e682838 + 95d1f34 commit e46b849

File tree

6 files changed

+93
-14
lines changed

6 files changed

+93
-14
lines changed

src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextAdder.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import de.hysky.skyblocker.config.SkyblockerConfigManager;
44
import de.hysky.skyblocker.utils.render.gui.AbstractContainerMatcher;
55
import net.minecraft.screen.slot.Slot;
6+
import org.intellij.lang.annotations.Language;
67
import org.jetbrains.annotations.NotNull;
78

89
import java.util.List;
@@ -17,7 +18,7 @@ public abstract class SlotTextAdder extends AbstractContainerMatcher {
1718
*
1819
* @see #SlotTextAdder(Pattern)
1920
*/
20-
protected SlotTextAdder(@NotNull String titlePattern) {
21+
protected SlotTextAdder(@NotNull @Language("RegExp") String titlePattern) {
2122
super(titlePattern);
2223
}
2324

src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextManager.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public class SlotTextManager {
2525
new AttributeShardAdder(),
2626
new PrehistoricEggAdder(),
2727
new PotionLevelAdder(),
28-
new CollectionAdder()
28+
new CollectionAdder(),
29+
new CommunityShopAdder()
2930
};
3031
private static final ArrayList<SlotTextAdder> currentScreenAdders = new ArrayList<>();
3132

src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CatacombsLevelAdder.java

+19-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import de.hysky.skyblocker.skyblock.item.slottext.SlotText;
44
import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder;
5+
import de.hysky.skyblocker.utils.RomanNumerals;
56
import net.minecraft.item.ItemStack;
67
import net.minecraft.screen.slot.Slot;
78
import net.minecraft.text.Text;
@@ -10,6 +11,8 @@
1011
import org.jetbrains.annotations.NotNull;
1112

1213
import java.util.List;
14+
import java.util.regex.Matcher;
15+
import java.util.regex.Pattern;
1316

1417
//This class is split into 3 inner classes as there are multiple screens for showing catacombs levels, each with different slot ids or different style of showing the level.
1518
//It's still kept in 1 main class for organization purposes.
@@ -18,6 +21,7 @@ private CatacombsLevelAdder() {
1821
}
1922

2023
public static class Dungeoneering extends SlotTextAdder {
24+
private static final Pattern LEVEL_PATTERN = Pattern.compile(".*?(?:(?<arabic>\\d+)|(?<roman>\\S+))? ?✯?");
2125
public Dungeoneering() {
2226
super("^Dungeoneering");
2327
}
@@ -26,12 +30,21 @@ public Dungeoneering() {
2630
public @NotNull List<SlotText> getText(Slot slot) {
2731
switch (slot.id) {
2832
case 12, 29, 30, 31, 32, 33 -> {
29-
String name = slot.getStack().getName().getString();
30-
int lastIndex = name.lastIndexOf(' ');
31-
if (lastIndex == -1) return List.of(SlotText.bottomLeft(Text.literal("0").formatted(Formatting.RED)));
32-
String level = name.substring(lastIndex + 1);
33-
if (!NumberUtils.isDigits(level)) return List.of(); //Sanity check, just in case.
34-
return List.of(SlotText.bottomRight(Text.literal(level).formatted(Formatting.RED)));
33+
Matcher matcher = LEVEL_PATTERN.matcher(slot.getStack().getName().getString());
34+
if (!matcher.matches()) return List.of();
35+
String arabic = matcher.group("arabic");
36+
String roman = matcher.group("roman");
37+
if (arabic == null && roman == null) return List.of(SlotText.bottomLeft(Text.literal("0").formatted(Formatting.RED)));
38+
String level;
39+
if (arabic != null) {
40+
if (!NumberUtils.isDigits(arabic)) return List.of(); //Sanity check
41+
level = arabic;
42+
} else { // roman != null
43+
if (!RomanNumerals.isValidRomanNumeral(roman)) return List.of(); //Sanity check
44+
level = String.valueOf(RomanNumerals.romanToDecimal(roman));
45+
}
46+
47+
return List.of(SlotText.bottomLeft(Text.literal(level).formatted(Formatting.RED)));
3548
}
3649
default -> {
3750
return List.of();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package de.hysky.skyblocker.skyblock.item.slottext.adders;
2+
3+
import de.hysky.skyblocker.skyblock.item.slottext.SlotText;
4+
import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder;
5+
import de.hysky.skyblocker.utils.ItemUtils;
6+
import de.hysky.skyblocker.utils.RomanNumerals;
7+
import net.minecraft.item.ItemStack;
8+
import net.minecraft.item.Items;
9+
import net.minecraft.screen.slot.Slot;
10+
import net.minecraft.text.Text;
11+
import net.minecraft.util.Formatting;
12+
import org.jetbrains.annotations.NotNull;
13+
14+
import java.util.List;
15+
16+
public class CommunityShopAdder extends SlotTextAdder {
17+
private static final byte CATEGORIES_START = 10;
18+
private static final byte CATEGORIES_END = 14; //Inclusive
19+
20+
public CommunityShopAdder() {
21+
super("^Community Shop");
22+
}
23+
24+
@Override
25+
public @NotNull List<SlotText> getText(Slot slot) {
26+
for (byte i = CATEGORIES_START; i <= CATEGORIES_END; i++) {
27+
if (slot.inventory.getStack(i).isOf(Items.LIME_STAINED_GLASS_PANE)) { //Only the selected category has a lime stained glass pane, the others have a gray one.
28+
return switch (i) { //This is a switch to allow adding more categories easily in the future, if we ever add more.
29+
case 11 -> getTextForUpgradesScreen(slot);
30+
default -> List.of();
31+
};
32+
}
33+
}
34+
return List.of();
35+
}
36+
37+
private static List<SlotText> getTextForUpgradesScreen(Slot slot) {
38+
final ItemStack stack = slot.getStack();
39+
switch (slot.id) {
40+
case 30, 31, 32, 33, 34, 38, 39, 40, 41, 42, 43, 44 -> {
41+
String name = stack.getName().getString();
42+
int lastIndex = name.lastIndexOf(' ');
43+
String roman = name.substring(lastIndex + 1); // + 1 as we don't want the space
44+
if (!RomanNumerals.isValidRomanNumeral(roman)) return List.of();
45+
46+
List<Text> lore = ItemUtils.getLore(stack);
47+
if (lore.isEmpty()) return List.of();
48+
String lastLine = lore.getLast().getString();
49+
return List.of(SlotText.bottomLeft(switch (lastLine) {
50+
case "Maxed out!" -> Text.literal("Max").withColor(0xfab387);
51+
case "Currently upgrading!" -> Text.literal("⏰").withColor(0xf9e2af).formatted(Formatting.BOLD);
52+
case "Click to claim!" -> Text.literal("✅").withColor(0xa6e3a1).formatted(Formatting.BOLD);
53+
default -> Text.literal(String.valueOf(RomanNumerals.romanToDecimal(roman))).withColor(0xcba6f7);
54+
}));
55+
56+
}
57+
}
58+
return List.of();
59+
}
60+
}

src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/MinionLevelAdder.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
import org.jetbrains.annotations.NotNull;
1212

1313
import java.util.List;
14+
import java.util.regex.Matcher;
15+
import java.util.regex.Pattern;
1416

1517
public class MinionLevelAdder extends SlotTextAdder {
18+
private static final Pattern MINION_PATTERN = Pattern.compile(".* Minion ([IVXLCDM]+)");
1619
public MinionLevelAdder() {
1720
super();
1821
}
@@ -21,11 +24,11 @@ public MinionLevelAdder() {
2124
public @NotNull List<SlotText> getText(Slot slot) {
2225
ItemStack itemStack = slot.getStack();
2326
if (!itemStack.isOf(Items.PLAYER_HEAD)) return List.of();
24-
String name = itemStack.getName().getString();
25-
if (!name.contains("Minion")) return List.of();
26-
String romanNumeral = name.substring(name.lastIndexOf(' ') + 1); //+1 because we don't need the space itself
27+
Matcher matcher = MINION_PATTERN.matcher(itemStack.getName().getString());
28+
if (!matcher.matches()) return List.of();
29+
String romanNumeral = matcher.group(1);
30+
if (!RomanNumerals.isValidRomanNumeral(romanNumeral)) return List.of();
2731
int level = RomanNumerals.romanToDecimal(romanNumeral);
28-
if (level == 0) return List.of();
2932
return List.of(SlotText.topRight(Text.literal(String.valueOf(level)).formatted(Formatting.AQUA)));
3033
}
3134
}

src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractContainerMatcher.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.hysky.skyblocker.utils.render.gui;
22

33
import de.hysky.skyblocker.skyblock.ChestValue;
4+
import org.jetbrains.annotations.NotNull;
45
import org.jetbrains.annotations.Nullable;
56

67
import java.util.regex.Pattern;
@@ -14,11 +15,11 @@ public abstract class AbstractContainerMatcher {
1415
@Nullable
1516
public final Pattern titlePattern;
1617

17-
public AbstractContainerMatcher() {
18+
protected AbstractContainerMatcher() {
1819
this((Pattern) null);
1920
}
2021

21-
public AbstractContainerMatcher(String titlePattern) {
22+
protected AbstractContainerMatcher(@NotNull String titlePattern) {
2223
this(Pattern.compile(titlePattern));
2324
}
2425

0 commit comments

Comments
 (0)