Modding:Entity Json Properties: Difference between revisions

From Vintage Story Wiki
Factor out how variants are defined into Modding:Registry_Object_JSON_Parsing
(Marked this version for translation)
(Factor out how variants are defined into Modding:Registry_Object_JSON_Parsing)
Line 47: Line 47:
     <td>array of object</td>
     <td>array of object</td>
     <td>-</td>
     <td>-</td>
     <td>Allows you define multiple variants of the same entity.</td>
     <td>Allows you define multiple [[Modding:Registry_Object_JSON_Parsing|variants]] of the same entity.</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="3">
The variantgroups property allows you to define multiple variants of this entity. All of them will have their unique pattern, which will be added to the entity code.
 
An easy example would be a sheep, which can either be small or tall:
<syntaxhighlight lang="json">
variantgroups: [
{ code:"size", states: ["small", "tall"] },
],
</syntaxhighlight>
 
Meaning there will be two blocks <code>sheep-small</code> and <code>sheep-tall</code>.
 
----
 
It's also possible to define multiple groups.
 
<syntaxhighlight lang="json">
variantgroups: [
{ code:"size", states: ["small", "tall"] },
{ code:"color", states: ["white", "black"] },
],
</syntaxhighlight>
 
As a result you will have 2x2 groups, which will be added one after each other: <code>sheep-small-white</code>, <code>sheep-tall-white</code>, <code>sheep-small-black</code> and <code>sheep-tall-black</code>.
 
----
 
Additionally it is possible to refer to external lists 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 full list of all groups and their variants (you can also find them in the <code>assets/worldproperties</code> folder):
{{:json:block:worldvariantgroups}}
----
 
Futhermore there are two ways of combining groups together. So far we covered the default combination mode, which is <code>multiplicative</code> (the total count of variants is the product of all states).
 
Imagine you want to implement a living tree, were either flowers, mushrooms or saplings or on it. You can use the <code>additive</code> combination mode for that:
<syntaxhighlight lang="json">
variantgroups: [
{ code: "type", loadFromProperties: "block/wood" },
{ code: "flower", loadFromProperties: "block/flower", combine: "additive" },
{ code: "mushroom", loadFromProperties: "block/mushroom", combine: "additive" },
{ code: "sapling", loadFromProperties: "block/wood", combine: "additive" },
],
</syntaxhighlight>
 
The living trees exists for every wood type (birch, oak, maple, pine, acacia, kapok) and can either have a flower, mushroom or a sapling suffix: <code>livingtree-{wood type}-{flower}</code>, <code>livingtree-{wood type}-{all flowers}</code>, <code>livingtree-{wood type}-{all mushrooms}</code> and <code>livingtree-{wood type}-{all saplings}</code>.
    </td>
   </tr>
   </tr>
   <tr>
   <tr>
Line 109: Line 53:
     <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 block.</td>
     <td>Allows different property values to be [[Modding:Registry_Object_JSON_Parsing#ByType_properties|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="3">
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).
 
An entity for example has two variants ('''big''', '''small'''):
<syntaxhighlight lang="json">
falldamagebyType: {
"*-big": true,
"*-small": false
},
</syntaxhighlight>
 
Since Vintagestory v1.8 it is also possible to use the variantgroup as a placeholder:
<syntaxhighlight lang="json">
variantgroups: [
{ code: "type", states: ["normal", "bamboo"] },
],
texture: { base: "entity/fish/{type}" }
</syntaxhighlight>
</td>
   </tr>
   </tr>
<tr>
  <td scope="row"><div class="tt" data-tt-id="p_allowedVariants" data-tt-parent="root">allowedVariants</div></td>
  <td>array of strings</td>
  <td>-</td>
  <td>Used to [[Modding:Registry_Object_JSON_Parsing#Filtering_out_variants|trim]] unnecessary items generated by combined variants. </td>
</tr>
<tr>
  <td scope="row"><div class="tt" data-tt-id="p_skipVariants" data-tt-parent="root">skipVariants</div></td>
  <td>array of strings</td>
  <td>-</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>
</tr>
   <tr>
   <tr>
     <td colspan="4" style='font-size: 14pt; border-bottom: 2pt solid black; padding-left: 100px;'><b>Common</b></td>
     <td colspan="4" style='font-size: 14pt; border-bottom: 2pt solid black; padding-left: 100px;'><b>Common</b></td>
Confirmedusers
261

edits