Modding:Basic Item: Difference between revisions

From Vintage Story Wiki
No edit summary
mNo edit summary
 
(47 intermediate revisions by 15 users not shown)
Line 1: Line 1:
<languages/>
<translate>
<!--T:1-->
{{GameVersion|1.19}}
__FORCETOC__
__FORCETOC__
This tutorial should introduce you into the basic of adding an item to the game using JSON files. If you want to add a item with functionality you should check out the tutorial for [[Advanced Items]]. There is a full list of all properties which can be defined inside the json file [[Item Json Properties]]. Adding a block to the game is rather similar, so if you have done that already most of the following steps should be known to you.
{{PageOutdated|lookat={{ll|Modding:Content_Tutorial_Simple_Item|the simple item tutorial|nsp=0}}}}


= A Simple Item =
First, if you haven't done it already, please read about {{ll|Modding:Asset System|nsp=1}}. This tutorial should introduce you to the basics of using JSON files to add an item to the game. If you want to add an item with functionality, you should check out the tutorial for [[Advanced Items]]. That page contains a full list of all properties that can be defined inside the json file [[Item Json Properties]]. Adding a block to the game is similar to adding an item, so if you have already learned how to do that, most of the following steps should be familiar.


So, the first thing we going to need is an idea. What does this game need. Wait i got it ... the game needs an overpowered wand. Let's call this mod '''MyWandMod'''.
== A Simple Item == <!--T:2-->
The first thing we need is an idea. What does this game need? Wait! I got it ... the game needs a cool wand. Let's call this mod '''BasicItem''', because this is the Basic Item tutorial, and we're making a wand.


== Workspace ==
== Workspace == <!--T:3-->
First create a folder to put the mod files in, which will become your '''workspace''' where we will create the mod itself. We will have to add several folders inside the main folder to keep our files organized. The Vintage Story mod loader requires some files to be placed in specific folders so the loader can find what it needs to load. For this mod, everything will go in our namespaced assets folder. For us, this folder is <code>assets/basicwand/</code>. ''Note'': the namespace does not need to be the same as the name of the mod.


First of all I suggested to create a new folder to keep everything nice and clean. Inside this '''workspace''' we will create the mod itself and later on put it into a zip file, so we can test it and distribute it to other people.
<!--T:4-->
All mods that add content must be in the <assets folder> and their own namespace directory. The namespace, for us is <code>basicwand</code>. This convention prevents multiple mods that use the same item code from causing issues. For example, if you enable extended debug info with the command <code>.edi</code>, you may notice that all the items in the game are prefixed with <code>game:</code>, which is the namespace for all the vanilla content.


== The Texture ==
<!--T:5-->
After getting our workspace ready, we can move on to actually making the wand.


This is the texture we gonna use [[File:Wand.png]]. Now we need to create the following folders inside our workspace <code>assets/mywandmod/textures/items/<code>, copy the texture in there and rename it to <code>wand.png</code>.
== Adding a Texture == <!--T:6-->
Let's start with the texture we will use: [[File:Wand.png]] <br>
(To create your own textures, you can use programs like [https://www.dotpdn.com/downloads/pdn.html/ PaintDotNet(free)], [https://www.piskelapp.com/ Piskel(free)], [https://www.gimp.org/ GIMP(free)], or [https://github.com/aseprite/aseprite/ Aseprite(free open source, or pay for precompiled)])


== The Item File ==
<!--T:7-->
In order to use the texture, we need to put it in the right place (so the mod loader can find it). To do this we will create the folder <code>textures/item/</code>. Remember, this is in our namespaced folder so the full path is <code>assets/basicwand/textures/item/</code>.


To create the actual wand need to create a json file inside <code>assets/mywandmod/itemtypes/</code> in your workspace. In this example we name it <code>wand.json</code>. This file contains the basic properties of your item.
== Creating the Item File == <!--T:8-->
To create the actual wand item, we need to create a JSON file inside the <code>itemtypes/</code> folder. In this example we name it <code>wand.json</code>. This file contains the basic properties of our item. (we recommend to use an editor with syntax highlighting, such as [https://notepad-plus-plus.org/ Notepad++] or [https://www.sublimetext.com/ Sublime Text]. If you are going to have many json files or some C#, then [https://code.visualstudio.com/ Visual Studio Code] is also a good pick).


The content of this json file should look as it follows:
<!--T:9-->
<syntaxhighlight lang="json">
The most basic item requires two things:
{
* '''code''': A unique identifier for the item.
code: "wand",
* '''texture''': What textures to apply to the item.
creativeinventory: { "general": ["*"] },
texture: { base: "wand" }
}
</syntaxhighlight>


* '''code''': A unique identifier for your item.
<!--T:10-->
* '''creativeinventory''': The creative inventory tabs the itemshould be shown in (currently only 1 tab available)
We also need to include this property to allow us access to our item in the creative inventory:
* '''textures''': What textures to apply.
* '''creativeinventory''': defines the creative inventory tabs where the item should be shown


== Naming the Block ==
<!--T:11-->
 
For now, our values for each property are simple:
To give the block a proper name, we need to create another json file and save it inside a new created folder <code>assets/mywandmod/lang/en.json</code>
* <code>code</code>: <code>wand</code>
* <code>texture</code>: <code>item/wand</code> (Note that the specified path does '''not''' include <code>texture</code> in the path.)
* <code>creativeinventory</code>: <code>general</code>


<!--T:12-->
''Finally'' the values in the actual JSON look like this:
<syntaxhighlight lang="json">
<syntaxhighlight lang="json">
{
{
"block-wand": "Wand"
  code: "wand",
  creativeinventory: {
    "general": ["*"]
  },
  texture: {
    base: "item/wand"
  }
}
}
</syntaxhighlight>
</syntaxhighlight>


== Testing/ Distribution ==
<!--T:13-->
 
You might have noticed that the <code>creativeinventory</code> and <code>textures</code> properties aren't as simple as the <code>code</code> values. The reason for the differences in <code>textures</code> and <code>creativeinventory</code> isn't something we'll cover in this tutorial, but is discussed in advanced tutorials.
There is only one thing left. We need to create a zip file of the assets folder inside your workspace. Either you use an external program (such as WinRAR or 7Zip) or you right-click the <code>assets</code> folder and hit '''Send To''' -> '''Compressed (zipped) folder'''. Eventually you can rename the zip file to <code>MyWandMod.zip</code>. The zip file can be either used for testing purposes or you can send it to other people so they can use it as well.
 
[http://wiki.vintagestory.at/images/e/ec/MyWandMod.zip MyWandMod.zip]
 
To install the mod, navigate to the [[VintageStory Folder]] and place it inside the mods folder.
 
Now we got everything ready to run our first test. You should be able to find the added item in the creative inventory.
 
[[File:2017-01-30 13-59-27.png|700px]]


= Advanced Properties =
== Naming the Item == <!--T:14-->
Now we've got almost everything ready, except for a proper name. To do this we create another JSON file: <code>lang/en.json</code>. The game uses this file to look up the name of the item. The language files have a very simple syntax: <code>"item-code": "Item Name"</code>.


== Mining Properties ==
<!--T:15-->
 
For our wand, this means our file should look something like this:
Our wand is still rather useless, so it might be a good idea to add our wand some mining functionality. How it works? We the property "miningspeedbytype" we can define the mining speed for each material. Here is a list of all [[Block Materials|block materials]].
 
The number indicates how fast the tool is able to mine the block, while <code>1</code> is the default value. <code>time to mine = block resistance / miningspeed</code>. Meaning a speed of <code>2</code> is twice as fast the default speed of one. So our tool is seven times faster than using the hand.
 
A pickaxe looks like this:
<syntaxhighlight lang="json">
<syntaxhighlight lang="json">
miningspeedbytype: {
{
"*": {
  "item-wand": "Wand"
"stone": 7,
}
"metal": 7
},
},
</syntaxhighlight>
 
Although the tool is working already, we should add some kind of durability. Therefore we need to define what can damage our tool and the durability itself.
 
Our tool can be damaged by breaking a block, or using it for an weapon. The property <code>damagedby</code> allows us to define all possible damage source. For now we will stick to <code>blockbreaking</code> and <code>attacking</code>.
 
<syntaxhighlight lang="json">
damagedby: ["blockbreaking", "attacking"],
</syntaxhighlight>
 
and the durability should be 2000:
 
<syntaxhighlight lang="json">
durabilitybytype: {
"*": 2000,
},
</syntaxhighlight>
</syntaxhighlight>


== Variants ==
== Conclusion == <!--T:16-->
 
Together, the item and language files are technically enough to be a complete mod. But they don't add the cool wand I said we would make at the beginning of this tutorial. In order to add more properties, we have to head over to the [[Modding:Advanced Item]] tutorial where I explain how we can do way cooler things with items than just create a measly stick.
Pretty basic so far, let's go more advanced. Let's add some variants to our wand, each of them should represent another tool (shovel, pickaxe, axe).
 
So first of all we have to add a new variantgroup. The name of your group is <code>tooltype</code> and possible values are <code>"shovel"</code>, <code>"pickaxe"</code>, <code>"axe"</code>:
<syntaxhighlight lang="json">
variantgroups: [
{ code: "tooltype", states: ["shovel", "pickaxe", "axe" ] },
],
</syntaxhighlight>
 
Now we need to change our <code>miningspeedbytype</code> property to set the speed of each material for each type:
<syntaxhighlight lang="json">
miningspeedbytype: {
"*-shovel": {
"soil": 7,
"sand": 7,
"gravel": 4.4
},"*-pickaxe": {
"stone": 7,
"metal": 7
},"*-axe": {
"wood": 6,
"leaves": 4
},
},
</syntaxhighlight>
 
Every group will be added after each other to the item name <code>item-myitemname-mygroup-mysecondgroup</code>. In total, our wand has 3 types and their full names are:
*item-wand-shovel
*item-wand-pickaxe
*item-wand-axe
 
Each of our selectors starts with a <code>*</code> which is a custom symbol and means it can be anything. Through that way you can select specific variants of your item.
 
If we would add another variant called <code>material</code> (values are <code>magic</code>, <code>air</code>, <code>death</code>) and wanted to select all shovels we would have to do it like that: <code>*-shovel-*</code>. Meaning it can be anything before, but it has to be a shovel and it can be any type of a shovel.
 
We can also change the durability for each type individually.
<syntaxhighlight lang="json">
durabilitybytype: {
"*-shovel": 4000,
"*-pickaxe": 3000,
"*-axe": 2000,
},
</syntaxhighlight>
 
== Variant Textures ==
 
Using the same way we specified the mining speed for each type we can also specify a texture for each type.
 
<syntaxhighlight lang="json">
texturebytype: {
"*-shovel": {
base: "tool/wand/wand-shovel",
},
"*-pickaxe": {
base: "tool/wand/wand-pickaxe",
},
"*-axe": {
base: "tool/wand/wand-axe",
},
}
</syntaxhighlight>
 
But we can accomplish the same thing with an easier way:
<syntaxhighlight lang="json">
texture: {
base: "tool/wand/wand-{tooltype}",
}
</syntaxhighlight>
 
<code>{tooltype}</code> will be replaced by either shovel, pickaxe or axe.
 
== Texture Overlays ==
 
As everybody knows programmers are lazy, so instead of drawing a texture for each variant of our item, we can use overlays instead, which will make it a lot easier.
 
These are the overlays for each type: [[File:Wand-overlay-axe.png]] [[File:Wand-overlay-pickaxe.png]] [[File:Wand-overlay-shovel.png]]. All we have to do now is to change the base texture to back to the original wand texture and add an overlay texture.
 
<syntaxhighlight lang="json">
texture: {
base: "tool/wand/wand",
overlays: [ "tool/wand/wand-overlay-{tooltype}" ],
},
</syntaxhighlight>
 
and this is the result:
 
[[File:2017-02-09 17-30-34.png|700px]]
 
== Download ==


You can download the mod to test it out yourself: [http://wiki.vintagestory.at/images/e/ec/MyAdvancedWandMod.zip MyAdvancedWandMod.zip]
<!--T:17-->
{{Navbox/contentmodding}}
</translate>

Latest revision as of 12:51, 28 March 2024

Other languages:

This page was last verified for Vintage Story version 1.19.


GameIcon.png

This page is outdated!
Some details may not be accurate, so use with caution! Please view the simple item tutorial for an up-to-date page!


First, if you haven't done it already, please read about Asset System . This tutorial should introduce you to the basics of using JSON files to add an item to the game. If you want to add an item with functionality, you should check out the tutorial for Advanced Items. That page contains a full list of all properties that can be defined inside the json file Item Json Properties. Adding a block to the game is similar to adding an item, so if you have already learned how to do that, most of the following steps should be familiar.

A Simple Item

The first thing we need is an idea. What does this game need? Wait! I got it ... the game needs a cool wand. Let's call this mod BasicItem, because this is the Basic Item tutorial, and we're making a wand.

Workspace

First create a folder to put the mod files in, which will become your workspace where we will create the mod itself. We will have to add several folders inside the main folder to keep our files organized. The Vintage Story mod loader requires some files to be placed in specific folders so the loader can find what it needs to load. For this mod, everything will go in our namespaced assets folder. For us, this folder is assets/basicwand/. Note: the namespace does not need to be the same as the name of the mod.

All mods that add content must be in the <assets folder> and their own namespace directory. The namespace, for us is basicwand. This convention prevents multiple mods that use the same item code from causing issues. For example, if you enable extended debug info with the command .edi, you may notice that all the items in the game are prefixed with game:, which is the namespace for all the vanilla content.

After getting our workspace ready, we can move on to actually making the wand.

Adding a Texture

Let's start with the texture we will use: Wand.png
(To create your own textures, you can use programs like PaintDotNet(free), Piskel(free), GIMP(free), or Aseprite(free open source, or pay for precompiled))

In order to use the texture, we need to put it in the right place (so the mod loader can find it). To do this we will create the folder textures/item/. Remember, this is in our namespaced folder so the full path is assets/basicwand/textures/item/.

Creating the Item File

To create the actual wand item, we need to create a JSON file inside the itemtypes/ folder. In this example we name it wand.json. This file contains the basic properties of our item. (we recommend to use an editor with syntax highlighting, such as Notepad++ or Sublime Text. If you are going to have many json files or some C#, then Visual Studio Code is also a good pick).

The most basic item requires two things:

  • code: A unique identifier for the item.
  • texture: What textures to apply to the item.

We also need to include this property to allow us access to our item in the creative inventory:

  • creativeinventory: defines the creative inventory tabs where the item should be shown

For now, our values for each property are simple:

  • code: wand
  • texture: item/wand (Note that the specified path does not include texture in the path.)
  • creativeinventory: general

Finally the values in the actual JSON look like this:

{
  code: "wand",
  creativeinventory: {
    "general": ["*"]
  },
  texture: {
    base: "item/wand"
  }
}

You might have noticed that the creativeinventory and textures properties aren't as simple as the code values. The reason for the differences in textures and creativeinventory isn't something we'll cover in this tutorial, but is discussed in advanced tutorials.

Naming the Item

Now we've got almost everything ready, except for a proper name. To do this we create another JSON file: lang/en.json. The game uses this file to look up the name of the item. The language files have a very simple syntax: "item-code": "Item Name".

For our wand, this means our file should look something like this:

{
  "item-wand": "Wand"
}

Conclusion

Together, the item and language files are technically enough to be a complete mod. But they don't add the cool wand I said we would make at the beginning of this tutorial. In order to add more properties, we have to head over to the Modding:Advanced Item tutorial where I explain how we can do way cooler things with items than just create a measly stick.


Content Modding
Basics Content Mods Developing a Content Mod Packaging & Release
Tutorials
Concepts Modding Concepts Modinfo Variants Domains Patching Remapping World Properties
Moddable Assets
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 ItemEntityEntity BehaviorsBlockBlock BehaviorsBlock ClassesBlock EntitiesBlock Entity BehaviorsCollectible 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