Modding:Basic Block: Difference between revisions

From Vintage Story Wiki
m
→‎Workspace: wording improvements
No edit summary
m (→‎Workspace: wording improvements)
(44 intermediate revisions by 3 users not shown)
Line 1: Line 1:
__FORCETOC__
__FORCETOC__


This tutorial should introduce you into the basic of adding a block to the game using JSON files. If you want to add a block with functionality you should check out the tutorial for [[Advanced Blocks]]. There is a full list of all properties which can be defined inside the json file [[Block Json Properties]].
Please read the tutorial [[Getting Started with Advanced Modding#Domains|Getting Started]] first, if you haven't done it already. This tutorial should introduce you into the basic of adding a block to the game using JSON files. If you want to add a block with functionality you should check out the tutorial for [[Advanced Blocks]]. There is a full list of all properties which can be defined inside the json file [[Block Json Properties|here]].


= A Simple Block =
= A Simple Block =


To get started let's create something simple. In our example we will add an ordinary gold block to the game (will be for decorative use only) and call this mod '''MyGoldBlock'''.
To get started let's create something simple. In our example we will add an ordinary gold block to the game (will be for decorative use only). So let's call this mod '''MyGoldBlock'''.


== Workspace ==
== Workspace ==


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.
First of all it is useful 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.


== The Texture ==
== The Texture ==


We will add a gold block to the game using this texture: [[File:Gold block.png]].
We will use this texture for our block: [[File:Gold block.png]].


Now we need to create the following folders inside our workspace<code>assets/mygoldblock/textures/blocks/</code>. Rename the texture to <code>mygoldtexture.png</code> and paste it into the <code>texture</code> folder.
Now we need to put the texture at the right place so we can use it later on. Therefore you have to rename the texture to <code>mygoldtexture.png</code> and put it inside <code>assets/mygoldblock/textures/block/</code> in your workspace (you have to create those folders first). <code>mygoldblock</code> will be our domain.


== The Block file ==
== The Block File ==


The next thing we need is a json file which will determine the properties of the block. For now we keep it simple and only cover simple properties, but there are a lot of other things you can do with. Here is a full list of all [[Block Json Properties]]. So create a new json file in your editor (we recommend to use an editor with syntax highlighting, such as [https://notepad-plus-plus.org/ Notepad++] or Visual Studio) named <code>mygoldblock.json</code>.
The next thing we are going to need is a json file which will determine the properties of the block. For now we will keep it simple and will work with simple properties only. If you want to do some more advanced stuff you can take a look at the [[Block Json Properties|Block Properties Overview]].
 
Now you need to create a new json file in your editor (we recommend to use an editor with syntax highlighting, such as [https://notepad-plus-plus.org/ Notepad++] or Visual Studio).


<syntaxhighlight lang="json">
<syntaxhighlight lang="json">
Line 25: Line 27:
code: "mygoldblock",
code: "mygoldblock",
creativeinventory: { "general": ["*"] },
creativeinventory: { "general": ["*"] },
shape: { base: "basic/cube" },
blockmaterial: "Stone",
blockmaterial: "Stone",
drawtype: "cube",
drawtype: "Cube",
textures: {
textures: {
all: { base: "mygoldtexture" }
all: { base: "block/mygoldtexture" }
},
},
resistance: 3.5,
resistance: 3.5,
Line 38: Line 39:
}
}
</syntaxhighlight>
</syntaxhighlight>


Short explanation of each line:
Short explanation of each line:


* '''code''': A unique identifier for your block. If you plan a larger mod, it is suggested to prefix your modname to the identifier.
* '''code''': A unique identifier for your block.
* '''creativeinventory''': The creative inventory tabs the block should be shown in (currently only 1 tab available)
* '''creativeinventory''': The creative inventory tabs the block should be shown in (currently only 1 tab available)
* '''shape''': Which model the block should use
* '''shape''': Which model the block should use
Line 48: Line 48:
* '''textures''': What textures to apply. For simple blocks you can define one single texture for 'all' faces or define one for every facing ('north', 'east', 'west', 'south', 'up', 'down')
* '''textures''': What textures to apply. For simple blocks you can define one single texture for 'all' faces or define one for every facing ('north', 'east', 'west', 'south', 'up', 'down')
* '''resistance''': How many seconds of real life time it takes to break the block without tools
* '''resistance''': How many seconds of real life time it takes to break the block without tools
* '''sounds''': The sounds to be played when placing/breaking or walking on the block. The prefix <code>game:</code> means this will use the vanilla assets, otherwise it will try to find those sounds inside your mod zip file.
* '''sounds''': The sounds to be played when placing/breaking or walking on the block. The prefix <code>game</code> has to be added, since our block has the domain <code>mygoldblock</code>. Otherwise it would try to find those sounds inside our domain.


Create another folder inside your workspace <code>assets/mygoldblock/blocktypes/</code> and save the json file in there.
Now save the file in your workspace inside <code>assets/mygoldblock/blocktypes/</code> and name it <code>mygoldblock.json</code>.


== Naming the Block ==
== Naming the Block ==


To give the block a proper name, we need to create another json file and save it inside a new created folder <code>assets/mygoldblock/lang/en.json</code>
To give the block a proper name, we need to create another json file and save it with the following path: <code>assets/mygoldblock/lang/en.json</code>


<syntaxhighlight lang="json">
<syntaxhighlight lang="json">
Line 64: Line 64:
== Testing/ Distribution ==
== Testing/ Distribution ==


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>MyGoldBlockMod.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.
The last thing we need to do is to create a zip file of the assets folder inside our 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>MyGoldBlockMod.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.
 
Furthermore you need to add a <code>modinfo.json</code> file, check out [[Game_Content_Mod|this tutorial]].


[http://wiki.vintagestory.at/images/4/4c/MyGoldBlockMod.zip MyGoldBlockMod.zip]
To install the mod, navigate to the [[Vintagestory folder]] and place it inside the mods folder.


To install the mod, navigate to the [[VintageStory Folder]] and place it inside the mods folder.
[https://wiki.vintagestory.at/images/4/4c/MyGoldBlockMod.zip MyGoldBlockMod.zip]


[[File:2017-01-10 12-33-45.png|700px]].
[[File:2017-01-10 12-33-45.png|700px]].
'''Hint''': Use the client command <code>.tfedit</code> if you want to adjust the block position, rotation and scale in Hands, in GUI, when dropped on the ground or in third person mode.


= Advanced Properties =
= Advanced Properties =
Line 85: Line 89:
textures: {
textures: {
all: {  
all: {  
base: "mygoldtexture",
base: "block/mygoldtexture",
alternates: [{base: "mygoldtexture1" }, {base: "mygoldtexture2" }, {base: "mygoldtexture3" }],
alternates: [{base: "block/mygoldtexture1" }, {base: "block/mygoldtexture2" }, {base: "block/mygoldtexture3" }],
},
},
},
},
Line 99: Line 103:
== Variants ==
== Variants ==


Gold is the best, but iron is awesome too ... so what shall will do? Let's add another variant of this block, because we all love iron.
Gold is the best, but iron is awesome too ... so what shall we do? Let's add another variant of this block, because we all love iron.


You could duplicate the blocktype file and rename silver to gold in all the places, or you can simply add another variant to the existing blocktype.
You could duplicate the blocktype file and rename silver to gold in all the places, or you can simply add another variant to the existing blocktype.
Line 121: Line 125:
"*-gold": {
"*-gold": {
all: {  
all: {  
base: "mygoldtexture",
base: "block/mygoldtexture",
alternates: [{base: "mygoldtexture1" }, {base: "mygoldtexture2" }, {base: "mygoldtexture3" }],
alternates: [{base: "block/mygoldtexture1" }, {base: "block/mygoldtexture2" }, {base: "block/mygoldtexture3" }],
},
},
},
},
"*-iron": {
"*-iron": {
all: {  
all: {  
base: "myirontexture",
base: "block/myirontexture",
alternates: [{base: "myirontexture1" }, {base: "myirontexture2" }, {base: "myirontexture3" }],
alternates: [{base: "block/myirontexture1" }, {base: "block/myirontexture2" }, {base: "block/myirontexture3" }],
},
},
}
}
Line 141: Line 145:
textures: {
textures: {
all: {  
all: {  
base: "my{type}texture",
base: "block/my{type}texture",
alternates: [{base: "my{type}texture1" }, {base: "my{type}texture2" }, {base: "my{type}texture3" }],
alternates: [{base: "block/my{type}texture1" }, {base: "block/my{type}texture2" }, {base: "block/my{type}texture3" }],
},
},
},
},
Line 155: Line 159:
{ code: "type", states: ["gold", "iron"] }
{ code: "type", states: ["gold", "iron"] }
],
],
shape: { base: "basic/cube" },
blockmaterial: "Stone",
blockmaterial: "Stone",
drawtype: "cube",
drawtype: "cube",
textures: {
textures: {
all: {  
all: {  
base: "my{type}texture",
base: "block/my{type}texture",
alternates: [{base: "my{type}texture1" }, {base: "my{type}texture2" }, {base: "my{type}texture3" }],
alternates: [{base: "block/my{type}texture1" }, {base: "block/my{type}texture2" }, {base: "block/my{type}texture3" }],
},
},
},
},
Line 191: Line 194:
"*-good": {
"*-good": {
all: {  
all: {  
base: "my{type}texture",
base: "block/my{type}texture",
},
},
},
},
"*-used": {
"*-used": {
all: {  
all: {  
base: "my{type}texture",
base: "block/my{type}texture",
alternates: [{base: "my{type}texture1" }, {base: "my{type}texture2" }, {base: "my{type}texture3" }],
alternates: [{base: "block/my{type}texture1" }, {base: "block/my{type}texture2" }, {base: "block/my{type}texture3" }],
},
},
},
},
Line 211: Line 214:
In order to use a custom shape we need to create one first. The engine only supports the model/shape format that's created by the [[VS Model Creator]].
In order to use a custom shape we need to create one first. The engine only supports the model/shape format that's created by the [[VS Model Creator]].


Once you have created your own shape you need to export it as a json file, create a new folder <code>assets/myshinyblock/shapes/blocks/</code> and save the file in there. In our example we will use this model [http://wiki.vintagestory.at/images/3/38/Myshinymodel.json Myshinymodel.json] and move it to <code>assets/myshinyblock/shapes/blocks/myshinymodel.json</code>.
Once you have created your own shape you need to export it as a json file, create a new folder <code>assets/myshinyblock/shapes/block/</code> and save the file in there. In our example we will use this model [https://wiki.vintagestory.at/images/3/38/Myshinymodel.json Myshinymodel.json] and move it to <code>assets/myshinyblock/shapes/block/myshinymodel.json</code>.
Now we need to specify the model inside our block type json file.
Now we need to specify the model inside our block type json file.


Line 221: Line 224:
and the shape to <code>myshinymodel</code>
and the shape to <code>myshinymodel</code>
<syntaxhighlight lang="json">
<syntaxhighlight lang="json">
shape: { base: "myshinymodel" },
shape: { base: "block/myshinymodel" },
</syntaxhighlight>
</syntaxhighlight>


Line 240: Line 243:
== Variants of Custom Shapes ==
== Variants of Custom Shapes ==


I created another model for the blocks in good condition ([http://wiki.vintagestory.at/images/f/fa/Myshinymodel1.json myshinymodel1.json]), because they should look more awesome, than the ones in used conditions. Therefore we need to copy the json file to <code>assets/myshinyblock/shapes/blocks/</code> as well.
I created another model for the blocks in good condition ([https://wiki.vintagestory.at/images/f/fa/Myshinymodel1.json myshinymodel1.json]), because they should look more awesome, than the ones in used conditions. Therefore we need to copy the json file to <code>assets/myshinyblock/shapes/block/</code> as well.


In order to specify the shape by type we need to remove the property <code>shape</code> and replace it with <code>shapebytype</code>:
In order to specify the shape by type we need to remove the property <code>shape</code> and replace it with <code>shapebytype</code>:
Line 246: Line 249:
shapebytype: {
shapebytype: {
"*-good": {
"*-good": {
base: "myshinymodel1",
base: "block/myshinymodel1",
},
},
"*-used": {
"*-used": {
base: "myshinymodel",
base: "block/myshinymodel",
},
},
},
},
Line 256: Line 259:
[[File:2017-01-12 14-51-45.png|700px]]
[[File:2017-01-12 14-51-45.png|700px]]


[http://wiki.vintagestory.at/images/4/42/MyShinyBlockMod.zip MyShinyBlockMod]
[https://wiki.vintagestory.at/images/4/42/MyShinyBlockMod.zip MyShinyBlockMod]


There are a lot of more things you can do with the blocktype and model formats. We recommend you to take a look at the Vintage Story block type files to understand how the system is working, in case something was left unexplained.
There are a lot of more things you can do with the blocktype and model formats. We recommend you to take a look at the Vintage Story block type files to understand how the system is working, in case something was left unexplained.
We hope we could introduce you into the basic of adding blocks the game. [[Advanced Blocks]] will teach you how to add more functionality to your block.
We hope we could introduce you into the basic of adding blocks the game. [[Advanced Blocks]] will teach you how to add more functionality to your block.
{{Navbox/modding|Vintage Story}}
Confirmedusers, Bureaucrats, editor, Administrators
34

edits