Modding:Content Tutorial Item Variants: Difference between revisions

From Vintage Story Wiki
(Nearly done...)
m (Added final piece)
Line 92: Line 92:


== Variant-Based Textures ==
== Variant-Based Textures ==
When using variants, there are two ways of adding differences between your objects. Read both methods first, and then decide which is more suitable in this case.
=== ByType ===
By using the ByType suffix on a property, you can specify completely different values for each variant.<syntaxhighlight lang="json">
"texturesByType": {
  "advancedwand-blue": {
"handle": { "base": "item/wand-handle" },
"head": { "base": "item/wand-blue" }
  },
  "advancedwand-red": {
"handle": { "base": "item/wand-handle" },
"head": { "base": "item/wand-red" }
  },
  "advancedwand-green": {
"handle": { "base": "item/wand-handle" },
"head": { "base": "item/wand-green" }
  }
},
</syntaxhighlight>However, notice here that a lot of content is duplicated, as all the wands use the same handle, and have head textures that are in the same folders.
The advantage of using ByType is that it is considerably versatile - If you wanted to add a completely separate texture to a specific wand, you could easily achieve this by using ByType. It is also worth noting that ByType can be used on ''any'' property within an item, block, or entity, except from the main code and variant properties.
=== Variant Substitution ===
The other option is to substitute part of the texture path with each wands variant.<syntaxhighlight lang="json">
"textures": {
    "handle": { "base": "item/wand-handle" },
    "head": { "base": "item/wand-{wandtype}" }
}
</syntaxhighlight>By adding our variant code inside curly brackets ('''{ }''') in the string, the head texture automatically turns into "''item/wand-blue", "item/wand-red",'' and ''"item/wand-green"'' for each respective variant object.
Evidently, this method uses considerably less code, however it does have some drawbacks. Variant substitution can only be used in properties that accept strings, usually limiting it's functionality to textures, shapes, and sounds. As well as this, it offers less customizability of what textures you can use, as they would all have to be located in very specific file paths.
=== Which to use? ===
Honestly, it doesn't matter which method you choose, as both achieve the same result. In a lot of cases, a mixture of using both ByTypes and substitution is the best option, as you can specify a unique texture for a more unique variant, but then use substitution on all of the other variants. By using the ByType method, you could choose to have completely different handle textures as well, however the substitution method offers considerably neater and shorter code.
If you load the game, you should be able to see your three different wands, each using a different primary color.
[[File:ContentTutorialItemVariantsWorking.png|frameless]]


== Conclusion ==
== Conclusion ==
Congratulations, you have now '''(created your first item...)'''! This tutorial should have given you some understanding of '''(blah blah blah)'''.  
Congratulations, you now have three variants of a single item, all within one file! This tutorial should have given you a good understanding of what variants are and how they work, as well as the potential they can have when making content mods.  


=== Next Steps... ===
=== Next Steps... ===
Try out the next tutorial, '''(link).''' This will show you how to create a '''(...)'''!
Coming soon!


{{Navbox/contentmodding}}
{{Navbox/contentmodding}}
</translate>
</translate>