Skip to content

Commit

Permalink
Improves Translatables
Browse files Browse the repository at this point in the history
  • Loading branch information
anjoismysign committed Aug 3, 2024
1 parent edb2679 commit 3001b79
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
2 changes: 1 addition & 1 deletion local-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>us.mytheria</groupId>
<artifactId>BlobLib</artifactId>
<version>1.698.30</version>
<version>1.698.31</version>
<relativePath>pom.xml</relativePath>
</parent>
<artifactId>bloblib</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
package us.mytheria.bloblib.entities.translatable;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import us.mytheria.bloblib.api.BlobLibTranslatableAPI;

import java.util.List;
import java.util.Objects;

public interface TranslatableBlock extends Translatable<List<String>> {

/**
* Gets a TranslatableBlock by its key. Key is the same as getReference.
*
* @param key The key to get the tag set by.
* @return The TranslatableBlock, or null if it doesn't exist.
*/
@Nullable
static TranslatableBlock by(@NotNull String key) {
Objects.requireNonNull(key);
return BlobLibTranslatableAPI.getInstance().getTranslatableBlock(key);
}

default TranslatableBlockModder modder() {
return TranslatableBlockModder.mod(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
public interface TranslatableItem extends Translatable<ItemStack> {

/**
* Gets a TranslatableItem by its Material and CustomModelData.
* Gets a TranslatableItem by its Material and ItemMeta
*
* @param itemStack The ItemStack to get the TranslatableItem by.
* @param locale The locale to get the TranslatableItem by.
* @return The TranslatableItem, or null if it doesn't exist.
*/
@Nullable
static TranslatableItem byMaterialAndCustomModelData(@NotNull ItemStack itemStack,
@NotNull String locale) {
static TranslatableItem byItemStack(@NotNull ItemStack itemStack,
@NotNull String locale) {
Objects.requireNonNull(itemStack, "'itemStack' cannot be null");
ItemMeta meta = itemStack.getItemMeta();
if (meta == null)
Expand Down Expand Up @@ -56,25 +56,25 @@ static TranslatableItem byMaterialAndCustomModelData(@NotNull ItemStack itemStac
}

/**
* Gets a TranslatableItem by its Material and CustomModelData in the default locale [en_us]
* Gets a TranslatableItem by its Material and ItemMeta in the default locale [en_us]
*
* @param itemStack The ItemStack to get the TranslatableItem by.
* @return The TranslatableItem, or null if it doesn't exist.
*/
static TranslatableItem byMaterialAndCustomModelData(@NotNull ItemStack itemStack) {
return byMaterialAndCustomModelData(itemStack, "en_us");
static TranslatableItem byItemStack(@NotNull ItemStack itemStack) {
return byItemStack(itemStack, "en_us");
}

/**
* Gets a TranslatableItem by its Material and CustomModelData.
* Gets a TranslatableItem by its Material and ItemMeta
*
* @param itemStack The ItemStack to get the TranslatableItem by.
* @param player The player to get the TranslatableItem's locale by.
* @return The TranslatableItem, or null if it doesn't exist.
*/
static TranslatableItem byMaterialAndCustomModelData(@NotNull ItemStack itemStack,
@NotNull Player player) {
return byMaterialAndCustomModelData(itemStack, player.getLocale());
static TranslatableItem byItemStack(@NotNull ItemStack itemStack,
@NotNull Player player) {
return byItemStack(itemStack, player.getLocale());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
package us.mytheria.bloblib.entities.translatable;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import us.mytheria.bloblib.api.BlobLibTranslatableAPI;

import java.util.Objects;

public interface TranslatableSnippet extends Translatable<String> {

/**
* Gets a TranslatableSnippet by its key. Key is the same as getReference.
*
* @param key The key to get the tag set by.
* @return The TranslatableSnippet, or null if it doesn't exist.
*/
@Nullable
static TranslatableSnippet by(@NotNull String key) {
Objects.requireNonNull(key);
return BlobLibTranslatableAPI.getInstance().getTranslatableSnippet(key);
}

default TranslatableSnippetModder modder() {
return TranslatableSnippetModder.mod(this);
}
Expand Down

0 comments on commit 3001b79

Please sign in to comment.