ContentTweaker integration seems to be incomplete
esotericist opened this issue ยท 4 comments
Right now, it appears that the only ZenGetters for armor traits are the ones you specify, which do not include all of the ones defined by the ContentTweaker specification.
This means that attempting to query, say, trait.level
will get you a No such member
error from the ZenScript compiler, while trait.identifier
does work.
Also, in the onHurt
and onDamaged
events, is newDamage
intended to be a value rather than a variable? The fact the documentation indicates it's the default substitution for damage if there's no return value implies it should be writable, but attempting to assign any value to it gets a not a valid lvalue
error from ZenScript which as far as I'm aware typically indicates an attempt to assign to something that is not a variable (I currently work around this by declaring my own newdamage
-- lowercase d
-- and using it as a return value, although that still doesn't buy me much without the ability to query the trait level).
This all came up during an attempt to make some Ice and Fire based armor (using dragon scales) in ConArm. My script is below (and the resistance scaling is very much a placeholder, I just kinda threw numbers in there while trying to get it implemented).
#loader contenttweaker
import mods.contenttweaker.conarm.ArmorTrait;
import mods.contenttweaker.conarm.ArmorTraitBuilder;
import mods.contenttweaker.conarm.ExtendedMaterialBuilder;
import crafttweaker.damage.IDamageSource;
val firetrait = mods.contenttweaker.conarm.ArmorTraitBuilder.create("dragontrait_fire");
firetrait.color = 0xCE2929;
firetrait.maxLevel = 4;
firetrait.localizedName = "Fire's Endurance";
firetrait.localizedDescription = "Once tempered, the fire has little effect.";
firetrait.onHurt = function(trait, armor, player, source, damage, newDamage, evt) {
var level = trait.level;
var newdamage = damage;
if (level = 4) {
level = 5;
}
if (source.getDamageType() == "dragon_fire") {
level = level * 2;
}
if (source.fireDamage == true) {
newdamage = (damage) * (1 - (0.04 * level));
}
return newdamage;
};
firetrait.register();
This is likely due to the changes that ContentTweaker made in one of their recent updates, so I have to update my integration accordingly. I'm not sure why you can't assign newDamage normally, but I'm also admittedly not that familiar with ZenScript or CraftTweaker. I'll look into this in my testing. Thank you for providing your scripts.
So I've updated my ContentTweaker integration for the next update. In the process of doing so, I noticed a few things when using your script to debug this issue.
The problem with your call to trait.level
is that you first have to call the method getData(IItemStack)
for the trait. Essentially, what you want is to call trait.getData(armor).level
instead.
Also, I found out that newDamage indeed cannot be assigned to anything so it largely functions as just a value.
I appreciate your time and effort, but I have to admit I find this a little confusing and frustrating.
Is there actually something in the upstream documentation somewhere that actually makes it clear this is the case, or is this something you worked out from dealing with the source code? Because I searched very hard for everything that might hint at intended usage for dealing with this stuff, and found so very little.
The 'examples' are simply stubs rather than anything that shows doing anything useful, and the documentation text surely implies newDamage
should do something, as it stands it's just another alias for damage
, isn't it?
Not that I mean to imply this is in any way your fault or problem, I just keep running into documentation that seems to be incomplete while trying to get things done in dealing with various mods (crafttweaker/contenttweaker being a stand-out example, but hardly alone), and it gets wearying.
I can understand your frustrations and I do want to help make things as clear for you and other users as possible.
The only documentation I have for reference is the CraftTweaker/ContentTweaker wiki. Anything else I could possibly know is either conjecture on my part or what I've figured out through implementing my integration code. I'm largely just piecing together what I can. Most of my integration code and documentation is just a derivative of the Tinkers' stuff that was already in place.
I can try to make the example stubs a bit more concrete, but I'm not sure what would be considered useful as I've honestly never used any scripts as a user myself.
There's a significant difference between damage
and newDamage
. The former holds the original damage value at all times. This value never changes throughout the particular event. The latter, however, can potentially throughout the event depending on how many sources hook into it. Each of these values has a particular purpose depending on whether you want to calculate based off the original damage or the actual damage.
At my earliest convenience, I'll try to update the documentation on my end to provide better information as per what we have discussed in this thread so far.
In addition, while I can't guarantee I'll know all the answers, I'm always happy to try and answer any questions or issues you may have about using the CraftTweaker/ContentTweaker integration features. This would also help improve the documentation in general as I get more feedback about possible oversights or gaps in information.