Modding:Content Tutorial Simple Recipe: Difference between revisions

From Vintage Story Wiki
(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 ==

Revision as of 12:01, 24 March 2024

Other languages:
  • English

This page was last verified for Vintage Story version 1.19.4.


Introduction

Objective

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

Before starting, it is recommended you download the workspace and assets for this tutorial. The completed files can also be found here.

This tutorial starts with the following assets:

  • Mod Setup & Folder Structure
  • Premade Blocktype file
  • Premade Itemtype file
  • Premade Lang file
  • Texture & Shape Files
  • Empty Grid Recipe Files

Prerequisites

This tutorial will assume you understand the following topics:

Although not necessary, it is recommended to have completed the following tutorials:

  • 2. Simple Item
    • The 'Simple Wand' item is included in the tutorial setup.
  • 3. Simple Block
    • The 'Simple Gold Block' is included in the tutorial setup.

Navigating Assets

Browse the downloaded workspace. You should have an understanding of most of the files that currently exist, however there are two new files:

  • assets/simplerecipe/recipes/grid/simplewandrecipe.json - An empty json file. This will be used to create a recipe for the 'Simple Wand' item.
  • assets/simplerecipe/recipes/grid/simpleblockrecipe.json - An empty json file. This will be used to create a recipe for the 'Simple Gold Block'.

Creating the Item Recipe

Conclusion

Congratulations, you have now created your first block! This tutorial should have given you greater understanding of blocks, textures, sounds and language files, as well as the basics of modding for Vintage Story!

Next Steps...

If you want to test your knowledge, consider doing the tasks under the Going Further section below.

When you're ready, try out the next tutorial: Simple Recipes. This will show you how to create recipes for the assets you have created.

Going Further

Want to make some additional changes to this mod? Try and achieve the following things!

Change the color of the block

To achieve this...
Modify the shinygoldtexture.png texture to a different color.

Change the block to only be mined with at least a tier 1 tool. Note that you will have to add a new "requiredToolTier" property

To achieve this...
Add "requiredToolTier":1 to the blocktype file.

Change your modid and domain to something else

To achieve this...
Modify both the modid entry in modinfo.json, and change the name of the 'simpleblock' folder in 'assets'.

Rename your 'Simple Gold Block'

To achieve this...
Change the entry for simplegoldblock in your en.json lang file.

Create another block with a different texture and properties

To achieve this...
Create a new block texture with a different name, and a duplicate blocktype file. In the new blocktype file, change the block code and change the texture property to your new texture path. Modify the properties to change the type of block. Don't forget to add new lang translation entries!


Content Modding
Basics Content Mods Developing a Content Mod
Tutorials
Concepts Modding Concepts Variants Domains Patching Remapping World Properties
Uncategorized
Icon Sign.png

Wondering where some links have gone?
The modding navbox is going through some changes! Check out Navigation Box Updates for more info and help finding specific pages.

Modding
Modding Introduction Getting Started Theme Pack
Content Modding Content Mods Developing a Content Mod Basic Tutorials Intermediate Tutorials Advanced Tutorials Content Mod Concepts
Code Modding Code Mods Setting up your Development Environment
Property Overview ItemEntityBlockBlock BehaviorsBlock ClassesBlock EntitiesBlock Entity BehaviorsWorld properties
Workflows & Infrastructure Modding Efficiency TipsMod-engine compatibilityMod ExtensibilityVS Engine
Additional Resources Community Resources Modding API Updates Programming Languages List of server commandsList of client commandsClient startup parametersServer startup parameters
Example ModsAPI DocsGitHub Repository