Modding:Basic Block: Difference between revisions

From Vintage Story Wiki
Line 98: Line 98:


== Variants ==
== Variants ==
Gold is the best, but iron is awesome too ... so what shall will do? Let's add some variants to this block, because we all love iron.
=== Variantgroup: Type ===
So first of all we need some new textures again: [[File:Myirontexture.png]] [[File:Myirontexture1.png]] [[File:Myirontexture2.png]] [[File:Myirontexture3.png]]
Now we need to change a few things in our json file. We can add all kinds of different groups, but for now we keep it simple. We are adding group called <code>type</code>, with the states <code>gold</code> and <code>iron</code>.
<syntaxhighlight lang="json">
variantgroups: [
{ code: "type", states: ["gold", "iron"] }
],
</syntaxhighlight>
The next thing we need to do is set textures by type. So we remove our <code>texture</code> property and replace it with a new property <code>texturesbytype</code>, which will allow us to set different textures for each type.
<syntaxhighlight lang="json">
texturesbytype: {
"*-gold": {
all: {
base: "metal/mygoldtexture",
alternates: [{base: "metal/mygoldtexture1" }, {base: "metal/mygoldtexture2" }, {base: "metal/mygoldtexture3" }],
},
},
"*-iron": {
all: {
base: "metal/myirontexture",
alternates: [{base: "metal/myirontexture1" }, {base: "metal/myirontexture2" }, {base: "metal/myirontexture3" }],
},
}
},
</syntaxhighlight>
Every group will be added after each other to the blocks name <code>myblockname-mygroup-mysecondgroup</code>. In our example the block name is ignorable so its replaced by <code>*</code>.
Eventually your file should like as it follows:
<syntaxhighlight lang="json">
{
code: "myshinyblock",
creativeinventory: { "default": ["*"] },
variantgroups: [
{ code: "type", states: ["gold", "iron"] }
],
shape: { base: "basic/cube" },
blockmaterial: "Stone",
drawtype: "cube",
texturesbytype: {
"*-gold": {
all: {
base: "metal/mygoldtexture",
alternates: [{base: "metal/mygoldtexture1" }, {base: "metal/mygoldtexture2" }, {base: "metal/mygoldtexture3" }],
},
},
"*-iron": {
all: {
base: "metal/myirontexture",
alternates: [{base: "metal/myirontexture1" }, {base: "metal/myirontexture2" }, {base: "metal/myirontexture3" }],
},
}
},
resistance: 3.5,
sounds: {
"place": "block/anvil",
"walk": "walk/stone"
}
}
</syntaxhighlight>
[[File:2017-01-10 14-36-58.png|700px]]
=== Variantgroup: Condition ===
Let's at another group to our block, which will determine the condition of this block. There will be two states <code>good</code> and <code>used</code>. We can add this group by adding another property inside <code>variantgroups[]</code>.
<syntaxhighlight lang="json">
variantgroups: [
{ code: "type", states: ["gold", "iron"] },
{ code: "condition", states: ["good", "used"]}
],
</syntaxhighlight>
To finish implementing this second group we need to take care of every case. We want the <code>good</code> blocks to only use the base texture and the <code>used</code> blocks to also use their random textures:
<syntaxhighlight lang="json">
texturesbytype: {
"*-gold-good": {
all: {
base: "metal/mygoldtexture"
},
},
"*-gold-used": {
all: {
base: "metal/mygoldtexture",
alternates: [{base: "metal/mygoldtexture1" }, {base: "metal/mygoldtexture2" }, {base: "metal/mygoldtexture3" }]
},
},
"*-iron-good": {
all: {
base: "metal/myirontexture"
},
},
"*-iron-used": {
all: {
base: "metal/myirontexture",
alternates: [{base: "metal/myirontexture1" }, {base: "metal/myirontexture2" }, {base: "metal/myirontexture3" }]
},
},
},
</syntaxhighlight>
The blocks in a good condition or on the right side, while the used ones are on the left:
[[File:2017-01-10 15-02-38.png|700px]]


== Custom Shapes ==
== Custom Shapes ==


== Variants of Custom Shapes ==
== Variants of Custom Shapes ==
Confirmedusers, editor, Administrators
886

edits