Modding:Block Json Properties: Difference between revisions

From Vintage Story Wiki
Factor out how variants are defined into Modding:Registry_Object_JSON_Parsing
(Add a link to the code that defines the properties)
(Factor out how variants are defined into Modding:Registry_Object_JSON_Parsing)
Line 80: Line 80:
     <td>array of objects</td>
     <td>array of objects</td>
     <td>-</td>
     <td>-</td>
     <td>Allows you define multiple variants of the same item.</td>
     <td>Allows you define multiple [[Modding:Registry_Object_JSON_Parsing|variants]] of the same item.</td>
     <td>armor, ore-graded, plank, </td>
     <td>armor, ore-graded, plank, </td>
  </tr>
  <tr>
    <td scope="row"><div class="tt" data-tt-id="p_variantgroups_info" data-tt-parent="p_variantgroups" data-invisible="true"></div></td>
    <td colspan="4">
The variantgroups property allows you to define multiple variants of this item. All of them will have their unique pattern, which will be added to the item code.
An easy example would be a bowl, which can either be raw or burned:
<syntaxhighlight lang="json">
code: "bowl",
variantgroups: [
{ code:"type", states: ["raw", "burned"] },
],
</syntaxhighlight>
Meaning there will be two variants <code>bowl-raw</code> and <code>bowl-burned</code>.
----
It's also possible to define multiple groups.
<syntaxhighlight lang="json">
code: "barrel",
variantgroups: [
{ code:"state", states: ["closed", "opened"] },
{ code:"contents", states: ["empty", "cabbage"] },
],
</syntaxhighlight>
As a result you will have 2x2 groups, which will be added one after each other: <code>barrel-closed-empty</code>, <code>barrel-closed-cabbage</code>, <code>barrel-opened-empty</code> and <code>barrel-opened-cabbage</code>.
----
Additionally it is possible to refer to external lists (used for blocks) that are found in the worldproperties folder, such as <code>block/rock</code>, which contains all states of all rock types. This used for <code>gravel</code>, <code>sand</code> and <code>rock</code>. It's a good way to keep everything organized:
<syntaxhighlight lang="json">
variantgroups: [
{ loadFromProperties: "block/rock" },
],
</syntaxhighlight>
Here is a [[Json:block:worldvariantgroups|full list]] of all groups and their variants (you can also find them in the <code>assets/worldproperties</code> folder).
----
Furthermore there are other ways of combining groups together. So far we covered the default combination mode, which is <code>Multiply</code> (the total count of variants is the product of all states). There are two other methods, Add and SelectiveMultiply.
Let's take a look at the <code>Add</code> combination mode used in this example of a flowerpot block:
<syntaxhighlight lang="json">
code: "flowerpot",
variantgroups: [
{ code: "type", states: ["raw"] },
{ code: "empty", states: ["empty"], combine: "Add" },
{ code: "flower", loadFromProperties: "block/flower", combine: "Add" },
{ code: "mushroom", loadFromProperties: "block/mushroom", combine: "Add" },
{ code: "sapling", loadFromProperties: "block/wood", combine: "Add" },
],
</syntaxhighlight>
The variants are <code>flowerpot-raw</code>, <code>flowerpot-empty</code>, <code>flowerpot-{all flowers}</code>, <code>flowerpot-{all mushrooms}</code> and <code>flowerpot-{all saplings}</code>.
<code>Add</code> mode could also be called separate, since it defines a variant separate from all the other groups:
<syntaxhighlight lang="json">
code: "thingy",
variantgroups: [
{ code: "something", states: ["same", "different"] },
{ code: "type", states: ["raw", "baked"] },
{ code: "empty", states: ["red", "green"], "combine": "Add" },
],
</syntaxhighlight>
In this case, the result would be <code>thingy-same-raw</code>, <code>thingy-same-baked</code>, <code>thingy-different-raw</code>, <code>thingy-different-baked</code>, <code>thingy-red</code> and <code>thingy-green</code>
The third combination mode <code>"SelectiveMultiply"</code> which allows you to specify which variant groups you want to combine multiplicatively with. There are many examples of this in the clothing item JSONS, as shown below with this example of a lowerbody asset:
<syntaxhighlight lang="json">
    code: "clothes",
    variantgroups: [
{ code: "category",  states: ["lowerbody"] },
{ code: "lowerbody", combine: "SelectiveMultiply", onVariant: "category", states: [
"aristocrat-leggings", "dirty-linen-trousers", "fine-trousers", "jailor-pants", "lackey-breeches", "merchant-pants", "messenger-trousers", "minstrel-pants", "noble-pants", "prince-breeches", "raindeer-trousers", "raw-hide-trousers", "shepherd-pants", "squire-pants", "steppe-shepherds-trousers", "tattered-peasent-gown", "torn-riding-pants", "warm-woolen-pants", "woolen-leggings", "workmans-gown"
        ] },
],
</syntaxhighlight>
The parameter <code>onVariant</code> specifies which variant group (by using that groups <code>code</code>) to target and the <code>code</code> specifies which of the target variant groups <code>states</code> (only one) to selectively combine with, ignoring all other variants without that specific state.
Using this will result items called <code>clothes-lowerbody-aristocrat-leggings</code>, <code>clothes-lowerbody-dirty-linen-trousers</code>, etc.
'''Variant group placeholder:'''
Since Vintagestory v1.8 it is also possible to use the variantgroups codes as placeholders (<code>{variant_group_code}</code>) in for example paths to textures.:
<syntaxhighlight lang="json">
code: "axe",
variantgroups: [
{ code: "metal", states: ["copper", "tinbronze", "bismuthbronze", "blackbronze", "gold", "silver", "iron" ] },
],
textures: {
"metal": { base: "block/metal/ingot/{metal}" },
"wood": { base: "item/tool/material/wood" }
},
</syntaxhighlight>
Now the <code>metal</code> texture path will change based on the variant. For example the variant <code>axe-copper</code> will use <code>block/metal/ingot/copper</code> as its <code>metal</code> texture.
    </td>
   </tr>
   </tr>
   <tr>
   <tr>
Line 193: Line 87:
     <td>key: string; value: object</td>
     <td>key: string; value: object</td>
     <td>-</td>
     <td>-</td>
     <td>You can create properties for certain variants of the item.</td>
     <td>Allows different property values to be [[Modding:Registry_Object_JSON_Parsing#Filtering_out_variants|specified]] based on the variant code.</td>
  </tr>
  <tr>
    <td scope="row"><div class="tt" data-tt-id="p_byType_info" data-tt-parent="p_byType" data-invisible="true"></div></td>
    <td colspan="4">
In order to define properties for specific variants you can add '''byType''' to the property name. This allows you to define it depending on the type and always follows the same syntax:
<syntaxhighlight lang="json">
(property)ByType: {
"selector": property,
"selector2": property2,
...
}
</syntaxhighlight>
 
If the selector matches the name of the variant the given property will be used. Keep in mind that only the first matching one will be used (everything below will be ignored).
 
A slab for example has two variants ('''up''', '''down'''), which have different collision boxes:
<syntaxhighlight lang="json">
collisionboxByType: {
"*-down": { x1: 0, y1: 0, z1: 0,  x2: 1, y2: 0.5, z2: 1 },
"*-up": { x1: 0, y1: 0.5, z1: 0,  x2: 1, y2: 1, z2: 1 }
},
</syntaxhighlight>
 
The char '''<code>*</code>''' stands for anything. In this case it ignores the code of the item.
 
Furthermore this opens up even more possbilities for more advanced selectors like this one for doors:
<code>*-north-*-opened-left</code>. This will ignore the second variantgroup. Additionally ByType can also be used for child properties:
<syntaxhighlight lang="json">
collisionboxnbox: {
x1: 0, y1: 0, z1: 0.875, x2: 1, y2: 1, z2: 1,
rotateYByType: {
"*-north-*-opened-left": 90,
"*-north-*-closed-left": 0,
"*-west-*-opened-left": 180,
"*-west-*-closed-left": 90,
 
"*-east-*-opened-left": 0,
"*-east-*-closed-left": 270,
"*-south-*-opened-left": 270,
"*-south-*-closed-left": 180,
 
"*-north-*-opened-right": 270,
"*-north-*-closed-right": 0,
"*-west-*-opened-right": 0,
"*-west-*-closed-right": 90,
 
"*-east-*-opened-right": 180,
"*-east-*-closed-right": 270,
"*-south-*-opened-right": 90,
"*-south-*-closed-right": 180
}
},
</syntaxhighlight>
 
    </td>
   </tr>
   </tr>
<tr>
<tr>
Line 254: Line 93:
   <td>array of strings</td>
   <td>array of strings</td>
   <td>-</td>
   <td>-</td>
   <td>Used to trim unnecessary items generated by combined variants. </td>
   <td>Used to [[Modding:Registry_Object_JSON_Parsing#Filtering_out_variants|trim]] unnecessary items generated by combined variants. </td>
   <td>crystalizedore-graded, ore-graded, ore-ungraded</td>
   <td>crystalizedore-graded, ore-graded, ore-ungraded</td>
</tr>
</tr>
<tr>
    <td scope="row"><div class="tt" data-tt-id="p_allowedVariants_info" data-tt-parent="p_allowedVariants" data-invisible="true"></div></td>
    <td colspan="4">
By using the <code>allowedVariants</code> you can specify which variants you want to be generated. Looks at this example of different armor parts (uses both <code>allowedVariants</code> and <code>skipVariants</code>):
<syntaxhighlight lang="json">
code: "armor",
variantgroups: [
{ code: "bodypart",  states: ["head", "body", "legs"] },
{ code: "construction",  states: [
"improvised",
"jerkin",
"lamellar",
"sewn",
"brigandine",
"chain",
"scale",
"plate"
]},
{ code: "material", states: [
"wood",
"leather",
"linen",
"copper",
"tinbronze",
"bismuthbronze",
"blackbronze",
"iron",
"steel",
"gold",
"silver"
]},
],
skipVariants: [
"armor-*-brigandine-leather",
"armor-*-brigandine-linen",
"armor-*-brigandine-wood",
"armor-*-brigandine-gold",
"armor-*-brigandine-silver",
"armor-*-chain-leather",
"armor-*-chain-linen",
"armor-*-chain-wood",
"armor-*-scale-leather",
"armor-*-scale-linen",
"armor-*-scale-wood",
"armor-*-scale-gold",
"armor-*-scale-silver",
"armor-*-plate-leather",
"armor-*-plate-linen",
"armor-*-plate-wood",
"armor-*-sewn-wood",
],
allowedVariants: [
"armor-body-improvised-wood",
"armor-body-jerkin-leather",
"armor-legs-jerkin-leather",
"armor-*-lamellar-wood",
"armor-*-lamellar-copper",
"armor-*-lamellar-tinbronze",
"armor-*-lamellar-bismuthbronze",
"armor-*-lamellar-blackbronze",
"armor-*-sewn-linen",
"armor-*-sewn-leather",
"armor-*-scale-*",
"armor-*-chain-*",
"armor-*-plate-*",
"armor-*-brigandine-*",
],</syntaxhighlight>
The wildcard char '''<code>*</code>''' stands for anything, and can be used to target many variants with one string instead of having to write them all down.
    </td>
  </tr>
<tr>
<tr>
   <td scope="row"><div class="tt" data-tt-id="p_skipVariants" data-tt-parent="root">skipVariants</div></td>
   <td scope="row"><div class="tt" data-tt-id="p_skipVariants" data-tt-parent="root">skipVariants</div></td>
   <td>array of strings</td>
   <td>array of strings</td>
   <td>-</td>
   <td>-</td>
   <td>Similar to allowedVariants, but instead skips the creation of listed variants rather than assigning which are allowed. </td>
   <td>Similar to allowedVariants, but instead [[Modding:Registry_Object_JSON_Parsing#Filtering_out_variants|skips]] the creation of listed variants rather than assigning which are allowed. </td>
   <td>armor</td>
   <td>armor</td>
</tr>
</tr>
<tr>
    <td scope="row"><div class="tt" data-tt-id="p_skipVariants_info" data-tt-parent="p_skipVariants" data-invisible="true"></div></td>
    <td colspan="4">
By using the <code>skipVariants</code> you can specify which variants you do NOT want to be generated. For an example look above under <code>allowedVariants</code> which shows both <code>allowedVariants</code> and <code>skipVariants</code> in use at the same time.
    </td>
  </tr>
   <tr>
   <tr>
     <td colspan="5" style='font-size: 14pt; border-bottom: 2pt solid black; padding-left: 100px;'><b>Specific</b></td>
     <td colspan="5" style='font-size: 14pt; border-bottom: 2pt solid black; padding-left: 100px;'><b>Specific</b></td>
Confirmedusers
261

edits