Modding:Content Tutorial Item Variants: Difference between revisions

From Vintage Story Wiki
Nearly done...
(Beginning tutorial)
(Nearly done...)
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.
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. 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.  


Line 37: Line 39:
Using the downloaded workspace, have a look at the mod assets that currently exist.
Using the downloaded workspace, have a look at the mod assets that currently exist.


* ''itemtypes/advancedwand.json'' - The itemtype file from the [[Modding:Content Tutorial Simple Item|Simple Item]] tutorial.
* ''itemtypes/advancedwand.json'' - This itemtype file is from the finished [[Modding:Content Tutorial Simple Item|Simple Item]] tutorial.
* ''lang/en.json'' - This already contains the entries needed for the tutorial.
* ''lang/en.json'' - This already contains the entries needed for the tutorial.
* ''shapes/item/advancedwand.json'' - The shape file for the new wand. If you open this file in your IDE, you should notice that this new model takes in two textures - ''head'' and ''handle''.
* ''shapes/item/advancedwand.json'' - The shape file for the new wand. If you open this file in your IDE, you should notice that this new model takes in two textures - ''head'' and ''handle''.
Line 49: Line 51:
* ''textures/item/wand-...'' - The four texture files for our wand. Notice that there exists 3 variants of colored texture, and 1 handle texture.
* ''textures/item/wand-...'' - The four texture files for our wand. Notice that there exists 3 variants of colored texture, and 1 handle texture.


== Adding an Item ==
== Defining Variants ==
'''(The above heading is counted as a 'step'. I recommend following a method of 'do', 'analyse', 'experiment' for each step to improve modder's knowledge and understanding.)'''
All work on 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"''.
 
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">
"variantgroups": [
    {
      "code": "wandtype",
      "states": [ "blue", "red", "green" ]
    }
],
</syntaxhighlight>This example will create a single variant group called ''"wandtype''". The variant code is used for a number of purposes, so make sure it is named sensibly and clearly. After the code property, we can define a list of states in an array. As you have only defined a single variant group, each entry in state will create a single object.
 
If you were to test the mod now, you will see that there exists three wand objects with the codes:
 
* ''advancedwand-blue''
* ''advancedwand-red''
* ''advancedwand-green''
 
However, the items do not have valid textures or shapes attached to them.
 
[[File:ContentTutorialItemVariantsWandsAddedNoShapeOrTexture.png|frameless]]
 
== 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.
 
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">
"textures": {
    "handle": { "base": "item/wand-handle" },
    "head": { "base": "item/wand-blue" }
},
</syntaxhighlight>This code allows the use of two textures. It is important to note that the keys for this property, namely "''handle"'' and "''head"'', match to the textures defined in the shape file.
 
You may have noticed that the property is going to turn all the wand heads blue.


=== Creating our Item ===
[[File:ContentTutorialItemVariantsInGameButAllSameTexture.png|frameless]]


=== Testing our Item ===
You would be correct.


=== Try it out... ===
== Variant-Based Textures ==


== Conclusion ==
== Conclusion ==
Confirmedusers
575

edits