Modding:Content Tutorial Simple Recipe: Difference between revisions

From Vintage Story Wiki
Started recipe tutorial.
(Page Creation - In Progress)
 
(Started recipe tutorial.)
Line 7: Line 7:


=== Objective ===
=== Objective ===
In this tutorial, you will create a new gold brick block! The block will be very simple, however completing this tutorial will show you how to create any number of new blocks. You will also get more practice on using textures and lang files, as well as an understanding of sound assets.
In this tutorial, you will create two new grid recipes for our previously made item and block! Recipes are a great way of allowing players to access your new content.  


=== Assets ===
=== Assets ===
Before starting, it is recommended you [https://github.com/Nateonus/vsmodexamples/releases/tag/SimpleBlockTutorial 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/SimpleRecipeTutorial download the workspace and assets] for this tutorial. The completed files can also be found here.  


This tutorial starts with the following assets:
This tutorial starts with the following assets:


* Mod Setup & Folder Structure
* Mod Setup & Folder Structure
* Empty block file
* Premade Blocktype file
* Template lang file
* Premade Itemtype file
* Block texture file
* Premade Lang file
* Texture & Shape Files
* Empty Grid Recipe Files


=== Prerequisites ===
=== Prerequisites ===
Line 24: Line 26:
* [[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.]]
Although not necessary, it is recommended to have completed the following tutorial:
Although not necessary, it is recommended to have completed the following tutorials:


* [[Modding:Content Tutorial Simple Item|2. Simple Item]]
* [[Modding:Content Tutorial Simple Item|2. Simple Item]]
** You will notice that creating an item and creating a block use very similar methods.
** The 'Simple Wand' item is included in the tutorial setup.
* [[Modding:Content Tutorial Simple Block|3. Simple Block]]
** The 'Simple Gold Block' is included in the tutorial setup.  


== Navigating Assets ==
== Navigating Assets ==
Using the downloaded workspace, have a look at the files that currently exist.
Browse the downloaded workspace. You should have an understanding of most of the files that currently exist, however there are two new files:


* ''modinfo.json'' - The mod info file, which registers your mod with the ID 'simpleblock'.
* ''assets/simplerecipe/recipes/grid/simplewandrecipe.json'' - An empty json file. This will be used to create a recipe for the 'Simple Wand' item.
* ''modicon.png'' - The mod icon file, which will be displayed on the mod manager menu.
* ''assets/simplerecipe/recipes/grid/simpleblockrecipe.json'' - An empty json file. This will be used to create a recipe for the 'Simple Gold Block'.
* ''assets/simpleitem/blocktypes/simpleshinyblock.json'' - An empty file, this is where you shall put the code for your block.
* ''assets/simpleitem/lang/en.json'' - A language file, which is where you will add your translation values.
* ''assets/simpleitem/textures/block/shinygoldtexture.png'' - A texture file for the block.


== Creating the Block ==
== Creating the Item Recipe ==<!-- Test test test. -->
In order to create a block, a file must be created inside the ''blocktypes'' folder. If using the provided workspace, there already exists a block file called simpleshinyblock. Open this file in your IDE.
 
The most important property when creating an asset is the code, also known as an ID. To begin, copy and paste this into the opened simpleshinyblock file.<syntaxhighlight lang="json">
{
  "code": "simplegoldblock"
}
</syntaxhighlight>Remember that json files are a set of keys to values. The key, in this example, is "''code''", and the value is "''simplegoldblock''". Note that the block file starts and ends in curly brackets ('''{ }'''), meaning it is a single object. Now that your block file has a code, it will now be created and registered in game. However, you need a way of accessing the block. To do this, add a new property:<syntaxhighlight lang="json">
{
  "code": "simplegoldblock",
  "creativeinventory": { "general": [ "*" ] },
}
</syntaxhighlight>Notice that each property is seperated using a comma. The new property, ''"creativeinventory"'' tells the game what creative tab this block will be placed in. The syntax of this particular property is a little bit more complex, but don't worry about it for now. All this does is add the block into the "general" creative tab.
 
If you were to launch Vintage Story and enable your mod, you will see the block in the creative menu!
 
[[File:SimpleBlockTutorialNoShapeOrTextureCreativeMenu.png|frameless|300x300px]]
 
You can also place your block in the world!
 
[[File:SimpleBlockTutorialNoShapeNoTexture.png|frameless|300x300px]]
 
Obviously, this is not the correct texture for the block.
== Adding the Shape & Texture ==
The texture file exists in the assets, so why isn't the item being [[wikipedia:Software_rendering|rendered]] correctly?
 
For blocks to use a certain texture, then it must specify this within its json file. Replace your current blocktype json with the following:<syntaxhighlight lang="json">
{
  "code": "simplegoldblock",
  "creativeinventory": { "general": [ "*" ] },
  "drawtype": "Cube",
  "texture": {
"base": "block/shinygoldtexture"
}
}
</syntaxhighlight>Two new properties have been added: ''drawtype'' and ''texture''.
 
Although ''drawtype'' is not necessary to determine the shape of the block, it is a good idea to include this property, as you may change it in the future. Setting this to ''Cube'' tells the block to render as a cube shape.
 
''Texture'' assigns and maps the texture to the block - Nothing special here. 
 
If you run the game again, your block will now have the appropriate texture.
 
[[File:SimpleBlockTutorialGoldBlockWithShapeAndTexture.png|border|frameless|347x347px]]
 
== Block Properties and Sounds ==
There are a couple more changes that need to be made for your block to be finished. 
 
The first thing to set is the mining properties for your block. Add a comma after the last property, and add the following properties to your json file: <syntaxhighlight lang="json">
"blockmaterial": "Stone",
"resistance": 3.5
</syntaxhighlight>The ''blockmaterial'' property determines what tools are effective at digging this block. Setting this to ''Stone'' implies that it can be mined by pickaxes. For a complete list of block materials, view the [https://github.com/anegostudios/vsapi/blob/a6adf202829e762f5e0397725fd462329d746f33/Common/Collectible/Block/EnumBlockMaterial.cs#L10 ''EnumBlockMaterial'' section on GitHub].
 
The ''resistance'' property determines how long a block takes to destroy, in seconds, without the use of a tool. Keep in mind that if the player uses a tool that affects the block material, the block will be destroyed faster.
 
To see if the changes are correct, save the file and reload the world. You should notice that your block takes longer to destroy, unless mined with a pickaxe.
 
You may also notice that your block doesn't sound very metallic - So let's fix that. Your final block json should look like the following:<syntaxhighlight lang="json">
{
  "code": "simplegoldblock",
  "creativeinventory": { "general": [ "*" ] },
  "drawtype": "Cube",
  "texture": {
"base": "block/shinygoldtexture"
},
  "blockmaterial": "Stone",
  "resistance": 3.5,
  "sounds": {
"place": "game:block/anvil",
"walk": "game:walk/stone"
}
}
</syntaxhighlight>The ''sounds'' property is rather self-explanatory, but it is important to notice that you prefix the file locations with "''game:''". This is because the sound files are located within the base game, and are not added by your mod. Here, we are just assigning sounds for ''place'' and ''walk.'' The most common types of sound for blocks are ''place'', ''walk'', ''break'', and ''hit.''
 
== Renaming the Block ==
Currently, every instance of the block is called ''<nowiki/>'simpleblock:block-simplegoldblock'.'' To fix this, you need to add an entry to the lang file. Open up the provided ''en.json'' language file, found in ''assets/simpleblock/lang.'' This is what the file should look like:<syntaxhighlight lang="json">
{
"": ""
}
</syntaxhighlight>On the left is the translation key, and on the right is the translated string. In this case, the translation key is 'block''-simplegoldblock'<nowiki/>''. Note that this is how the game is currently displaying the name, minus the mod domain prefix. The translated string for this should be '<nowiki/>''Simple Gold Block'<nowiki/>''.<syntaxhighlight lang="json">
{
"block-simplegoldblock": "Simple Gold Block"
}
</syntaxhighlight>To speed up testing, if you still have Vintage Story open, you can use the command '<nowiki/>''.reload lang'<nowiki/>'' to reload all lang files. Hovering over your block should show that the lang file has taken effect.
 
[[File:SimpleGoldBlockTutorialInCreativeMenu.png|frameless]]


== Conclusion ==
== Conclusion ==
Confirmedusers
605

edits