
Add renameItemFormatted in ClientEvents.lang
OuOu2021 opened this issue · 1 comments
Describe the feature
Current Behavior
In StartupEvents.registry('item', event)
, we can use both displayName
and formattedDisplayName
methods to set item names:
event.create('my_item_1')
.displayName('My Item') // Static string
event.create('my_item_2')
.formattedDisplayName(Component.translatable('item.minecraft.dirt')) // Dynamic translation
However, in ClientEvents.lang
, the renameItem
&renameBiome
&renameBlock
&renameEntity
methods only accept a raw string:
ClientEvents.lang('en_us', event => {
event.renameItem('kubejs:my_item', 'My Item') // Static string only
})
This limitation prevents us from referencing other translation keys or composing dynamic text at runtime.
Proposed Change
Overload renameItem(item: ItemStack, name: string | TextComponent)
or add renameItemFormatted(item: ItemStack, name: TextComponent)
so that if an TextComponent
is given, it displays the correct formatted string.
Additional info
No response
Unfortunately we can't really do this... Language files only support simple string components1 and ClientEvents.lang only overrides lang files, so we would have to override the Item's getDescription
method as well. The problem is that that is non-trivial because subclasses of Item
can override this method themselves, so in short, this can unfortunately never happen. There used to be a mod that enabled full json components for lang files, but I doubt that that is still being worked on :/
Footnotes
-
As well as string substitution using
%s
,%d
, etc., but still just format strings. ↩