Package xland.mcmod.enchlevellangpatch.api
The API of Enchantment Level Language Patch.
What is it for?
It is an API to patch the language file of Minecraft, resource packs and mods, without modifying it.
This means, you can make changes to these translations in bulk.
In particular, you can register your own style for enchantment levels as well as potion potency.
How can I register a patch?
Here's an example, using EnchantmentLevelLangPatch.registerPatch(java.util.function.Predicate, EnchantmentLevelLangPatch):
final int prefixLen = "item.minecraft.".length();
EnchantmentLevelLangPatch.registerPatch(
s -> s.startsWith("item.minecraft."),
(storage, key) -> {
String s = storage.get(key);
if (s != null) return s;
if (s.length() == prefixLen) return "???";
return String.join(" ", Arrays.stream(s.substring(prefixLen).split("_"))
.flatMap(word -> {
String w = word.strip();
if (w.isEmpty()) return Stream.empty();
return Stream.of(Character.toUppercase(w.charAt(0) + w.substring(1)));
})
.collect(Collectors.toList()));
}
);
When it comes to enchantment level or potion potency, things are quite similar:
final Locale localeThai = new Locale("th", "TH", "TH");
EnchantmentLevelLangPatch patch = (storage, key) -> {
int lvl = Integer.parseInt(key.substring(18));
return String.format(localeThai, "%d", lvl);
};
EnchantmentLevelLangPatch.registerEnchantmentPatch("my_mod_id:thai_numbers", patch);
// If you want to apply it immediately:
EnchantmentLevelLangPatchConfig.setCurrentEnchantmentHooks(patch);
Note: 1.19.4+ implementation
Since Minecraft 1.19.4, the game invokes the patch with fallback (instead of the one without fallback).
You can use EnchantmentLevelLangPatch.withFallback(EnchantmentLevelLangPatch.WithFallback) to create a patch if
you want to apply your patch only in Minecraft 1.19.4+.
Mod entrypoint
If your mod runs on Fabric/Quilt: your patches should be registered
in entrypoint "enchlevel-langpatch.init", whose type is ClientModInitializer.
If your mod runs on Forge: register your patches in your mod constructor.
-
ClassDescriptionAn API to patch the language file of Minecraft, resource packs and mods.An
EnchantmentLevelLangPatchthat receives a fallback string.An API to modify the current enchantment level patch and the current potion potency patch.