diff --git a/ci-pom.xml b/ci-pom.xml
index 36dfbd0..e50f28b 100644
--- a/ci-pom.xml
+++ b/ci-pom.xml
@@ -7,7 +7,7 @@
us.mytheria
BlobLib
- 1.697.40
+ 1.697.41
pom.xml
bloblib
diff --git a/local-pom.xml b/local-pom.xml
index 44b93ee..a7741cc 100644
--- a/local-pom.xml
+++ b/local-pom.xml
@@ -5,7 +5,7 @@
us.mytheria
BlobLib
- 1.697.40
+ 1.697.41
pom.xml
bloblib
diff --git a/pom.xml b/pom.xml
index cc5849e..704e92c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
4.0.0
us.mytheria
BlobLib
- 1.697.40
+ 1.697.41
pom
diff --git a/src/main/java/us/mytheria/bloblib/entities/translatable/TranslatableItem.java b/src/main/java/us/mytheria/bloblib/entities/translatable/TranslatableItem.java
index c4d2160..db16d7e 100644
--- a/src/main/java/us/mytheria/bloblib/entities/translatable/TranslatableItem.java
+++ b/src/main/java/us/mytheria/bloblib/entities/translatable/TranslatableItem.java
@@ -23,6 +23,37 @@ static TranslatableItem by(@NotNull String key) {
return BlobLibTranslatableAPI.getInstance().getTranslatableItem(key);
}
+ /**
+ * Will attempt to localize a specific ItemStack while preserving
+ * their NBTs.
+ *
+ * @param itemStack The ItemStack to process. If null, nothing happens.
+ * @param locale The target locale.
+ */
+ static void localize(@Nullable ItemStack itemStack,
+ @NotNull String locale) {
+ TranslatableItem translatableItem = TranslatableItem.isInstance(itemStack);
+ if (translatableItem == null)
+ return;
+ TranslatableItem localized = translatableItem.localize(locale);
+ ItemStack toStack = localized.getClone();
+ ItemMeta from = itemStack.getItemMeta();
+ Objects.requireNonNull(from);
+ ItemMeta to = toStack.getItemMeta();
+ Objects.requireNonNull(to);
+ if (to.hasDisplayName())
+ from.setDisplayName(to.getDisplayName());
+ else
+ from.setDisplayName(null);
+ if (to.hasLore())
+ from.setLore(to.getLore());
+ else
+ from.setLore(null);
+ PersistentDataContainer container = from.getPersistentDataContainer();
+ container.set(BlobTranslatableItem.localeKey, PersistentDataType.STRING, localized.getLocale());
+ itemStack.setItemMeta(from);
+ }
+
@Nullable
static TranslatableItem isInstance(@Nullable ItemStack item) {
if (item == null)