Advanced tooltip functions
PrincessRTFM opened this issue ยท 2 comments
Issue Description:
When using IItemStack.addAdvancedTooltip(ITooltipFunction)
, the tooltip function documentation says that the parameter passed will be the IItemStack
that the tooltip is being generated for (which also makes sense) but an in-game /ct syntax
says that it passes an IIngredient
instead (which doesn't) despite both the function and the function's parameter being type-specified.
What happens:
If my tooltip function tries to access NBT data via the tag
zengetter on the parameter directly, I get no such member in crafttweaker.item.IIngredient: tag
pointing to the line in question. If I treat it as an ingredient and use .itemArray[0]
then the script (sometimes) works, and doesn't log any errors. At worst, it just doesn't add any tooltip text for some reason.
This happens regardless of whether I declare the function to be as ITooltipFunction
, by the way.
What you expected to happen:
Either the parameter to be passed as an IItemStack
or an error to be thrown when I declare that the parameter is expected to be an IItemStack
.
Script used (Please Pastebin or gist your script, posting an unpasted or ungist'd script will automatically close this issue):
Entire script here. The bit you actually want starts on line 200. The specific issue is on line 215 - if I use item.itemArray[0]
then it (sometimes) works and I don't get errors; if I try item
alone, I get the described error.
crafttweaker.log file (Please Pastebin or gist your file, posting an unpasted or ungist'd file will automatically close this issue):
Affected Versions (Do not use "latest"):
- Minecraft:
1.12.2
- Forge:
14.23.5.2847
- Crafttweaker:
1.12-4.1.15
- Using a server: singleplayer integrated server only
- If yes, does the client have the exact same scripts?
Your most recent log file where the issue was present:
I have no idea what's going on with my script, then. If I remove the import for the ITooltipFunction
and don't cast the function, it complains that it can't find the ITooltipFunction
type. If I leave the import line in but don't cast, it doesn't do that, but /ct syntax
seems to think that item
inside the function is an IIngredient
, even though it's also declared as an IItemStack
explicitly. What's worse is that I pasted your exact code at the end of my script file, and I got the same error - no such member in crafttweaker.item.IIngredient: tag
- when I run /ct syntax
again. I even added a new file, test.zs
, that has nothing but the import for the IItemStack
type and the your code, and the syntax command throws me the same error. The entire file is just:
import crafttweaker.item.IItemStack;
<minecraft:diamond>.addAdvancedTooltip(function(item as IItemStack) {
if !isNull(item.tag){
return item.tag as string;
}
return "no tag";
});
Is /ct syntax
somehow doing something different than normal game-init loading?
I'm having trouble reproducing this, using:
<minecraft:diamond>.addAdvancedTooltip(function(item as IItemStack) {
if !isNull(item.tag){
return item.tag as string;
}
return "no tag";
});
shows {}
in-game, as it has an empty tag (I assume), but it doesn't crash.
Using a custom global function to print the object type:
<minecraft:diamond>.addAdvancedTooltip(function(item as IItemStack) {
return typeof(item);
});
produces:
crafttweaker.mc1120.item.MCItemStack
So I'm really not sure what is going on here, but I'm fairly sure the JVM would complain if we somehow passed and IIngredient to an IItemStack param.