ContentTweaker

ContentTweaker

27M Downloads

[question] Tinker's Construct material traits and modifiers

belathus opened this issue ยท 2 comments

commented

I'm thinking of making a few modifiers and traits for tools, and one of the first things I thought to make was a material similar to thaumium tools, back in 1.7.10, where they added a modifier slot to the tool.

I believe I could achieve this by adding the trait from TiC, <ticontrait:writable>, but I'd rather have this be its own trait so that I could have a paper/thaumium tool that had 5 modifier slots available. I'm unsure as to how I'd go about doing this.

Similarly, could I create a modifier that changed the tool's stats? For example, increased bow draw speed when in dimension X? I could probably do attack damage easily with the calcDamage event, since that allows me to return the new damage amount, or change the break speed using the PlayerBreakSpeed event. What about permanent changes to a tool's stats, similar to applying quartz or redstone to a tool?

Furthermore, what about applying traits with levels? Something like <ticontrait:luck:2>? How would I pull the current trait's level from the tool in an event? Do I have to grab it via the item's NBT tag?

Are modifiers handled the same way as traits? Could I apply a modifier to a material as if it were a trait?

Sorry I have so many questions about this.

commented

(Not a ContentTweaker dev) This isn't a bug; you're probably better off asking questions like this on the Discord channel. I've gotten plenty of help from the developers there myself.

You should spend some time reading the documentation for the Trait Builder if you haven't already.

Changing tool stats seems tricky, but when there's not an appropriate event to use instead, you could probably still get away with onUpdate events that used NBT editing to change the stats. The catch is that you'll need to make sure to write it in such a way that it a) doesn't keep changing the stats forever b) quickly exits if it's not going to change anything (performance matters as it's executed every tick while carried!) and c) can't be exploited (that might make traits that add modifier points tricky!). "Dummy" NBT properties might be useful for tracking state data for such onUpdate functions. Keep in mind that tools are effectively "built anew" to some degree when parts are replaced; test your trait event functions with that in mind!

Trait events all get their trait as a parameter to the event function, so for a trait reference trait handed to your function, you could get the trait's integer level with trait.level; see Trait Data Representation for details.

Traits are modifiers behind the scenes, just traits are applied for free when building tools with the trait's part, while modifiers are added by investing extra items. Adding an existing modifier to a material as a trait seems entirely possible, but since IIRC the level is based on the number of parts with the "modifier-trait", it might not work the way you'd like; I haven't tried it. I've contemplated the (hacky!) approach of creating a "fake" or hidden trait that uses its onUpdate event to NBT-edit its tool and replace itself with a more properly-configured modifier. That might have issues with tool-part replacement, though (as mentioned earlier: potential exploits!).

If in doubt, reading source code for Tinker's Construct or ContentTweaker can be good hints, assuming you're comfortable with that.

commented

I asked in Discord. No one replied, so I came here.