Modding:Advanced JSON Item: Difference between revisions

From Vintage Story Wiki
m
prep for split (copied from basic item mod)
m (VeryGoodDog moved page Modding:Advanced Item to Modding:Advanced JSON Item: theres a page called Modding:Advanced Items about code mod items.)
m (prep for split (copied from basic item mod))
Line 1: Line 1:
WIP ask VeryGoodDog if you really want this done
WIP ask VeryGoodDog if you really want this done
= 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|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">
miningspeedByType: {
"*": {
"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>
== 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 <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: "item/wand-shovel",
},
"*-pickaxe": {
base: "item/wand-pickaxe",
},
"*-axe": {
base: "item/wand-axe",
},
}
</syntaxhighlight>
But we can accomplish the same thing with an easier way:
<syntaxhighlight lang="json">
texture: {
base: "item/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: "wand",
overlays: [ "item/wand-overlay-{tooltype}" ],
},
</syntaxhighlight>
and this is the result:
[[File:2017-02-09 17-30-34.png|700px]]
= Mod Download =
You can download the mod to test it out yourself:
[https://wiki.vintagestory.at/images/e/ec/MyAdvancedWandMod.zip MyAdvancedWandMod.zip]
= Moving Forward =
The example shown here is a rather simple item, and barely covers all the unique things that can be added in Vintage Story. It's highly suggested that you experiment with or at least familiarize yourself with all the known item properties before moving onto code mods. The best way to do this is to peruse the '''[[Modding:Item Json Properties | Item Properties]]''' page, which contains an ongoing list of all the usable JSON item properties currently incorporated into the game. Most properties in the list also have referenced files you can search for in the Vintage Story Assets folder. If you don't know where this is, you can find tutorials for each operating system at the [[Modding:The Asset System | Asset System]] page.
If you haven't yet, it's suggested you also check out the '''[[Modding:Basic Block| Basic Block]]''' and '''[[Modding:Basic Entity | Basic Entity]]''' pages to learn how simple JSON items and entities are added to the game.
However, if you're feeling like making the jump to code mods then you'll want to start by setting up your '''[[Modding: Setting up your Development Environment | Development Environment]]'''.
'''Hint''': Use the client command <code>.tfedit</code> if you want to adjust the item position, rotation and scale in Hands, in GUI, when dropped on the ground or in third person mode.
{{Navbox/modding|Vintage Story}}
Confirmedusers, Bureaucrats, editor, Administrators
1,522

edits