#Tooltip modification
76 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
Any one has ideas? plz help
This is a rough version of a script that works. There are definitely some things that can be improved, but you can do it yourself. It works for me in 1.20.1 fabric. ```ItemEvents.tooltip((tooltip) => {
tooltip.addAdvanced(
'minecraft:diamond_chestplate',
(item, advanced, text) => {
//store every tooltip element in an array that contains 'Armor' or 'Body'
const storedTextArr = [];
for (let i = 0; i < text.length; i++) {
//console.log(text.get(i).string); debug log
if (/Armor|Body/.test(${text.get(i).string})) {
//console.log(text.get(i)); debug log
storedTextArr.push(text.get(i));
}
}
//remove every tooltip element that is stored in the storedTextArr
text.removeIf((el) => {
let remove = false;
storedTextArr.forEach((storedEl) => {
if (el == storedEl) remove = true;
});
return remove;
});
//add the shift to tooltip
if (!tooltip.shift) {
text.add(text.length - 1, [Text.of('[Shift]').gold()]);
} else {
for (let i = 0; i < storedTextArr.length; i++) {
text.add(text.length - 1, [storedTextArr[i]]);
}
}
}
);
});```
Thank you!
I currently remove any attack damage or attack speed attribute tooltips but when I use this code if I shift for the tooltip it adds attack speed and damage back. Is there a way to prevent this?
could you illustrate it with pictures? I don't know what the problem is.
You dont want to show any attribute wehen pressing shift ?
Sure! As of right now, I have another script that removes both attack damage and attack speed from the default tooltip (shown above). However, with this script added they re-appear when I hold shift. Can I make them exempt from showing with Shift?
So you want these items that no longer have any atk and speed attributes to be excluded from the shift? So no more shift at all or that all other attributes except speed and atk are displayed there, such as crit?
"No shift at all" can be solved using an item list and "everything except atk and speed" by merging your first script with mine.
Right I want all my extra attributes to show but except for attack speed and attack damage. I merged my script with yours and they still appear in the Shift tooltip
Try this ```js
ItemEvents.tooltip((tooltip) => {
//const swordArr = Ingredient.of(/helmet/).itemIds;
const swordArr = Ingredient.of(/sword/).itemIds;
swordArr.forEach((itemId) => {
tooltip.addAdvanced(itemId, (item, advanced, text) => {
//store every tooltip element in an array that does not contain Attack Damage/Speed and starts with space/+/- int
const storedTextArr = [];
for (let i = 0; i < text.length; i++) {
//console.log('DEBUG 01', text.get(i).string); //debug log
if (/Attack Damage|Attack Speed/.test(text.get(i).string)) continue;
if (/^(+|-| )\d/.test(text.get(i).string)) {
//console.log('DEBUG 02', text.get(i).string); //debug log
storedTextArr.push(text.get(i));
}
}
//remove every tooltip element except for the item name
let name = text.get(0);
text.removeIf((e) => e != name);
//add the shift to tooltip
if (!tooltip.shift) {
text.add(text.length, [Text.of('[Shift for bonus stats]').gold()]);
} else {
for (let i = 0; i < storedTextArr.length; i++) {
text.add(text.length, [storedTextArr[i]]);
}
}
});
});
});```
And disable the other script that removes speed and attack damage
Hmm I tried this and it does the same thing as my old script. The attack damage and attack speed are still there. I'm not sure why it stores every other apotheosis attribute in the shift tooltip.
let me see if I can provide a screenshot
Paste version of tooltip_ss.pdf from @valid pecan
sorry it's a pdf can't ss in game when shifting haha
The problem is I don't have the mod (apotheosis) myself. It works with the Aquamirae mod in my game.
Without script
With script
I can only imagine that your attributes are not called Attack Damage/Speed, but something else. (in your game)
It's not any different. I also have AttributesLib and I can see that the attack speed and damage attributes are still the defaults
For the golden sword in that picture it's default attack damage is 5
So when I'm shifting it actually shows the base damage and not the modifier
Can you send me a before and after picture?
And is my script the only script that modifes tooltips in your game ?
And to be safe. The way it is in my screenshots, is that how it should be?
I just pressed f2 ^^
weird mine doesn't like me ig
I can't help with this problem 🙂
I have no idea why that is the case for you
I rebound the key and it's because my f2 is paired with the function key haha
this is actually with the code after I removed my other scripts
Ok, I'm starting to understand the error. You seem to have several Attack Damage text elements
Can you send me another picture without a tooltip script. So what the item default looks like
Because there is a green, a red and a blue attack damage in your picture
True I'm also realizing that your script isn't working for me because I don't know where to put the item id's
const swordArr = Ingredient.of(/sword/).itemIds this should get every item id that contains sword in its id name
Ok, luckily that was easier than expected
You always follow through thanks for the help my friend 👍
No problem. Have fun with your modpack
Do you think there's a way to get rid of the 'Two Handed' text in the tooltip?
Because that's not an attribute that's hardcoded
If you remove the / in this code //console.log('DEBUG 01', text.get(i).string); //debug log, all text elements will be displayed in your client log. You have to see if it is listed there. If so, it should be doable.
youre welcome ^^
Ugh sorry one more question, is there a way to move the ttoltip down a line?
ok ty
Ok if you just add a space text element after the "removing" it should work. text.add(1, [Text.of(' ')]); ```js
ItemEvents.tooltip((tooltip) => {
const swordArr = Ingredient.of(/sword/).itemIds;
swordArr.forEach((itemId) => {
tooltip.addAdvanced(itemId, (item, advanced, text) => {
//store every tooltip element in an array that does not contain Attack Damage/Speed and starts with space/+/- int
const storedTextArr = [];
for (let i = 0; i < text.length; i++) {
//console.log('DEBUG 01', text.get(i).string); //debug log
if (/Attack Damage|Attack Speed/.test(text.get(i).string)) continue;
if (/^(+|-| )\d/.test(text.get(i).string)) {
//console.log('DEBUG 02', text.get(i).string); //debug log
storedTextArr.push(text.get(i));
}
}
//remove every tooltip element except for the item name
let name = text.get(0);
text.removeIf((e) => e != name);
text.add(1, [Text.of(' ')]);
//add the shift to tooltip
if (!tooltip.shift) {
text.add(text.length, [Text.of('[Shift for bonus stats]').gold()]);
} else {
for (let i = 0; i < storedTextArr.length; i++) {
text.add(text.length, [storedTextArr[i]]);
}
}
});
});
});```
Hey again, is there a way to make it so it doesn't include enchantments?
you need to explain this in more detail
As of right now you’ve helped me make it so that when I specify an item group every stat besides attack damage, speed, reach, +, and - get stored in a shift tooltip. However when I’m using this script it also removes any enchantments (I.e. sharpness) from an enchanted item’s tooltip. Is there a way to add enchantments to a different blacklist like we did with attack damage, speed etc. so that enchantments still show up on the vanilla tooltip?
ItemEvents.tooltip((tooltip) => {
const swordArr = Ingredient.of(/sword/).itemIds;
swordArr.forEach((itemId) => {
tooltip.addAdvanced(itemId, (item, advanced, text) => {
//store every tooltip element in an array that is not blacklisted
const storedTextArr = [];
for (let i = 1; i < text.length; i++) {
//console.log('DEBUG ALL', text.get(i).string);
//blacklist regex, every string here will be removed from the tooltip
if (!/Attack Damage|Attack Speed/.test(text.get(i).string)) {
//console.log('DEBUG STORED', text.get(i));
storedTextArr.push(text.get(i));
}
}
//remove every tooltip except for the item name and add a space
let name = text.get(0);
text.removeIf((e) => e != name);
text.add(1, [Text.of('').darkRed()]);
//add the shift to tooltip
if (!tooltip.shift) {
text.add(text.length, [Text.of('[Shift]').gold()]);
} else {
storedTextArr.forEach((textEl) => {
text.add(text.length, [textEl]);
});
}
});
});
});```
If there's something else you don't want to have in the tooltip, just add it to the regex
And it's not + and - but +, -, space followed by a number (that's what \d is for) ^^
Oh I see. The problem is I want enchantments to have normal behavior on items so they still show up on the default tooltip, not in the shift tooltip.
Then you need a blacklist for everything you dont want and a whitelist for everything in the default tooltip. Because i have no idea how to detect if a tooltip is an enchantment
Okay will do thank you
It took a long time and a lot of reading, but I got it to work. Thanks for the inspiration up until this point!