Tooltips
Link to tooltips
Adding or removing a tooltip is really easy:
All you need is an item (or IoreDict or similar), in other words, an IIngredient.
Clearing tooltips
Link to clearing-tooltips
This removes ALL tooltips from the item
ZenScript Copyitem.clearTooltip();
// item.clearTooltip(leaveName as bool);
// removes all tooltips but leaves the item name
item.clearTooltip(true);
Removing specific tooltips
Link to removing-specific-tooltips
This function removes all tooltips that match the given regex. One tooltip is generally one line of text (unless there are forced linebreaks due to space).
ZenScript Copyitem.removeTooltip(regex);
item
is an IIngredient
tT
is a string
Or removes a tooltip at a specific line.
ZenScript Copyitem.removeTooltipLine(line);
item
is an IIngredient
line
is an integer
Normal Tooltips
Link to normal-tooltips
This adds tT
as tooltip to item
.
ZenScript Copyitem.addTooltip(tT);
<minecraft:chest>.addTooltip("Storage, what can I say more?");
item
is an IIngredient
tT
is a string
Shift Tooltips
Link to shift-tooltips
This adds a tooltip, that will only be visible when you hold shift.
You can also add an info that will be visible when you don't hold shift (usually used to create something like a message telling you about the shift tooltip.)
ZenScript Copyitem.addShiftTooltip(tT);
item.addShiftTooltip(tT, info);
<minecraft:chest>.addShiftTooltip("STORAGE!!!");
<minecraft:redstone>.addShiftTooltip("RED!!!", "Hold shift to know what I am");
item
is an IIngredient
tT
is an IFormattedText. You can also just use a string as they are automatically converted.
info
is an IFormattedText. You can also just use a string as they are automatically converted.
Markup
Link to markup
The world is colorful, and so should be all of our tooltips. You can also nest these options, should you with to (if you wanted a green text, that is strikethrough)
Coloring a String
Link to coloring-a-string
You can apply one of the 16 colors to your string
ZenScript Copyformat.black
format.darkBlue
format.darkGreen
format.darkAqua
format.darkRed
format.darkPurple
format.gold
format.gray
format.darkGray
format.blue
format.green
format.aqua
format.red
format.lightPurple
format.yellow
format.white
ZenScript Copy<minecraft:stick>.addTooltip(format.green("This one wasn't ripe"));
Formatting a String
Link to formatting-a-string
You can apply different formats to your String should you wish to:
ZenScript Copyformat.obfuscated
format.bold
format.strikethrough
format.underline
format.italic
ZenScript Copy<minecraft:stick>.addShiftTooltip(format.strikethrough("This is a bad tooltip"));
Tooltip functions
Link to tooltip-functions
You can replace the IFormattedText parameter with an ITooltipFunction (import crafttweaker.item.ITooltipFunction;
).
These functions allow you to dynamically generate a tooltip based on the given IItemStack.
A tooltip function is a function that takes an IItemStack and returns the tooltip as string.
This means that using a format
command does not work for these functions, you will need to rely on Minecraft's formatting prefixes if you need to accomplish that.
For the shift tooltips, you can provide a 2nd function as well, which allows you to also generate the tooltip that should be shown when shift is not pressed. For shift tooltips it's either both parameters as function or both as IFormattedText, no mix-ups!
ZenScript CopyaddAdvancedTooltip(ITooltipFunction fn);
addShiftTooltip(ITooltipFunction fn, @Optional ITooltipFunction infoFn);
//Example
<ore:myAxeOreDictionary>.add(<minecraft:iron_axe:*>, <minecraft:golden_axe:*>, <minecraft:diamond_axe:*>);
<ore:myAxeOreDictionary>.addAdvancedTooltip(function(item) {
return "Damage: " ~ item.damage ~ " / " ~ item.maxDamage;
});
<ore:myAxeOreDictionary>.addShiftTooltip(function(item) {
return "Uses left: " ~ (item.maxDamage - item.damage);
}, function(item){
return "Hold shift for some juicy math.";
});