Hello! I'm trying to figure out how I could add some kind of dynamic tooltip which changes based on the highest enchantment level that a tool has.
For example, if my sword has sharpness 5 and looting 3, I want to only take into consideration the sharpness 5, and add a tooltip related to that value, like this:
-ATN: 30
I already know how I could only get the highest enchantment, but I'm still uncertain on how to do the dynamic tooltip. I would like for it to look like the attached screenshot, but I can manage the formatting, I just would like some guidance when it comes to the dynamic thing.
For the time being, I have a client_script which add other regular tooltips based on a dictionary, which goes like this:
import weaponList from 'sds_requirements.js';
import armorList from 'sds_requirements.js';
const itemList = Object.assign(weaponList, armorList);
ItemEvents.modifyTooltips(event => {
for (const [item, requirements] of Object.entries(itemList)) {
event.add(item, '')
//event.add(weapon, Text.gray('Stat requirements:'))
let reqEND = 0;
let reqSTR = 0;
let reqDEX = 0;
for (const [stat, statValue] of Object.entries(requirements)) {
switch (stat) {
case ('kubejs:sds_endurance'):
reqEND = statValue
break;
case ('kubejs:sds_strength'):
reqSTR = statValue
break;
case ('kubejs:sds_dexterity'):
reqDEX = statValue
break;
}
}
event.modify(item, {shift: false}, tooltip => {
tooltip.add(
Text.gray('Req: ')
.append(Text.darkGray(reqEND > 0 ? `(${reqEND}) ` : ''))
.append(Text.darkRed(reqSTR > 0 ? `(${reqSTR}) ` : ''))
.append(Text.gold(reqDEX > 0 ? `(${reqDEX}) ` : ''))
)
});
event.modify(item, {shift: true}, tooltip => {
tooltip.add(Text.gray('Stat requirements:'));
if (reqEND > 0) tooltip.add(Text.darkGray(`- END: ${reqEND}`));
if (reqSTR > 0) tooltip.add(Text.darkRed(`- STR: ${reqSTR}`));
if (reqDEX > 0) tooltip.add(Text.gold(`- DEX: ${reqDEX}`));
});
}
});