aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker
diff options
context:
space:
mode:
authorAaron <51387595+AzureAaron@users.noreply.github.com>2024-04-23 12:15:49 -0400
committerAaron <51387595+AzureAaron@users.noreply.github.com>2024-04-26 16:23:21 -0400
commit330f8286d4e925f9a5c7ae5629e979edaf948363 (patch)
treed4b435e1596d7a73410cc945d5e7085b1cb62ac4 /src/main/java/de/hysky/skyblocker
parent07f6469fffac314ac529794e159b266bc49fc6af (diff)
downloadSkyblocker-330f8286d4e925f9a5c7ae5629e979edaf948363.tar.gz
Skyblocker-330f8286d4e925f9a5c7ae5629e979edaf948363.tar.bz2
Skyblocker-330f8286d4e925f9a5c7ae5629e979edaf948363.zip
Handle removal/flattening of the ExtraAttributes tag
The tag doesn't exist anymore, the data is no longer "nested" under it.
Diffstat (limited to 'src/main/java/de/hysky/skyblocker')
-rw-r--r--src/main/java/de/hysky/skyblocker/mixin/DrawContextMixin.java6
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/TeleportOverlay.java12
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorDeletorPreview.java9
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java52
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemStackBuilder.java4
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/ItemUtils.java67
6 files changed, 63 insertions, 87 deletions
diff --git a/src/main/java/de/hysky/skyblocker/mixin/DrawContextMixin.java b/src/main/java/de/hysky/skyblocker/mixin/DrawContextMixin.java
index e2979040..6654bae6 100644
--- a/src/main/java/de/hysky/skyblocker/mixin/DrawContextMixin.java
+++ b/src/main/java/de/hysky/skyblocker/mixin/DrawContextMixin.java
@@ -36,10 +36,10 @@ public abstract class DrawContextMixin {
if (!SkyblockerConfigManager.get().general.itemInfoDisplay.attributeShardInfo) return;
if (Utils.isOnSkyblock()) {
- NbtCompound extraAttributes = ItemUtils.getExtraAttributes(stack);
+ NbtCompound customData = ItemUtils.getCustomData(stack);
- if (extraAttributes != null && extraAttributes.getString(ItemUtils.ID).equals("ATTRIBUTE_SHARD")) {
- NbtCompound attributesTag = extraAttributes.getCompound("attributes");
+ if (ItemUtils.getItemId(stack).equals("ATTRIBUTE_SHARD")) {
+ NbtCompound attributesTag = customData.getCompound("attributes");
String[] attributes = attributesTag.getKeys().toArray(String[]::new);
if (attributes.length != 0) {
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/TeleportOverlay.java b/src/main/java/de/hysky/skyblocker/skyblock/TeleportOverlay.java
index bc0eede8..392360e7 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/TeleportOverlay.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/TeleportOverlay.java
@@ -28,7 +28,7 @@ public class TeleportOverlay {
if (Utils.isOnSkyblock() && SkyblockerConfigManager.get().general.teleportOverlay.enableTeleportOverlays && client.player != null && client.world != null) {
ItemStack heldItem = client.player.getMainHandStack();
String itemId = ItemTooltip.getInternalNameFromNBT(heldItem, true);
- NbtCompound extraAttributes = ItemUtils.getExtraAttributes(heldItem);
+ NbtCompound customData = ItemUtils.getCustomData(heldItem);
if (itemId != null) {
switch (itemId) {
@@ -43,20 +43,20 @@ public class TeleportOverlay {
}
}
case "ASPECT_OF_THE_END", "ASPECT_OF_THE_VOID" -> {
- if (SkyblockerConfigManager.get().general.teleportOverlay.enableEtherTransmission && client.options.sneakKey.isPressed() && extraAttributes != null && extraAttributes.getInt("ethermerge") == 1) {
- render(wrc, extraAttributes, 57);
+ if (SkyblockerConfigManager.get().general.teleportOverlay.enableEtherTransmission && client.options.sneakKey.isPressed() && customData != null && customData.getInt("ethermerge") == 1) {
+ render(wrc, customData, 57);
} else if (SkyblockerConfigManager.get().general.teleportOverlay.enableInstantTransmission) {
- render(wrc, extraAttributes, 8);
+ render(wrc, customData, 8);
}
}
case "ETHERWARP_CONDUIT" -> {
if (SkyblockerConfigManager.get().general.teleportOverlay.enableEtherTransmission) {
- render(wrc, extraAttributes, 57);
+ render(wrc, customData, 57);
}
}
case "SINSEEKER_SCYTHE" -> {
if (SkyblockerConfigManager.get().general.teleportOverlay.enableSinrecallTransmission) {
- render(wrc, extraAttributes, 4);
+ render(wrc, customData, 4);
}
}
case "NECRON_BLADE", "ASTRAEA", "HYPERION", "SCYLLA", "VALKYRIE" -> {
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorDeletorPreview.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorDeletorPreview.java
index 657db0c9..392ee100 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorDeletorPreview.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/CompactorDeletorPreview.java
@@ -40,10 +40,9 @@ public class CompactorDeletorPreview {
if (targetIndex == -1) return false;
// Get items in compactor or deletor
- NbtCompound extraAttributes = ItemUtils.getExtraAttributes(stack);
- if (extraAttributes == null) return false;
+ NbtCompound customData = ItemUtils.getCustomData(stack);
// Get the slots and their items from the nbt, which is in the format personal_compact_<slot_number> or personal_deletor_<slot_number>
- List<IntObjectPair<ItemStack>> slots = extraAttributes.getKeys().stream().filter(slot -> slot.contains(type.toLowerCase().substring(0, 7))).map(slot -> IntObjectPair.of(Integer.parseInt(slot.substring(17)), ItemRepository.getItemStack(extraAttributes.getString(slot)))).toList();
+ List<IntObjectPair<ItemStack>> slots = customData.getKeys().stream().filter(slot -> slot.contains(type.toLowerCase().substring(0, 7))).map(slot -> IntObjectPair.of(Integer.parseInt(slot.substring(17)), ItemRepository.getItemStack(customData.getString(slot)))).toList();
List<TooltipComponent> components = tooltips.stream().map(Text::asOrderedText).map(TooltipComponent::of).collect(Collectors.toList());
IntIntPair dimensions = DIMENSIONS.getOrDefault(size, DEFAULT_DIMENSION);
@@ -60,9 +59,9 @@ public class CompactorDeletorPreview {
// Add the preview tooltip component
components.add(targetIndex, new CompactorPreviewTooltipComponent(slots, dimensions));
- if (extraAttributes.contains("PERSONAL_DELETOR_ACTIVE")) {
+ if (customData.contains("PERSONAL_DELETOR_ACTIVE")) {
components.add(targetIndex, TooltipComponent.of(Text.literal("Active: ")
- .append(extraAttributes.getBoolean("PERSONAL_DELETOR_ACTIVE") ? Text.literal("YES").formatted(Formatting.BOLD).formatted(Formatting.GREEN) : Text.literal("NO").formatted(Formatting.BOLD).formatted(Formatting.RED)).asOrderedText()));
+ .append(customData.getBoolean("PERSONAL_DELETOR_ACTIVE") ? Text.literal("YES").formatted(Formatting.BOLD).formatted(Formatting.GREEN) : Text.literal("NO").formatted(Formatting.BOLD).formatted(Formatting.RED)).asOrderedText()));
}
((DrawContextInvoker) context).invokeDrawTooltip(client.textRenderer, components, x, y, HoveredTooltipPositioner.INSTANCE);
return true;
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java
index 16d64707..d4d34e0f 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/ItemTooltip.java
@@ -140,17 +140,17 @@ public class ItemTooltip {
});
if (SkyblockerConfigManager.get().general.dungeonQuality) {
- NbtCompound ea = ItemUtils.getExtraAttributes(stack);
- if (ea != null && ea.contains("baseStatBoostPercentage")) {
- int baseStatBoostPercentage = ea.getInt("baseStatBoostPercentage");
+ NbtCompound customData = ItemUtils.getCustomData(stack);
+ if (customData != null && customData.contains("baseStatBoostPercentage")) {
+ int baseStatBoostPercentage = customData.getInt("baseStatBoostPercentage");
boolean maxQuality = baseStatBoostPercentage == 50;
if (maxQuality) {
lines.add(Text.literal(String.format("%-17s", "Item Quality:") + baseStatBoostPercentage + "/50").formatted(Formatting.RED).formatted(Formatting.BOLD));
} else {
lines.add(Text.literal(String.format("%-21s", "Item Quality:") + baseStatBoostPercentage + "/50").formatted(Formatting.BLUE));
}
- if (ea.contains("item_tier")) { // sometimes it just isn't here?
- int itemTier = ea.getInt("item_tier");
+ if (customData.contains("item_tier")) { // sometimes it just isn't here?
+ int itemTier = customData.getInt("item_tier");
if (maxQuality) {
lines.add(Text.literal(String.format("%-17s", "Floor Tier:") + itemTier + " (" + itemTierFloors.get(itemTier) + ")").formatted(Formatting.RED).formatted(Formatting.BOLD));
} else {
@@ -189,8 +189,8 @@ public class ItemTooltip {
lines.add(Text.literal(String.format(format, "Museum: (" + itemCategory + ")"))
.formatted(Formatting.LIGHT_PURPLE));
} else {
- NbtCompound extraAttributes = ItemUtils.getExtraAttributes(stack);
- boolean isInMuseum = (extraAttributes.contains("donated_museum") && extraAttributes.getBoolean("donated_museum")) || MuseumItemCache.hasItemInMuseum(internalID);
+ NbtCompound customData = ItemUtils.getCustomData(stack);
+ boolean isInMuseum = (customData.contains("donated_museum") && customData.getBoolean("donated_museum")) || MuseumItemCache.hasItemInMuseum(internalID);
Formatting donatedIndicatorFormatting = isInMuseum ? Formatting.GREEN : Formatting.RED;
@@ -216,13 +216,13 @@ public class ItemTooltip {
if (existingTooltip.startsWith("Color: ")) {
correctLine = true;
- addExoticTooltip(lines, internalID, ItemUtils.getCustomData(stack).copyNbt(), colorHex, expectedHex, existingTooltip);
+ addExoticTooltip(lines, internalID, ItemUtils.getCustomData(stack), colorHex, expectedHex, existingTooltip);
break;
}
}
if (!correctLine) {
- addExoticTooltip(lines, internalID, ItemUtils.getCustomData(stack).copyNbt(), colorHex, expectedHex, "");
+ addExoticTooltip(lines, internalID, ItemUtils.getCustomData(stack), colorHex, expectedHex, "");
}
}
}
@@ -291,57 +291,57 @@ public class ItemTooltip {
// TODO What in the world is this?
public static String getInternalNameFromNBT(ItemStack stack, boolean internalIDOnly) {
- NbtCompound ea = ItemUtils.getExtraAttributes(stack);
+ NbtCompound customData = ItemUtils.getCustomData(stack);
- if (ea == null || !ea.contains(ItemUtils.ID, NbtElement.STRING_TYPE)) {
+ if (customData == null || !customData.contains(ItemUtils.ID, NbtElement.STRING_TYPE)) {
return null;
}
- String internalName = ea.getString(ItemUtils.ID);
+ String internalName = customData.getString(ItemUtils.ID);
if (internalIDOnly) {
return internalName;
}
// Transformation to API format.
- if (ea.contains("is_shiny")) {
+ if (customData.contains("is_shiny")) {
return "ISSHINY_" + internalName;
}
switch (internalName) {
case "ENCHANTED_BOOK" -> {
- if (ea.contains("enchantments")) {
- NbtCompound enchants = ea.getCompound("enchantments");
+ if (customData.contains("enchantments")) {
+ NbtCompound enchants = customData.getCompound("enchantments");
Optional<String> firstEnchant = enchants.getKeys().stream().findFirst();
String enchant = firstEnchant.orElse("");
return "ENCHANTMENT_" + enchant.toUpperCase(Locale.ENGLISH) + "_" + enchants.getInt(enchant);
}
}
case "PET" -> {
- if (ea.contains("petInfo")) {
- JsonObject petInfo = SkyblockerMod.GSON.fromJson(ea.getString("petInfo"), JsonObject.class);
+ if (customData.contains("petInfo")) {
+ JsonObject petInfo = SkyblockerMod.GSON.fromJson(customData.getString("petInfo"), JsonObject.class);
return "LVL_1_" + petInfo.get("tier").getAsString() + "_" + petInfo.get("type").getAsString();
}
}
case "POTION" -> {
- String enhanced = ea.contains("enhanced") ? "_ENHANCED" : "";
- String extended = ea.contains("extended") ? "_EXTENDED" : "";
- String splash = ea.contains("splash") ? "_SPLASH" : "";
- if (ea.contains("potion") && ea.contains("potion_level")) {
- return (ea.getString("potion") + "_" + internalName + "_" + ea.getInt("potion_level")
+ String enhanced = customData.contains("enhanced") ? "_ENHANCED" : "";
+ String extended = customData.contains("extended") ? "_EXTENDED" : "";
+ String splash = customData.contains("splash") ? "_SPLASH" : "";
+ if (customData.contains("potion") && customData.contains("potion_level")) {
+ return (customData.getString("potion") + "_" + internalName + "_" + customData.getInt("potion_level")
+ enhanced + extended + splash).toUpperCase(Locale.ENGLISH);
}
}
case "RUNE" -> {
- if (ea.contains("runes")) {
- NbtCompound runes = ea.getCompound("runes");
+ if (customData.contains("runes")) {
+ NbtCompound runes = customData.getCompound("runes");
Optional<String> firstRunes = runes.getKeys().stream().findFirst();
String rune = firstRunes.orElse("");
return rune.toUpperCase(Locale.ENGLISH) + "_RUNE_" + runes.getInt(rune);
}
}
case "ATTRIBUTE_SHARD" -> {
- if (ea.contains("attributes")) {
- NbtCompound shards = ea.getCompound("attributes");
+ if (customData.contains("attributes")) {
+ NbtCompound shards = customData.getCompound("attributes");
Optional<String> firstShards = shards.getKeys().stream().findFirst();
String shard = firstShards.orElse("");
return internalName + "-" + shard.toUpperCase(Locale.ENGLISH) + "_" + shards.getInt(shard);
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 19f89d3c..186d52b4 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemStackBuilder.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemStackBuilder.java
@@ -48,11 +48,9 @@ public class ItemStackBuilder {
// Create & Attach ExtraAttributes tag
NbtCompound customData = new NbtCompound();
- NbtCompound extraAttributes = new NbtCompound();
- customData.put(ItemUtils.EXTRA_ATTRIBUTES, extraAttributes);
// Add Skyblock Item Id
- extraAttributes.put(ItemUtils.ID, NbtString.of(internalName));
+ customData.put(ItemUtils.ID, NbtString.of(internalName));
// Item Name
String name = injectData(item.getDisplayName(), injectors);
diff --git a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
index d9bfa6fc..3435e45d 100644
--- a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
+++ b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
@@ -40,7 +40,6 @@ import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.lit
public class ItemUtils {
private static final Logger LOGGER = LoggerFactory.getLogger(ItemUtils.class);
- public static final String EXTRA_ATTRIBUTES = "ExtraAttributes";
public static final String ID = "id";
public static final String UUID = "uuid";
private static final DateTimeFormatter OBTAINED_DATE_FORMATTER = DateTimeFormatter.ofPattern("MMMM d, yyyy").withZone(ZoneId.systemDefault()).localizedBy(Locale.ENGLISH);
@@ -55,74 +54,54 @@ public class ItemUtils {
return Command.SINGLE_SUCCESS;
});
}
-
- public static NbtComponent getCustomData(@NotNull ItemStack stack) {
- return stack.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT);
- }
- /**
- * Gets the {@code ExtraAttributes} NBT tag from the item stack.
- *
- * @param stack the item stack to get the {@code ExtraAttributes} NBT tag from
- * @return an optional containing the {@code ExtraAttributes} NBT tag of the item stack
- */
- public static Optional<NbtCompound> getExtraAttributesOptional(@NotNull ItemStack stack) {
- return Optional.ofNullable(getExtraAttributes(stack));
- }
-
- /**
- * Gets the {@code ExtraAttributes} NBT tag from the item stack.
- *
- * @param stack the item stack to get the {@code ExtraAttributes} NBT tag from
- * @return the {@code ExtraAttributes} NBT tag of the item stack, or null if the item stack is null or does not have an {@code ExtraAttributes} NBT tag
- */
- @Nullable
- public static NbtCompound getExtraAttributes(@NotNull ItemStack stack) {
- NbtComponent customData = getCustomData(stack);
- NbtCompound customNbt = customData.copyNbt();
- return customNbt.contains(EXTRA_ATTRIBUTES) ? customNbt.getCompound(EXTRA_ATTRIBUTES) : null;
+ @SuppressWarnings("deprecation")
+ public static NbtCompound getCustomData(@NotNull ItemStack stack) {
+ return stack.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT).getNbt();
}
/**
- * Gets the internal name of the item stack from the {@code ExtraAttributes} NBT tag.
+ * Gets the Skyblock item id of the item stack.
*
* @param stack the item stack to get the internal name from
* @return an optional containing the internal name of the item stack
*/
- public static Optional<String> getItemIdOptional(@NotNull ItemStack stack) {
- return getExtraAttributesOptional(stack).map(extraAttributes -> extraAttributes.getString(ID));
+ public static Optional<String> getItemIdOptional(@NotNull ItemStack stack) {
+ NbtCompound customData = getCustomData(stack);
+ return customData.contains(ID) ? Optional.of(customData.getString(ID)) : Optional.empty();
}
/**
- * Gets the internal name of the item stack from the {@code ExtraAttributes} NBT tag.
+ * Gets the Skyblock item id of the item stack.
*
* @param stack the item stack to get the internal name from
* @return the internal name of the item stack, or an empty string if the item stack is null or does not have an internal name
*/
- public static String getItemId(@NotNull ItemStack stack) {
- NbtCompound extraAttributes = getExtraAttributes(stack);
- return extraAttributes != null ? extraAttributes.getString(ID) : "";
+ public static String getItemId(@NotNull ItemStack stack) {
+ NbtCompound customData = getCustomData(stack);
+ return customData.contains(ID) ? customData.getString(ID) : "";
}
/**
- * Gets the UUID of the item stack from the {@code ExtraAttributes} NBT tag.
+ * Gets the UUID of the item stack.
*
* @param stack the item stack to get the UUID from
* @return an optional containing the UUID of the item stack
*/
- public static Optional<String> getItemUuidOptional(@NotNull ItemStack stack) {
- return getExtraAttributesOptional(stack).map(extraAttributes -> extraAttributes.getString(UUID));
+ public static Optional<String> getItemUuidOptional(@NotNull ItemStack stack) {
+ NbtCompound customData = getCustomData(stack);
+ return customData.contains(UUID) ? Optional.of(customData.getString(UUID)) : Optional.empty();
}
/**
- * Gets the UUID of the item stack from the {@code ExtraAttributes} NBT tag.
+ * Gets the UUID of the item stack.
*
* @param stack the item stack to get the UUID from
* @return the UUID of the item stack, or an empty string if the item stack is null or does not have a UUID
*/
- public static String getItemUuid(@NotNull ItemStack stack) {
- NbtCompound extraAttributes = getExtraAttributes(stack);
- return extraAttributes != null ? extraAttributes.getString(UUID) : "";
+ public static String getItemUuid(@NotNull ItemStack stack) {
+ NbtCompound customData = getCustomData(stack);
+ return customData.contains(UUID) ? customData.getString(UUID) : "";
}
/**
@@ -141,8 +120,8 @@ public class ItemUtils {
* @param stack the item under the pointer
* @return if the item have a "Timestamp" it will be shown formated on the tooltip
*/
- public static String getTimestamp(ItemStack stack) {
- NbtCompound ea = getExtraAttributes(stack);
+ public static String getTimestamp(ItemStack stack) {
+ NbtCompound ea = getCustomData(stack);
if (ea != null && ea.contains("timestamp", NbtElement.LONG_TYPE)) {
Instant date = Instant.ofEpochMilli(ea.getLong("timestamp"));
@@ -164,13 +143,13 @@ public class ItemUtils {
}
public static boolean hasCustomDurability(@NotNull ItemStack stack) {
- NbtCompound extraAttributes = getExtraAttributes(stack);
+ NbtCompound extraAttributes = getCustomData(stack);
return extraAttributes != null && (extraAttributes.contains("drill_fuel") || extraAttributes.getString(ID).equals("PICKONIMBUS"));
}
@Nullable
public static IntIntPair getDurability(@NotNull ItemStack stack) {
- NbtCompound extraAttributes = getExtraAttributes(stack);
+ NbtCompound extraAttributes = getCustomData(stack);
if (extraAttributes == null) return null;
// TODO Calculate drill durability based on the drill_fuel flag, fuel_tank flag, and hotm level