Skip to content

Commit

Permalink
fix up the name parsing how I want
Browse files Browse the repository at this point in the history
  • Loading branch information
fzzyhmstrs committed Sep 26, 2024
1 parent db1e4e5 commit 2f51c29
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,21 @@ public ArchaeologyLootRecipe(ClientArchaeologyLootTable loot) {
StringBuilder archName = new StringBuilder();
String[] chestPathTokens = loot.id.getPath().split("[/_]");
for (String str : chestPathTokens) {
if (!archName.isEmpty()) {
archName.append(" ");
}
if (str.length() <= 1) {
archName.append(" ").append(str);
archName.append(str);
} else {
archName.append(" ").append(str.substring(0, 1).toUpperCase()).append(str.substring(1));
archName.append(str.substring(0, 1).toUpperCase()).append(str.substring(1));
}
}
if(EMILootAgnos.isModLoaded(loot.id.getNamespace())) {
String modName = EMILootAgnos.getModName(loot.id.getNamespace());
rawTitle = LText.translatable("emi_loot.archaeology.unknown_archaeology", archName.toString() + modName);
rawTitle = LText.translatable("emi_loot.archaeology.unknown_archaeology", archName.toString() + " " + modName);
} else {
Text unknown = LText.translatable("emi_loot.archaeology.unknown");
rawTitle = LText.translatable("emi_loot.archaeology.unknown_archaeology", archName.toString() + unknown.getString());
rawTitle = LText.translatable("emi_loot.archaeology.unknown_archaeology", archName.toString() + " " + unknown.getString());
}
if (EMILoot.config.isLogI18n(EMILoot.Type.ARCHAEOLOGY)) {
EMILoot.LOGGER.warn("Untranslated archaeology loot table \"" + loot.id + "\" (key: \"" + key + "\")");
Expand Down
12 changes: 8 additions & 4 deletions xplat/src/main/java/fzzyhmstrs/emi_loot/emi/ChestLootRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,22 @@ public ChestLootRecipe(ClientChestLootTable loot) {
StringBuilder chestName = new StringBuilder();
String[] chestPathTokens = loot.id.getPath().split("[/_]");
for (String str : chestPathTokens) {
if (LText.tablePrefixes.contains(str)) continue;
if (!chestName.isEmpty()) {
chestName.append(" ");
}
if (str.length() <= 1) {
chestName.append(" ").append(str);
chestName.append(str);
} else {
chestName.append(" ").append(str.substring(0, 1).toUpperCase()).append(str.substring(1));
chestName.append(str.substring(0, 1).toUpperCase()).append(str.substring(1));
}
}
if(EMILootAgnos.isModLoaded(loot.id.getNamespace())) {
String modName = EMILootAgnos.getModName(loot.id.getNamespace());
rawTitle = LText.translatable("emi_loot.chest.unknown_chest", chestName.toString() + modName);
rawTitle = LText.translatable("emi_loot.chest.unknown_chest", chestName.toString() + " " + modName);
} else {
Text unknown = LText.translatable("emi_loot.chest.unknown");
rawTitle = LText.translatable("emi_loot.chest.unknown_chest", chestName.toString() + unknown.getString());
rawTitle = LText.translatable("emi_loot.chest.unknown_chest", chestName.toString() + " " + unknown.getString());
}
if (EMILoot.config.isLogI18n(EMILoot.Type.CHEST)) {
EMILoot.LOGGER.warn("Untranslated chest loot table \"" + loot.id + "\" (key: \"" + key + "\")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,21 @@ public GameplayLootRecipe(ClientGameplayLootTable loot) {
StringBuilder gameplayName = new StringBuilder();
String[] chestPathTokens = loot.id.getPath().split("[/_]");
for (String str : chestPathTokens) {
if (!gameplayName.isEmpty()) {
gameplayName.append(" ");
}
if (str.length() <= 1) {
gameplayName.append(" ").append(str);
gameplayName.append(str);
} else {
gameplayName.append(" ").append(str.substring(0, 1).toUpperCase()).append(str.substring(1));
gameplayName.append(str.substring(0, 1).toUpperCase()).append(str.substring(1));
}
}
if(EMILootAgnos.isModLoaded(loot.id.getNamespace())) {
String modName = EMILootAgnos.getModName(loot.id.getNamespace());
rawTitle = LText.translatable("emi_loot.gameplay.unknown_gameplay", gameplayName.toString() + modName);
rawTitle = LText.translatable("emi_loot.gameplay.unknown_gameplay", gameplayName.toString() + " " + modName);
} else {
Text unknown = LText.translatable("emi_loot.gameplay.unknown");
rawTitle = LText.translatable("emi_loot.gameplay.unknown_gameplay", gameplayName.toString() + unknown.getString());
rawTitle = LText.translatable("emi_loot.gameplay.unknown_gameplay", gameplayName.toString() + " " + unknown.getString());
}
if (EMILoot.config.isLogI18n(EMILoot.Type.GAMEPLAY)) {
EMILoot.LOGGER.warn("Untranslated gameplay loot table \"" + loot.id + "\" (key: \"" + key + "\")");
Expand Down
23 changes: 23 additions & 0 deletions xplat/src/main/java/fzzyhmstrs/emi_loot/util/LText.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,32 @@
import net.minecraft.text.Text;
import net.minecraft.util.Language;

import java.util.HashSet;
import java.util.List;
import java.util.Set;


public class LText {

public static HashSet<String> tablePrefixes = new HashSet<>(List.of(
"spawners",
"spawner",
"shearing",
"pots",
"pot",
"gameplay",
"equipment",
"entities",
"entity",
"dispensers",
"dispenser",
"chests",
"chest",
"blocks",
"block",
"archaeology"
));

public static MutableText translatable(String key) {
return Text.translatable(key);
}
Expand Down

0 comments on commit 2f51c29

Please sign in to comment.