Modding:Content Tutorial Item Variants: Difference between revisions

From Vintage Story Wiki
m
no edit summary
m (Added final piece)
mNo edit summary
Line 7: Line 7:


=== Objective ===
=== Objective ===
So far the tutorials have only scratched the surface of creating new assets. To make your modding more efficient, you can utilize the variant system to create numerous similar objects from a single json file, and allow each object to have minor (or major) differences.  
So far, the tutorials have only scratched the surface of creating new assets. To make your modding more efficient, you can utilize the variant system to create numerous similar objects from a single json file, and allow each object to have minor (or major) differences.  


In this tutorial, you will create a set of items using variants, each with independent textures. Our items will not have any functionality, however this tutorial should give you a good understanding of what variants are and how to use them.  
In this tutorial you will create a set of items using variants, each with independent textures. The items will not have any functionality, however this tutorial should give you a good understanding of what variants are and how to use them.  


=== Assets ===
=== Assets ===
Line 52: Line 52:


== Defining Variants ==
== Defining Variants ==
All work on this tutorial will be done in the itemtypes/''advancedwand.json'' file. Open it in your IDE and you can get started.
All work in this tutorial will be done in the itemtypes/''advancedwand.json'' file. Open it in your IDE and you can get started.


Firstly, the item's code is still set to "''simplewand"''. Change this to "''advancedwand"''.  
Firstly, the item's code is still set to "''simplewand"''. Change this to "''advancedwand"''.  


Before you can utilize any variant systems, you will need to define the variants for your item. To do this, you use the ''"variantGroups"'' property. This is usually placed directly below the ''code'' property, but it can be placed anywhere in the object.<syntaxhighlight lang="json">
Before you can utilize any variant systems, you will need to define the variants for your item. To do this, use the ''"variantGroups"'' property. This is ''usually'' placed directly below the ''code'' property, but it would work anywhere in the object.<syntaxhighlight lang="json">
"variantgroups": [
"variantgroups": [
     {
     {
Line 76: Line 76:


== Adding Multiple Textures ==
== Adding Multiple Textures ==
Before adding any textures to the object, you should change the shape. Find the "''shape"'' property and make it use "''item/advancedwand"'' instead of the current value.
Before adding any textures to the object, you should update the object to the new shape. Find the "''shape"'' property and make it use "''item/advancedwand"'' instead of the current value.


Currently, your item is using a single texture. Remember, the new shape contains two textures, so you will now need to define both textures within the item. Replace the entire "''texture"'' property (including the value and { }'s) with the following property:<syntaxhighlight lang="json">
Currently, your item is using a single texture. Remember that the new shape contains two textures, so you will now need to define both textures within the item. Replace the entire "''texture"'' property (including the values and { }'s) with the following property:<syntaxhighlight lang="json">
"textures": {
"textures": {
     "handle": { "base": "item/wand-handle" },
     "handle": { "base": "item/wand-handle" },
Line 110: Line 110:
   }
   }
},
},
</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.
</syntaxhighlight>However, a lot of content here 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.
The advantage of using ByType is that it is considerably versatile - If you wanted to add a completely different 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 ===
=== Variant Substitution ===
The other option is to substitute part of the texture path with each wands variant.<syntaxhighlight lang="json">
The other option is to substitute part of the texture path with each wands variant state.<syntaxhighlight lang="json">
"textures": {
"textures": {
     "handle": { "base": "item/wand-handle" },
     "handle": { "base": "item/wand-handle" },
Line 122: Line 122:
</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.
</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.
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 specific file paths.


=== Which to use? ===
=== 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.
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: you could 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, 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.
If you load the game, you should be able to see your three different wands, each using a different primary color.
Confirmedusers
711

edits