Skip to content

Commit fb47aa0

Browse files
committed
some small changes / cleanup
1 parent dfd5611 commit fb47aa0

4 files changed

Lines changed: 22 additions & 82 deletions

File tree

commons/src/main/java/net/swofty/commons/StringUtility.java

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ public static String getFormatedStatistic(ItemStatistic statistic) {
281281
return statistic.getDisplayColor() + statistic.getSymbol() + " " + statistic.getDisplayName();
282282
}
283283

284-
/*
285284
public static List<String> centerLines(List<String> lines) {
286285
int maxLength = lines.stream()
287286
.map(StringUtility::stripColor)
@@ -298,69 +297,4 @@ public static List<String> centerLines(List<String> lines) {
298297

299298
return centered;
300299
}
301-
*/
302-
303-
//TODO fix this stupid centering
304-
public static List<String> centerLines(List<String> lines) {
305-
int CHAT_WIDTH_PIXELS = 320;
306-
int SPACE_WIDTH = 4; // Minecraft space width
307-
List<String> centered = new ArrayList<>();
308-
309-
for (String line : lines) {
310-
if (line.isEmpty()) {
311-
centered.add(line);
312-
continue;
313-
}
314-
315-
boolean bold = false;
316-
int pixelWidth = 0;
317-
int formatCodeCount = 0;
318-
319-
// Calculate visible width and count format codes
320-
for (int i = 0; i < line.length(); i++) {
321-
char c = line.charAt(i);
322-
if (c == '§' && i + 1 < line.length()) {
323-
char code = line.charAt(i + 1);
324-
if (code == 'l') bold = true;
325-
else if (code == 'r') bold = false;
326-
formatCodeCount += 2;
327-
i++; // Skip format code
328-
continue;
329-
}
330-
pixelWidth += getCharWidth(c, bold) + 1; // +1 for character spacing
331-
}
332-
333-
// Subtract the last character's spacing
334-
if (pixelWidth > 0) pixelWidth--;
335-
336-
// Calculate padding
337-
int padding = (CHAT_WIDTH_PIXELS - pixelWidth) / 2;
338-
int spaces = Math.max(0, padding / SPACE_WIDTH);
339-
340-
// Add extra space if needed (Minecraft rendering quirk)
341-
if (padding % SPACE_WIDTH >= 2) {
342-
spaces++;
343-
}
344-
System.out.printf("Line (%.3f px): %s\n", (float)pixelWidth, line.replace("§", "&"));
345-
346-
centered.add(" ".repeat(spaces) + line);
347-
}
348-
349-
return centered;
350-
}
351-
352-
private static int getCharWidth(char c, boolean bold) {
353-
// Special case for certain characters
354-
if (c == '➡') return 6; // Arrow character
355-
if (c == '✯') return 7; // Star character
356-
357-
return switch (c) {
358-
case ' ', 'I', '[', ']', 't' -> 4;
359-
case '!', '.', ',', ':', ';', 'i', '|' -> 2;
360-
case '\'', '`', 'l' -> 3;
361-
case '*', 'f', 'k', '<', '>' -> 5;
362-
case '§' -> 0;
363-
default -> bold ? 6 : 5;
364-
};
365-
}
366300
}

type.generic/src/main/java/net/swofty/types/generic/data/datapoints/DatapointBestiary.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,14 @@ public List<String> getDisplay(List<String> lore, int kills, BestiaryMob mob, Be
111111
double currentRequirement = bestiaryData.getTotalKillsForNextTier(bracket, tier + 1);
112112
double totalRequirement = bestiaryData.getTotalKillsForMaxTier(mob);
113113

114+
String baseLoadingBar = "─────────────────";
115+
int maxBarLength = baseLoadingBar.length();
116+
int formattingCodeLength = 4;
117+
114118
lore.add("§7" + bestiaryEntry.getDescription());
115119
lore.add("");
116120
lore.add("§7Kills: §a" + kills);
117-
lore.add("§7Deaths: §a TO BE DONE"); //TODO add datapoint for amount of deaths
121+
lore.add("§7Deaths: §a" + "TODO"); //TODO add datapoint for amount of deaths
118122
lore.add("");
119123

120124
if (tier > 0) {
@@ -123,24 +127,26 @@ public List<String> getDisplay(List<String> lore, int kills, BestiaryMob mob, Be
123127
}
124128

125129
// Current tier progress
126-
int unlockedPercentage = (int) (currentProgress / currentRequirement * 100);
127-
lore.add("§7Progress to Tier " + StringUtility.getAsRomanNumeral(tier + 1) + " §b" + unlockedPercentage + "%");
128-
129-
String baseLoadingBar = "─────────────────";
130-
int maxBarLength = baseLoadingBar.length();
131-
int completedLength = (int) Math.round((currentProgress / currentRequirement) * maxBarLength);
130+
if (tier < mob.getMaxBestiaryTier()) {
131+
int unlockedPercentage = (int) (currentProgress / currentRequirement * 100);
132+
lore.add("§7Progress to Tier " + StringUtility.getAsRomanNumeral(tier + 1) + " §b" + unlockedPercentage + "%");
132133

133-
String completedLoadingBar = "§3§m" + baseLoadingBar.substring(0, Math.min(completedLength, maxBarLength));
134-
int formattingCodeLength = 4;
135-
String uncompletedLoadingBar = "§f§m" + baseLoadingBar.substring(Math.min(completedLoadingBar.length() - formattingCodeLength, maxBarLength));
134+
int completedLength = (int) Math.round((currentProgress / currentRequirement) * maxBarLength);
136135

137-
lore.add(completedLoadingBar + uncompletedLoadingBar + "§r §b" + StringUtility.commaify(currentProgress) + "§3/§b" + StringUtility.shortenNumber(currentRequirement));
136+
String completedLoadingBar = "§3§m" + baseLoadingBar.substring(0, Math.min(completedLength, maxBarLength));
137+
String uncompletedLoadingBar = "§f§m" + baseLoadingBar.substring(Math.min(completedLoadingBar.length() - formattingCodeLength, maxBarLength));
138138

139-
lore.add("");
139+
lore.add(completedLoadingBar + uncompletedLoadingBar + "§r §b" + StringUtility.commaify(currentProgress) + "§3/§b" + StringUtility.shortenNumber(currentRequirement));
140+
lore.add("");
141+
}
140142

141143
// Total kill progress*
142144
int totalUnlockedPercentage = (int) (kills / totalRequirement * 100);
143-
lore.add("§7Overall Progress: §b" + totalUnlockedPercentage + "%");
145+
if (tier < mob.getMaxBestiaryTier()) {
146+
lore.add("§7Overall Progress: §b" + totalUnlockedPercentage + "%");
147+
} else {
148+
lore.add("§7Overall Progress: §b" + totalUnlockedPercentage + "% §7(§c§lMAX!§7)");
149+
}
144150

145151
int totalCompletedLength = (int) Math.round((kills / totalRequirement) * maxBarLength);
146152
String totalCompletedBar = "§3§m" + baseLoadingBar.substring(0, Math.min(totalCompletedLength, maxBarLength));
@@ -150,9 +156,10 @@ public List<String> getDisplay(List<String> lore, int kills, BestiaryMob mob, Be
150156

151157
if (mob.getMaxBestiaryTier() > tier) {
152158
lore.add("§8Capped at Tier " + StringUtility.getAsRomanNumeral(mob.getMaxBestiaryTier()));
153-
lore.add("");
154159
}
155160

161+
lore.add("");
162+
156163
if (tier < mob.getMaxBestiaryTier()) {
157164
bestiaryData.getNextBonuses(lore, bestiaryEntry.getName(), tier + 1);
158165
lore.add("");

type.generic/src/main/java/net/swofty/types/generic/entity/mob/impl/RegionPopulator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public interface RegionPopulator {
1414
List<Populator> getPopulators();
1515

1616
static void populateRegion(MobRegistry registry, Populator populator) {
17+
if (SkyBlockConst.getInstanceContainer() == null) return;
1718
SkyBlockRegion region = SkyBlockRegion.getRandomRegionOfType(populator.regionType());
1819

1920
if (region == null) return;

type.generic/src/main/java/net/swofty/types/generic/event/actions/custom/bestiary/ActionBestiaryLevelUp.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public void run(BestiaryUpdateEvent event) {
4949

5050
List<String> lines = new ArrayList<>();
5151
lines.add("");
52-
lines.add("§6§lREWARDS");
5352
lines.add("§6§lBESTIARY");
5453
lines.add(transitionLine);
5554
lines.add("");
@@ -72,7 +71,6 @@ public void run(BestiaryUpdateEvent event) {
7271

7372
message.append("§3§l").append("▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬");
7473

75-
System.out.println(message);
7674
player.sendMessage(message.toString());
7775
}
7876
}

0 commit comments

Comments
 (0)