Modding:Item Json Properties: Difference between revisions

From Vintage Story Wiki
m
Minor clarification.
m (Minor clarification.)
 
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<languages/>
<translate>
{{GameVersion|1.19}}
__NOTOC__
__NOTOC__
== Overview ==
== Overview == <!--T:1-->
A complete list of all available properties
This is a mostly-complete list of available properties for items. To see an exhaustive list of properties, check out the [https://github.com/anegostudios/vsessentialsmod/blob/master/Loading/ItemType.cs ItemType] and [https://github.com/anegostudios/vsessentialsmod/blob/master/Loading/CollectibleType.cs CollectibleType] GitHub pages. Any value immediately underneath a <code>[JsonProperty]</code> label can be used within an itemtype file.


<!--T:2-->
Definitions:
Definitions:


<!--T:3-->
'''Key''' - The name of the property, which should be used as it appears in the column.
'''Key''' - The name of the property, which should be used as it appears in the column.


<!--T:4-->
'''Value''' - A component of a property.
'''Value''' - A component of a property.


<!--T:5-->
'''Array''' - A list of objects or values that can be referenced in code.
'''Array''' - A list of objects or values that can be referenced in code.


<!--T:6-->
'''String''' - A sequence of characters that can be used as an identifier in code. Essentially a word that can be referenced and assigned to something. Generally does not use numbers.
'''String''' - A sequence of characters that can be used as an identifier in code. Essentially a word that can be referenced and assigned to something. Generally does not use numbers.


<!--T:7-->
'''Boolean''' - A true or false value, essentially "on" or "off".  
'''Boolean''' - A true or false value, essentially "on" or "off".  


<!--T:8-->
'''Int''' - An integer, or whole number. Cannot use decimal values.  
'''Int''' - An integer, or whole number. Cannot use decimal values.  


'''Float''' - A decimal, specifically one that does not exceed more than 1 significiant digit
<!--T:9-->
'''Float''' - A decimal, specifically one that does not exceed more than 1 significant digit


<!--T:10-->
'''Object''' - This is a bit more complex, but essentially objects are the items, blocks and entities that can be interacted with. In most cases, when an "object" type appears it means you must use a specific item variant code, which follows the "itemcode-variant_1-variant_2-variant_n" style of naming.  
'''Object''' - This is a bit more complex, but essentially objects are the items, blocks and entities that can be interacted with. In most cases, when an "object" type appears it means you must use a specific item variant code, which follows the "itemcode-variant_1-variant_2-variant_n" style of naming.  


 
</translate>


<table id="treeviewtable" class="table table-bordered tt-table" style='table-layout: fixed'>
<table id="treeviewtable" class="table table-bordered tt-table" style='table-layout: fixed'>
Line 70: Line 82:
     <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">
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">
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 full list of all groups and their variants (you can also find them in the <code>assets/worldproperties</code> folder):
{{:json:block:worldvariantgroups}}
----
Furthermore there are other 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). There are two other methods, Additive and SelectiveMultiply.
Let's take a look at the <code>additive</code> combination mode used in the flowerpot block:
<syntaxhighlight lang="json">
variantgroups: [
{ code: "type", states: ["raw"] },
{ code: "empty", states: ["empty"], combine: "additive" },
{ code: "flower", loadFromProperties: "block/flower", combine: "additive" },
{ code: "mushroom", loadFromProperties: "block/mushroom", combine: "additive" },
{ code: "sapling", loadFromProperties: "block/wood", combine: "additive" },
],
</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>Additive</code> mode could also be called separate, since it defines a variant separate from all the other groups:
<syntaxhighlight lang="json">
variantgroups: [
{ code: "something", states: ["same", "different"] },
{ code: "type", states: ["raw", "baked"] },
{ code: "empty", states: ["red", "green"], "combine": "additive" },
],
</syntaxhighlight>
In this case, the result would be <code>same-raw</code>, <code>same-baked</code>, <code>different-raw</code>, <code>different-baked</code>, <code>red</code> and <code>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 the 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 function <code>onVariant</code> specifies which variant group to selectively combine with, ignoring all other variants without it (in case some are combined additively).
Using this will result items called <code>clothes-lowerbody-aristocrat-leggings</code>, <code>clothes-lowerbody-dirty-linen-trousers</code>, etc.
    </td>
   </tr>
   </tr>
   <tr>
   <tr>
Line 164: Line 89:
     <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#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).
 
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>
 
Since Vintagestory v1.8 it is also possible to use the variantgroup as a placeholder:
<syntaxhighlight lang="json">
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>
</td>
   </tr>
   </tr>
   <tr>
   <tr>
Line 235: Line 95:
   <td>array of objects</td>
   <td>array of objects</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>  
Line 242: Line 102:
   <td>array of object</td>
   <td>array of object</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>
Line 813: Line 673:
</tr>
</tr>
<tr>
<tr>
   <td scope="row"><div class="tt" data-tt-id="p_alist_stat_hunger" data-tt-parent="p_alist_astats">healingeffectiveness</div></td>
   <td scope="row"><div class="tt" data-tt-id="p_alist_stat_hunger" data-tt-parent="p_alist_astats">hungerrate</div></td>
   <td>number, decimal</td>
   <td>number, decimal</td>
   <td>-</td>
   <td>-</td>
Line 1,490: Line 1,350:


<syntaxhighlight lang="json">
<syntaxhighlight lang="json">
transitionableProps [{
transitionableProps: [{
   type: "Perish",
   type: "Perish",
   freshHours: { avg: 240 },
   freshHours: { avg: 240 },
Confirmedusers
536

edits