Modding:Content Tutorial Block Variants: Difference between revisions

From Vintage Story Wiki
Marked this version for translation
m (Going further code fix)
(Marked this version for translation)
 
Line 3: Line 3:
{{GameVersion|1.19.7}}
{{GameVersion|1.19.7}}
__FORCETOC__
__FORCETOC__
== Introduction ==
== Introduction == <!--T:1-->


=== Objective ===
=== Objective === <!--T:2-->
The variant system has an extensive amount of uses. In this tutorial, we will create a set of blocks with independent textures, using two separate variant groups. These blocks will show you how you can mix variant groups together to create a huge number of new assets.
The variant system has an extensive amount of uses. In this tutorial, we will create a set of blocks with independent textures, using two separate variant groups. These blocks will show you how you can mix variant groups together to create a huge number of new assets.


=== Assets ===
=== Assets === <!--T:3-->
Before starting, it is recommended you [https://github.com/Nateonus/vsmodexamples/releases/tag/BlockVariantsTutorial download the workspace and assets] for this tutorial. The completed files can also be found here.  
Before starting, it is recommended you [https://github.com/Nateonus/vsmodexamples/releases/tag/BlockVariantsTutorial download the workspace and assets] for this tutorial. The completed files can also be found here.  


<!--T:4-->
This tutorial starts with the following assets:
This tutorial starts with the following assets:


<!--T:5-->
* Mod Setup & Folder Structure
* Mod Setup & Folder Structure
* Template advanced shiny block file
* Template advanced shiny block file
Line 18: Line 20:
* Block texture files
* Block texture files


=== Prerequisites ===
=== Prerequisites === <!--T:6-->
This tutorial will assume you understand the following topics:
This tutorial will assume you understand the following topics:


<!--T:7-->
* [[Modding:Developing a Content Mod|Setting up a content mod and using an IDE.]]
* [[Modding:Developing a Content Mod|Setting up a content mod and using an IDE.]]
* [[Modding:Content Tutorial Basics|The functions of shape, texture and lang files.]]
* [[Modding:Content Tutorial Basics|The functions of shape, texture and lang files.]]


<!--T:8-->
It is recommended to have completed the following tutorials:
It is recommended to have completed the following tutorials:


<!--T:9-->
* [[Modding:Content Tutorial Simple Block|3. Simple Block]] - The simple block made in this tutorial is the basis for this tutorial.
* [[Modding:Content Tutorial Simple Block|3. Simple Block]] - The simple block made in this tutorial is the basis for this tutorial.
* [[Modding:Content Tutorial Item Variants|5. Item Variants]] - This tutorial gives a good beginning stage for creating variants. These tutorials will also be formatted very similarly.
* [[Modding:Content Tutorial Item Variants|5. Item Variants]] - This tutorial gives a good beginning stage for creating variants. These tutorials will also be formatted very similarly.


<!--T:10-->
It is recommended, but not necessary, to understand the following concept:
It is recommended, but not necessary, to understand the following concept:


<!--T:11-->
* [[Modding:Variants|Variants]]
* [[Modding:Variants|Variants]]


== Navigating Assets ==
== Navigating Assets == <!--T:12-->
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.


<!--T:13-->
* ''blocktypes/advancedshinyblock.json'' - This blocktype file is from the finished [[Modding:Content Tutorial Simple Block|Simple Block]] tutorial.
* ''blocktypes/advancedshinyblock.json'' - This blocktype file is from the finished [[Modding:Content Tutorial Simple Block|Simple Block]] 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.


<!--T:14-->
* ''textures/block/shiny...'' - The four texture files for our blocks. Notice that we are using gold and iron textures, and both have 'damaged' states.
* ''textures/block/shiny...'' - The four texture files for our blocks. Notice that we are using gold and iron textures, and both have 'damaged' states.


== Defining Variants ==
== Defining Variants == <!--T:15-->
All work in this tutorial will be done in the ''blocktypes''/''advancedshinyblock.json'' file. Open it in your IDE and you can get started.
All work in this tutorial will be done in the ''blocktypes''/''advancedshinyblock.json'' file. Open it in your IDE and you can get started.


<!--T:16-->
Firstly, the item's code is still set to "''simplegoldblock"''. Change this to "''advancedshinyblock"''.  
Firstly, the item's code is still set to "''simplegoldblock"''. Change this to "''advancedshinyblock"''.  


<!--T:17-->
Before you can utilize any variant systems, you will need to define the variants for your block. To do this, use the ''"variantGroups"'' property. This is ''usually'' placed directly below the ''code'' property, but it would work anywhere in the object.
Before you can utilize any variant systems, you will need to define the variants for your block. To do this, use the ''"variantGroups"'' property. This is ''usually'' placed directly below the ''code'' property, but it would work anywhere in the object.


<!--T:18-->
For this block, we are going to create two variant groups.<syntaxhighlight lang="json">
For this block, we are going to create two variant groups.<syntaxhighlight lang="json">
"variantgroups": [
"variantgroups": [
Line 61: Line 73:
</syntaxhighlight>This example creates two variant groups - Named "''type''" and "''condition''". When you use more than one variant group, the game will create block codes using every permutation of those two groups.  
</syntaxhighlight>This example creates two variant groups - Named "''type''" and "''condition''". When you use more than one variant group, the game will create block codes using every permutation of those two groups.  


<!--T:19-->
If you were to test the mod now, you will see that there exists four block objects with the codes:
If you were to test the mod now, you will see that there exists four block objects with the codes:


<!--T:20-->
* ''advancedshinyblock-gold-good''
* ''advancedshinyblock-gold-good''
* ''advancedshinyblock-gold-used''
* ''advancedshinyblock-gold-used''
Line 69: Line 83:
Notice that the order your variant groups are defined affects the order they appear in the ID. When using variants, especially when using wildcards, this is important to remember.  
Notice that the order your variant groups are defined affects the order they appear in the ID. When using variants, especially when using wildcards, this is important to remember.  


<!--T:21-->
As you probably expected by now, these blocks do not have the appropriate textures.  
As you probably expected by now, these blocks do not have the appropriate textures.  


<!--T:22-->
[[File:BlockVariantsContentTutorial Block all with same textures..png|frameless]]
[[File:BlockVariantsContentTutorial Block all with same textures..png|frameless]]


== Variant-Based Textures ==
== Variant-Based Textures == <!--T:23-->
As explained in the [[Modding:Content Tutorial Item Variants|Item Variants]] tutorial, there are two ways of using variants - ''ByType'' and ''Substitution''. In this tutorial, you're going to use both methods. Before continuing, it may be a good idea to refresh yourself about how both methods work in the item variants tutorial.
As explained in the [[Modding:Content Tutorial Item Variants|Item Variants]] tutorial, there are two ways of using variants - ''ByType'' and ''Substitution''. In this tutorial, you're going to use both methods. Before continuing, it may be a good idea to refresh yourself about how both methods work in the item variants tutorial.


<!--T:24-->
This is the current texture property:<syntaxhighlight lang="json">
This is the current texture property:<syntaxhighlight lang="json">
"textures": {
"textures": {
Line 82: Line 99:
</syntaxhighlight>This blocktype has a total of four variants - That's not many. Although you could create a ''byType'' entry for each variant code, it is a good idea to understand how you can use a mixture of the two methods. Keep in mind, similar to the item variants, there are a number of ways to achieve the final result. Feel free to experiment with other methods, variants are a complex but beautiful subject when used effectively.
</syntaxhighlight>This blocktype has a total of four variants - That's not many. Although you could create a ''byType'' entry for each variant code, it is a good idea to understand how you can use a mixture of the two methods. Keep in mind, similar to the item variants, there are a number of ways to achieve the final result. Feel free to experiment with other methods, variants are a complex but beautiful subject when used effectively.


<!--T:25-->
Using the ''ByType'' suffix, you can split the texture by the condition variant:<syntaxhighlight lang="json">
Using the ''ByType'' suffix, you can split the texture by the condition variant:<syntaxhighlight lang="json">
"texturesbytype": {
"texturesbytype": {
Line 108: Line 126:
''Anyway, back to the code.''
''Anyway, back to the code.''


<!--T:26-->
The given code sample doesn't actually specify a different texture for each type. Replace each texture property with a specific variant substitution.<syntaxhighlight lang="json">
The given code sample doesn't actually specify a different texture for each type. Replace each texture property with a specific variant substitution.<syntaxhighlight lang="json">
"texturesbytype": {
"texturesbytype": {
Line 136: Line 155:
If you are having issues getting any textures to work, it is often a good idea to create a table like this. For every ID, work out the resolved texture path, and ensure it exists.
If you are having issues getting any textures to work, it is often a good idea to create a table like this. For every ID, work out the resolved texture path, and ensure it exists.


<!--T:27-->
If you now test your mod, you'll see your blocks working as expected!
If you now test your mod, you'll see your blocks working as expected!


<!--T:28-->
[[File:ContentTutorialBlockVariants All Block Variants Working With Textures.png|frameless]]
[[File:ContentTutorialBlockVariants All Block Variants Working With Textures.png|frameless]]


== Conclusion ==
== Conclusion == <!--T:29-->
Congratulations, you now have four variants of a single block, all within one file! After this tutorial, you should have more of an understanding of how variants can be grouped together, and how to get the most out of them.  
Congratulations, you now have four variants of a single block, all within one file! After this tutorial, you should have more of an understanding of how variants can be grouped together, and how to get the most out of them.  


=== Next Steps... ===
=== Next Steps... === <!--T:30-->
If you want to test your knowledge, consider doing the tasks under the ''Going Further'' section below.
If you want to test your knowledge, consider doing the tasks under the ''Going Further'' section below.


<!--T:31-->
Variants are pretty nifty, but they can get even better. Take a look at the next tutorial, [[Modding:Content Tutorial Complex Grid Recipes|Complex Grid Recipes]] for a demonstration on how to use variants inside recipes.
Variants are pretty nifty, but they can get even better. Take a look at the next tutorial, [[Modding:Content Tutorial Complex Grid Recipes|Complex Grid Recipes]] for a demonstration on how to use variants inside recipes.


== Going Further ==
== Going Further == <!--T:32-->
Want to make some additional changes to this mod? Try and achieve the following things!
Want to make some additional changes to this mod? Try and achieve the following things!


<!--T:33-->
Make the '<nowiki/>''used''<nowiki/>' blocks destroy faster than the '<nowiki/>''good''' blocks.
Make the '<nowiki/>''used''<nowiki/>' blocks destroy faster than the '<nowiki/>''good''' blocks.
{| class="wikitable mw-collapsible mw-collapsed"
{| class="wikitable mw-collapsible mw-collapsed"
Line 201: Line 224:
|}
|}


<!--T:34-->
{{Navbox/contentmodding}}
{{Navbox/contentmodding}}
</translate>
</translate>
Confirmedusers
637

edits