Skip to content

Commit 37c9e61

Browse files
added hidden_gem_categories and renamed override_affix_name_on_rename
1 parent 04aa9cb commit 37c9e61

4 files changed

Lines changed: 134 additions & 13 deletions

File tree

src/main/java/com/nightwielder/apothictooltipcleanup/Config.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class Config {
2727
public static final ModConfigSpec.ConfigValue<String> GEM_TOOLTIP_MODE;
2828
public static final ModConfigSpec.BooleanValue COMPACT_GEM_DISPLAY;
2929
public static final ModConfigSpec.BooleanValue HIDE_FITS_IN;
30+
public static final ModConfigSpec.ConfigValue<List<? extends String>> HIDDEN_GEM_CATEGORIES;
3031

3132
// Sockets
3233
public static final ModConfigSpec.BooleanValue MERGE_EMPTY_SOCKETS;
@@ -43,7 +44,7 @@ public class Config {
4344

4445
// ===== Server spec =====
4546
// Anvil
46-
public static final ModConfigSpec.BooleanValue STRIP_AFFIX_NAME_ON_RENAME;
47+
public static final ModConfigSpec.BooleanValue OVERRIDE_AFFIX_NAME_ON_RENAME;
4748

4849
static {
4950
ModConfigSpec.Builder builder = new ModConfigSpec.Builder();
@@ -102,6 +103,9 @@ public class Config {
102103
builder.comment(" Deprecated, use gem_tooltip_mode instead.");
103104
HIDE_FITS_IN = builder.define("hide_fits_in", false);
104105

106+
builder.comment(" Case-insensitive list of gem categories to hide from Fits In tooltips.");
107+
HIDDEN_GEM_CATEGORIES = builder.defineListAllowEmpty("hidden_gem_categories", List.of(), () -> "", o -> o instanceof String);
108+
105109
builder.comment(" sockets",
106110
" ============================================================",
107111
" Merges empty sockets into one summary line.",
@@ -145,9 +149,9 @@ public class Config {
145149

146150
serverBuilder.push("anvil");
147151

148-
serverBuilder.comment(" Anvil renames remove Apotheosis prefix/suffix decoration.",
152+
serverBuilder.comment(" Anvil renames override Apotheosis prefix/suffix decoration.",
149153
" Affixes, sockets, and rarity color stay intact. Server-side.");
150-
STRIP_AFFIX_NAME_ON_RENAME = serverBuilder.define("strip_affix_name_on_rename", false);
154+
OVERRIDE_AFFIX_NAME_ON_RENAME = serverBuilder.define("override_affix_name_on_rename", false);
151155

152156
serverBuilder.pop();
153157

src/main/java/com/nightwielder/apothictooltipcleanup/handler/AffixCooldownStripper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.nightwielder.apothictooltipcleanup.Config;
44
import com.nightwielder.apothictooltipcleanup.util.TooltipMatcher;
5+
import net.minecraft.ChatFormatting;
56
import net.minecraft.network.chat.Component;
67

78
import java.util.List;
@@ -10,6 +11,9 @@
1011

1112
public final class AffixCooldownStripper {
1213
private static final Pattern COOLDOWN_MARKER = Pattern.compile("\\s*\\[⌛\\s*\\d+:\\d+\\]");
14+
// The dot_prefix template renders its own "• " bullet, so we drop the bullet that the
15+
// pre-render string carried before re-wrapping the cleaned body.
16+
private static final Pattern LEADING_BULLET = Pattern.compile("^•\\s*");
1317

1418
private AffixCooldownStripper() {}
1519

@@ -25,7 +29,8 @@ public static void apply(List<Component> tooltip) {
2529
if (text.indexOf('⌛') < 0) continue;
2630
String cleaned = COOLDOWN_MARKER.matcher(text).replaceAll("");
2731
if (!cleaned.equals(text)) {
28-
it.set(Component.translatable("text.apotheosis.dot_prefix", Component.literal(cleaned)));
32+
String body = LEADING_BULLET.matcher(cleaned).replaceFirst("");
33+
it.set(Component.translatable("text.apotheosis.dot_prefix", Component.literal(body)).withStyle(ChatFormatting.YELLOW));
2934
}
3035
}
3136
}

src/main/java/com/nightwielder/apothictooltipcleanup/handler/AnvilRenameOverride.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private AnvilRenameOverride() {}
2222

2323
@SubscribeEvent
2424
public static void onAnvilUpdate(AnvilUpdateEvent event) {
25-
if (!Config.STRIP_AFFIX_NAME_ON_RENAME.get()) return;
25+
if (!Config.OVERRIDE_AFFIX_NAME_ON_RENAME.get()) return;
2626
if (!ApotheosisDetector.isApotheosisLoaded()) return;
2727

2828
ItemStack left = event.getLeft();
@@ -35,7 +35,7 @@ public static void onAnvilUpdate(AnvilUpdateEvent event) {
3535
ItemStack output = left.copy();
3636
output.set(DataComponents.CUSTOM_NAME, Component.literal(name));
3737

38-
Style wrapperStyle = Style.EMPTY.withItalic(false);
38+
Style wrapperStyle = Style.EMPTY;
3939
DynamicHolder<LootRarity> rarity = AffixHelper.getRarity(output);
4040
if (rarity.isBound()) {
4141
wrapperStyle = wrapperStyle.withColor(rarity.get().color());

src/main/java/com/nightwielder/apothictooltipcleanup/handler/FitsInRemover.java

Lines changed: 119 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ private FitsInRemover() {}
3838

3939
public static void apply(List<Component> tooltip) {
4040
String mode = Config.GEM_TOOLTIP_MODE.get();
41-
if ("full".equalsIgnoreCase(mode)) return;
41+
if ("full".equalsIgnoreCase(mode)) {
42+
applyFullCategoryFilter(tooltip);
43+
return;
44+
}
4245

4346
boolean hidden = "hidden".equalsIgnoreCase(mode);
4447
boolean compact = "compact".equalsIgnoreCase(mode);
@@ -71,17 +74,45 @@ public static void apply(List<Component> tooltip) {
7174

7275
if (isFits) {
7376
if (ultra) {
74-
List<String> names = sortByGroup(extractCategoryNames(tooltip, i + 1, afterBullets));
77+
List<String> names = sortByGroup(filterHidden(extractCategoryNames(tooltip, i + 1, afterBullets)));
7578
removeRange(tooltip, i, afterBullets);
7679
if (!names.isEmpty()) {
7780
tooltip.add(i, joinedCategoryBullet(String.join(", ", names)));
7881
i++;
7982
}
8083
continue;
8184
}
82-
// compact: replace the header with a plain teal "Fits in:" line, leave category bullets below.
85+
// compact: replace the header with a plain teal "Fits in:" line, then drop any
86+
// hidden categories from the bullets below it.
8387
tooltip.set(i, fitsInHeaderBullet());
88+
int headerIndex = i;
8489
i++;
90+
int bulletIndex = i;
91+
while (bulletIndex < afterBullets
92+
&& TooltipMatcher.keyStartsWith(tooltip.get(bulletIndex), "text.apotheosis.dot_prefix")) {
93+
String inner = extractBulletText(tooltip.get(bulletIndex));
94+
if (inner == null || inner.isEmpty()) {
95+
bulletIndex++;
96+
continue;
97+
}
98+
List<String> names = splitCategories(inner);
99+
List<String> kept = filterHidden(names);
100+
if (kept.size() == names.size()) {
101+
bulletIndex++;
102+
} else if (kept.isEmpty()) {
103+
tooltip.remove(bulletIndex);
104+
afterBullets--;
105+
} else {
106+
tooltip.set(bulletIndex, categoryBullet(String.join(", ", kept)));
107+
bulletIndex++;
108+
}
109+
}
110+
// Every category bullet filtered out leaves the header with nothing below it; drop it.
111+
if (headerIndex + 1 >= tooltip.size()
112+
|| !TooltipMatcher.keyStartsWith(tooltip.get(headerIndex + 1), "text.apotheosis.dot_prefix")) {
113+
tooltip.remove(headerIndex);
114+
i--;
115+
}
85116
continue;
86117
}
87118

@@ -118,6 +149,59 @@ public static void apply(List<Component> tooltip) {
118149
cleanupOrphanBlanks(tooltip);
119150
}
120151

152+
// Full mode preserves Apoth's native gem layout, so we only filter the Fits In category list
153+
// and leave everything else (header text, bonus block, blank lines) untouched.
154+
private static void applyFullCategoryFilter(List<Component> tooltip) {
155+
List<? extends String> hiddenCategories = Config.HIDDEN_GEM_CATEGORIES.get();
156+
if (hiddenCategories == null || hiddenCategories.isEmpty()) return;
157+
158+
int i = 0;
159+
while (i < tooltip.size()) {
160+
String key = TooltipMatcher.getKey(tooltip.get(i));
161+
boolean isFits = key != null
162+
&& (key.startsWith("text.apotheosis.socketable_into") || key.startsWith("text.apotheosis.fits_in"));
163+
if (!isFits) {
164+
i++;
165+
continue;
166+
}
167+
168+
int headerIndex = i;
169+
int bulletIndex = i + 1;
170+
int afterBullets = bulletIndex;
171+
while (afterBullets < tooltip.size()
172+
&& TooltipMatcher.keyStartsWith(tooltip.get(afterBullets), "text.apotheosis.dot_prefix")) {
173+
afterBullets++;
174+
}
175+
176+
while (bulletIndex < afterBullets) {
177+
String inner = extractBulletText(tooltip.get(bulletIndex));
178+
if (inner == null || inner.isEmpty()) {
179+
bulletIndex++;
180+
continue;
181+
}
182+
List<String> names = splitCategories(inner);
183+
List<String> kept = filterHidden(names);
184+
if (kept.size() == names.size()) {
185+
bulletIndex++;
186+
} else if (kept.isEmpty()) {
187+
tooltip.remove(bulletIndex);
188+
afterBullets--;
189+
} else {
190+
tooltip.set(bulletIndex, categoryBullet(String.join(", ", kept)));
191+
bulletIndex++;
192+
}
193+
}
194+
195+
if (headerIndex + 1 >= tooltip.size()
196+
|| !TooltipMatcher.keyStartsWith(tooltip.get(headerIndex + 1), "text.apotheosis.dot_prefix")) {
197+
tooltip.remove(headerIndex);
198+
i = headerIndex;
199+
} else {
200+
i = afterBullets;
201+
}
202+
}
203+
}
204+
121205
private static Component joinedCategoryBullet(String text) {
122206
return Component.translatable("text.apotheosis.dot_prefix",
123207
Component.literal("Fits in: " + text))
@@ -176,14 +260,42 @@ private static List<String> extractCategoryNames(List<Component> tooltip, int fr
176260
for (int k = from; k < toExclusive; k++) {
177261
String inner = extractBulletText(tooltip.get(k));
178262
if (inner == null || inner.isEmpty()) continue;
179-
for (String part : inner.split(",")) {
180-
String trimmed = part.trim();
181-
if (!trimmed.isEmpty()) names.add(trimmed);
182-
}
263+
names.addAll(splitCategories(inner));
183264
}
184265
return names;
185266
}
186267

268+
// Splits a category bullet's inner text ("Swords, Bows, ...") into trimmed, non-empty names.
269+
private static List<String> splitCategories(String inner) {
270+
List<String> names = new ArrayList<>();
271+
for (String part : inner.split(",")) {
272+
String trimmed = part.trim();
273+
if (!trimmed.isEmpty()) names.add(trimmed);
274+
}
275+
return names;
276+
}
277+
278+
// Drops any category names listed in the hidden_gem_categories config, case-insensitively.
279+
private static List<String> filterHidden(List<String> categories) {
280+
List<? extends String> hidden = Config.HIDDEN_GEM_CATEGORIES.get();
281+
if (hidden == null || hidden.isEmpty()) return categories;
282+
Set<String> hiddenSet = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
283+
hiddenSet.addAll(hidden);
284+
List<String> filtered = new ArrayList<>(categories.size());
285+
for (String name : categories) {
286+
if (!hiddenSet.contains(name)) filtered.add(name);
287+
}
288+
return filtered;
289+
}
290+
291+
// Rebuilds a Fits-In category bullet after hidden categories are dropped, preserving the teal
292+
// styling Apoth uses natively. Used by compact mode (after the synthesized header) and full mode
293+
// (under Apoth's original header).
294+
private static Component categoryBullet(String text) {
295+
return Component.translatable("text.apotheosis.dot_prefix", Component.literal(text))
296+
.withStyle(Style.EMPTY.withColor(FITS_IN_COLOR));
297+
}
298+
187299
private static void stripUnique(List<Component> tooltip) {
188300
int j = 0;
189301
while (j < tooltip.size()) {

0 commit comments

Comments
 (0)