Modding:Basic Item: Difference between revisions
CreativeMD (talk | contribs) No edit summary |
CreativeMD (talk | contribs) No edit summary |
||
Line 70: | Line 70: | ||
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>. | 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 | <syntaxhighlight lang="json"> | ||
damagedby: ["blockbreaking", "attacking"], | damagedby: ["blockbreaking", "attacking"], | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 76: | Line 76: | ||
and the durability should be 2000: | and the durability should be 2000: | ||
<syntaxhighlight | <syntaxhighlight lang="json"> | ||
durabilitybytype: { | durabilitybytype: { | ||
"*": 2000, | "*": 2000, | ||
Line 120: | Line 120: | ||
We can also change the durability for each type individually. | We can also change the durability for each type individually. | ||
<syntaxhighlight | <syntaxhighlight lang="json"> | ||
durabilitybytype: { | durabilitybytype: { | ||
"*-shovel": 4000, | "*-shovel": 4000, | ||
Line 132: | Line 132: | ||
Using the same way we specified the mining speed for each type we can also specify a texture for each type. | Using the same way we specified the mining speed for each type we can also specify a texture for each type. | ||
<syntaxhighlight | <syntaxhighlight lang="json"> | ||
texturebytype: { | texturebytype: { | ||
"*-shovel": { | "*-shovel": { | ||
Line 147: | Line 147: | ||
But we can accomplish the same thing with an easier way: | But we can accomplish the same thing with an easier way: | ||
<syntaxhighlight | <syntaxhighlight lang="json"> | ||
texture: { | texture: { | ||
base: "tool/wand/wand-{tooltype}", | base: "tool/wand/wand-{tooltype}", |
Revision as of 14:45, 9 February 2017
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.
A Simple Item
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.
The Texture
This is the texture we gonna use . In order to use it we need to place it inside the assets folder of the Vintagestory folder. Therefore the path should look like this: assets/textures/items/tool/wand/wand.png
.
The Json File
Now we need to let the game know if its existence. We can accomplish that by creating a json file and placing it inside assets/itemtypes/tool/wand.json
.
The content of this json file should look as it follows:
{
code: "wand",
creativeinventory: { "default": ["*"] },
texture: { base: "tool/wand/wand" }
}
- code: A unique identifier for your item. If you plan a larger mod, it is suggested to prefix your modname to the identifier.
- creativeinventory: The creative inventory tabs the itemshould be shown in (currently only 1 tab available)
- textures: What textures to apply.
Testing
Now we got everything ready to run our first test. You should be able to find the added item in the creative inventory.
Naming the Item
To give the item a proper name, you currently have to manually add a line like this in the file assets/lang/en.json
"item-wand": "Wand",
A better way of handling naming and translation will be added once its desired.
Distributing a mod
The current modding system does not yet support mod-specific asset folders. The current way of doing it is to create a zip file a user can extract into his game folder that will extract the files into the right folders. Example:
A proper mod manager will be added to the game once there is a few serious mods out there (go bug tyron about it ;-) ).
Advanced Properties
Mining Properties
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.
A pickaxe looks like this:
miningspeedbytype: {
"*": {
"stone": 7,
"metal": 7
},
},
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 damagedby
allows us to define all possible damage source. For now we will stick to blockbreaking
and attacking
.
damagedby: ["blockbreaking", "attacking"],
and the durability should be 2000:
durabilitybytype: {
"*": 2000,
},
Variants
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 tooltype
and possible values are "shovel"
, "pickaxe"
, "axe"
:
variantgroups: [
{ code: "tooltype", states: ["shovel", "pickaxe", "axe" ] },
],
Now we need to change our miningspeedbytype
property to set the speed of each material for each type:
miningspeedbytype: {
"*-shovel": {
"soil": 7,
"sand": 7,
"gravel": 4.4
},"*-pickaxe": {
"stone": 7,
"metal": 7
},"*-axe": {
"wood": 6,
"leaves": 4
},
},
Every group will be added after each other to the item name item-myitemname-mygroup-mysecondgroup
. 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 *
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 material
(values are magic
, air
, death
) and wanted to select all shovels we would have to do it like that: *-shovel-*
. 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.
durabilitybytype: {
"*-shovel": 4000,
"*-pickaxe": 3000,
"*-axe": 2000,
},
Variant Textures
Using the same way we specified the mining speed for each type we can also specify a texture for each type.
texturebytype: {
"*-shovel": {
base: "tool/wand/wand-shovel",
},
"*-pickaxe": {
base: "tool/wand/wand-pickaxe",
},
"*-axe": {
base: "tool/wand/wand-axe",
},
}
But we can accomplish the same thing with an easier way:
texture: {
base: "tool/wand/wand-{tooltype}",
}
{tooltype}
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 items, we can use overlays instead, which will make it a lot easier.