aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAaron <51387595+AzureAaron@users.noreply.github.com>2024-07-13 15:12:46 -0400
committerGitHub <noreply@github.com>2024-07-13 15:12:46 -0400
commit5b7ac9f48a8c684b3e20f9d7d9447d4a5860b603 (patch)
treea8800e53ae7dbacbec8702274c9ca6a7573140cf /src
parentb9378e6f8c57fe811ee87dbcce0b328edd06489b (diff)
downloadSkyblocker-5b7ac9f48a8c684b3e20f9d7d9447d4a5860b603.tar.gz
Skyblocker-5b7ac9f48a8c684b3e20f9d7d9447d4a5860b603.tar.bz2
Skyblocker-5b7ac9f48a8c684b3e20f9d7d9447d4a5860b603.zip
Aaron's Mod compatibility for profile viewer (#833)
Diffstat (limited to 'src')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemStackBuilder.java5
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java2
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/profileviewer/inventory/itemLoaders/ItemLoader.java10
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/TextTransformer.java92
4 files changed, 105 insertions, 4 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemStackBuilder.java b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemStackBuilder.java
index 01ffc144..ab61b684 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemStackBuilder.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemStackBuilder.java
@@ -2,6 +2,7 @@ package de.hysky.skyblocker.skyblock.itemlist;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.NEURepoManager;
+import de.hysky.skyblocker.utils.TextTransformer;
import io.github.moulberry.repo.constants.PetNumbers;
import io.github.moulberry.repo.data.NEUItem;
import io.github.moulberry.repo.data.Rarity;
@@ -53,10 +54,10 @@ public class ItemStackBuilder {
// Item Name
String name = injectData(item.getDisplayName(), injectors);
- stack.set(DataComponentTypes.CUSTOM_NAME, Text.of(name));
+ stack.set(DataComponentTypes.CUSTOM_NAME, TextTransformer.fromLegacy(name));
// Lore
- stack.set(DataComponentTypes.LORE, new LoreComponent(item.getLore().stream().map(line -> Text.of(injectData(line, injectors))).toList()));
+ stack.set(DataComponentTypes.LORE, new LoreComponent(item.getLore().stream().map(line -> TextTransformer.fromLegacy(injectData(line, injectors))).map(Text.class::cast).toList()));
String nbttag = item.getNbttag();
// add skull texture
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java b/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java
index 306fe279..a9f83ca8 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/collections/GenericCategory.java
@@ -132,6 +132,8 @@ public class GenericCategory implements ProfileViewerPage {
String[] parts = tierText.split("/");
int cTier = Integer.parseInt(parts[0].trim());
Color colour = itemStack.hasGlint() ? Color.MAGENTA : Color.darkGray;
+ //DO NOT CHANGE THIS METHOD CALL! Aaron's Mod mixes in here to provide chroma text for max collections
+ //and changing the method called here will break that! Consult Aaron before making any changes :)
context.drawText(textRenderer, Text.literal(toRomanNumerals(cTier)), x + 9 - (textRenderer.getWidth(toRomanNumerals(cTier)) / 2), y + 21, colour.getRGB(), false);
}
break;
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/inventory/itemLoaders/ItemLoader.java b/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/inventory/itemLoaders/ItemLoader.java
index f3045c11..11280af1 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/inventory/itemLoaders/ItemLoader.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/profileviewer/inventory/itemLoaders/ItemLoader.java
@@ -3,6 +3,7 @@ package de.hysky.skyblocker.skyblock.profileviewer.inventory.itemLoaders;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mojang.serialization.JsonOps;
+
import de.hysky.skyblocker.skyblock.PetCache;
import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
import de.hysky.skyblocker.skyblock.profileviewer.ProfileViewerScreen;
@@ -10,6 +11,7 @@ import de.hysky.skyblocker.skyblock.profileviewer.inventory.Pet;
import de.hysky.skyblocker.skyblock.tabhud.util.Ico;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.NEURepoManager;
+import de.hysky.skyblocker.utils.TextTransformer;
import io.github.moulberry.repo.data.NEUItem;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.*;
@@ -21,6 +23,7 @@ import net.minecraft.registry.Registries;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
+import net.minecraft.util.Util;
import java.io.ByteArrayInputStream;
import java.util.*;
@@ -79,13 +82,13 @@ public class ItemLoader {
// Item Name
- stack.set(DataComponentTypes.CUSTOM_NAME, Text.of(nbttag.getCompound("display").getString("Name")));
+ stack.set(DataComponentTypes.CUSTOM_NAME, TextTransformer.fromLegacy(nbttag.getCompound("display").getString("Name")));
// Lore
NbtList loreList = nbttag.getCompound("display").getList("Lore", 8);
stack.set(DataComponentTypes.LORE, new LoreComponent(loreList.stream()
.map(NbtElement::asString)
- .map(Text::literal)
+ .map(TextTransformer::fromLegacy)
.collect(Collectors.toList())));
// add skull texture
@@ -111,6 +114,9 @@ public class ItemLoader {
// Set Count
stack.setCount(containerContent.getCompound(i).getInt("Count"));
+ // Attach an override for Aaron's Mod so that these ItemStacks will work with the mod's features even when not in Skyblock
+ extraAttributes.put("aaron-mod", Util.make(new NbtCompound(), comp -> comp.putBoolean("alwaysDisplaySkyblockInfo", true)));
+
stack.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(extraAttributes));
itemList.add(stack);
diff --git a/src/main/java/de/hysky/skyblocker/utils/TextTransformer.java b/src/main/java/de/hysky/skyblocker/utils/TextTransformer.java
new file mode 100644
index 00000000..b8fb5101
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/utils/TextTransformer.java
@@ -0,0 +1,92 @@
+package de.hysky.skyblocker.utils;
+
+import org.jetbrains.annotations.NotNull;
+
+import it.unimi.dsi.fastutil.chars.CharList;
+import net.minecraft.text.MutableText;
+import net.minecraft.text.Style;
+import net.minecraft.text.Text;
+import net.minecraft.util.Formatting;
+
+/**
+ * Contains utilities for transforming text. These methods are from Aaron's Mod.
+ *
+ * @author AzureAaron
+ */
+public class TextTransformer {
+ private static final CharList FORMAT_CODES = CharList.of('4', 'c', '6', 'e', '2', 'a','b', '3', '1', '9', 'd', '5', 'f', '7', '8', '0', 'r', 'k', 'l', 'm', 'n', 'o');
+
+ /**
+ * Converts strings with section symbol/legacy formatting to MutableText objects.
+ *
+ * @param legacy The string with legacy formatting to be transformed
+ * @return A {@link MutableText} object matching the exact formatting of the input
+ *
+ * @author AzureAaron
+ */
+ public static MutableText fromLegacy(@NotNull String legacy) {
+ MutableText newText = Text.empty();
+ StringBuilder builder = new StringBuilder();
+ Formatting formatting = null;
+ boolean bold = false;
+ boolean italic = false;
+ boolean underline = false;
+ boolean strikethrough = false;
+ boolean obfuscated = false;
+
+ for (int i = 0; i < legacy.length(); i++) {
+ //If we've encountered a new formatting code then append the text from the previous "sequence" and reset state
+ if (i != 0 && legacy.charAt(i - 1) == '§' && FORMAT_CODES.contains(Character.toLowerCase(legacy.charAt(i))) && !builder.isEmpty()) {
+ newText.append(Text.literal(builder.toString()).setStyle(Style.EMPTY
+ .withColor(formatting)
+ .withBold(bold)
+ .withItalic(italic)
+ .withUnderline(underline)
+ .withStrikethrough(strikethrough)
+ .withObfuscated(obfuscated)));
+
+ //Erase all characters in the builder so we can reuse it, also clear formatting
+ builder.delete(0, builder.length());
+ formatting = null;
+ bold = false;
+ italic = false;
+ underline = false;
+ strikethrough = false;
+ obfuscated = false;
+ }
+
+ if (i != 0 && legacy.charAt(i - 1) == '§') {
+ Formatting fmt = Formatting.byCode(legacy.charAt(i));
+
+ switch (fmt) {
+ case BOLD -> bold = true;
+ case ITALIC -> italic = true;
+ case UNDERLINE -> underline = true;
+ case STRIKETHROUGH -> strikethrough = true;
+ case OBFUSCATED -> obfuscated = true;
+
+ default -> formatting = fmt;
+ }
+
+ continue;
+ }
+
+ //This character isn't the start of a formatting sequence or this character isn't part of a formatting sequence
+ if (legacy.charAt(i) != '§' && (i == 0 || (i != 0 && legacy.charAt(i - 1) != '§'))) {
+ builder.append(legacy.charAt(i));
+ }
+
+ // We've read the last character so append the last text with all of the formatting
+ if (i == legacy.length() - 1) {
+ newText.append(Text.literal(builder.toString()).setStyle(Style.EMPTY
+ .withColor(formatting)
+ .withBold(bold)
+ .withItalic(italic)
+ .withUnderline(underline)
+ .withStrikethrough(strikethrough)
+ .withObfuscated(obfuscated)));
+ }
+ }
+ return newText;
+ }
+}