Modding:Entity Json Properties: Difference between revisions

From Vintage Story Wiki
no edit summary
No edit summary
No edit summary
Line 23: Line 23:
     <td>string</td>
     <td>string</td>
     <td>required</td>
     <td>required</td>
     <td>A unique identifier for the item.</td>
     <td>A unique identifier for the entity.</td>
   </tr>
   </tr>
   <tr>
   <tr>
Line 40: Line 40:
     <td>boolean</td>
     <td>boolean</td>
     <td>true</td>
     <td>true</td>
     <td>If the item will be loaded or not. Can be used to temporarily remove the item.</td>
     <td>If the entity will be loaded or not. Can be used to temporarily remove the entity.</td>
  </tr>
  <tr>
    <td scope="row"><div class="tt" data-tt-id="p_variantgroups" data-tt-parent="root">VariantGroups</div></td>
    <td>array of object</td>
    <td>-</td>
    <td>Allows you define multiple 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>
    <td scope="row"><div class="tt" data-tt-id="p_byType" data-tt-parent="root">(any) byType</div></td>
    <td>key: string; value: object</td>
    <td>-</td>
    <td>You can create properties for certain variants of the block.</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).
 
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 block.
 
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>
 
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>
    <td colspan="4" style='font-size: 14pt; border-bottom: 2pt solid black; padding-left: 100px;'><b>Common</b></td>
   </tr>
   </tr>
  </table>
  </table>
Confirmedusers, editor, Administrators
886

edits