Skip to content

ZenScript

KameiB edited this page Jan 4, 2025 · 2 revisions

ZenScript

Changing an item's default name

Usually, when you want to replace an item's default name, you would do it like this:

<minecraft:fishing_rod:*>.displayName = "Ancient Fishing Rod";

What this does is getting that item's original lang key and replacing its value with the designated String.
The problem is, it'll replace it with that String, whatever the language the client is using.

Instead, I recommend creating a .lang file just for your custom item names, adding that item's lang key and putting your desired name on it, like this:

item.fishingRod.name=Ancient Fishing Rod

Lang file loading order

Keep in mind, Minecraft manages language keys as follows:

  1. Read all lang keys inside Minecraft's JAR, from first to last, as they appear.
  2. Load each mod's JAR name in alphabetical order, and read its .lang file.
    Note: If the Minecraft instance has the Resource Loader mod, the resources/minecraft folder gets read before all mods. Then each mods' .lang file, then that mod's corresponding resources subfolder.
  3. Load each Resource Pack from bottom to top, as they appear in the Resource Packs page.

On each step, if Minecraft finds a lang key that previously read, it updates its HashMap with the new value.
This means you can override an existing lang key's value with your desired value.

In the case of the mod Aquaculture, it uses the exact same item.fishingRod.name lang key for its custom wooden Fishing Rod, as Vanilla's Fishing Rod. That's why if you create your lang key inside the resources/minecraft folder, it'll get replaced by a mod if it has the same lang key, and so on.

Therefore, if you create a folder starting with zz and the name of the folder, for example: zzscripts, Minecraft will read your .lang file last, effectively overriding the desired lang key, without worrying which mod it belongs to.


But sometimes, there are items whose lang key are not easy to find.
In that case, use the game.localize function:

<notreepunching:cobblestone/basalt>.displayName = game.localize("tile.notreepunching:cobblestone.basalt.name","en_us");

The 1st argument is your language key, and the 2nd argument is a language code.
The item will use your specified lang key, effectively becoming translatable.

Don't worry about the "en_us". Your name will be displayed in the current language.


Adding a custom description to all specified items

Usually, when you want to add a description to an item's tooltip, you'll do it like this:

<minecraft:fishing_rod:*>.addTooltip(format.red("Only used for crafting!"));

You can use the game.localize function here as well:

<minecraft:fishing_rod:*>.addTooltip(game.localize("tooltip.scripts.onlycrafting","en_us"));

And freely format your text inside the lang key.

Clone this wiki locally