Modding:JSON Patching: Difference between revisions

From Vintage Story Wiki
Describe addmerge operation
(updated for 1.19.4 and cleaned up a bit)
(Describe addmerge operation)
Line 143: Line 143:
To avoid the possibility of mod conflicts, do not use the '''game''' folder. Instead, use a folder with the same name as your '''modid'''; that is, your mod's domain. So in this example, WolvesAreWimps.zip should instead have the folders '''assets\wolvesarewimps\patches''' and WolvesDropSticks.zip should instead have the folders '''assets\wolvesdropsticks\patches'''. File names are also arbitrary, you do not need to use '''survival-entities-land-wolf-male.json''' and can name the file anything you want, since its contents direct the game on what and how to patch, not the file's name.
To avoid the possibility of mod conflicts, do not use the '''game''' folder. Instead, use a folder with the same name as your '''modid'''; that is, your mod's domain. So in this example, WolvesAreWimps.zip should instead have the folders '''assets\wolvesarewimps\patches''' and WolvesDropSticks.zip should instead have the folders '''assets\wolvesdropsticks\patches'''. File names are also arbitrary, you do not need to use '''survival-entities-land-wolf-male.json''' and can name the file anything you want, since its contents direct the game on what and how to patch, not the file's name.
   
   
=== Overwriting issue === <!--T:33-->   
=== AddMerge operation === <!--T:33-->   


<!--T:31-->
In addition to the "add" operation, the "addmerge" operation was added in version 1.19.4. "addmerge" is safer, and should be generally be used instead of "add.
Patches that are creating e.g. behaviors or attributes (for example, if item does not have it), will be overwritten by patches from other mods that are doing same, but with another value.


<!--T:32-->
They behave the same in many conditions:
For example, this patch will be overwritten with patch from example below, even if '''add''' operation is used:
* For targets that do not exist, both create the target
* For paths that end with '''dash -''', both will append a new entry to the target array
* For paths that end with a number, both will insert the value into the target array at that location
* For paths that point to an existing primitive value (string, bool, or int), both will replace the value
 
However, they differ when the target is an existing array or object. "add" will replace the target with the patch value. "addmerge" will append the patch value if the target is an array. "addmerge" will merge the value if the target is an object.
 
For example, prior to version 1.19.4, the fat item did not have a behaviors array. Let's say a mod added the behaviors through a patch (notice the path does not end in '''dash -'''):
<syntaxhighlight lang="json">
<syntaxhighlight lang="json">
[
[
Line 160: Line 166:
]
]
</syntaxhighlight>
</syntaxhighlight>
However, in version 1.19.4 the vanilla fat object was changed to include a behaviors array. So if the old patch was applied on the new game version, then it would replace the vanilla behavior instead of adding a new behavior. Whereas, if the patch used the "addmerge" operation (putting aside that the "addmerge" operation didn't exist in 1.19.3), then it would add instead of replace the behavior in 1.19.4.
<syntaxhighlight lang="json">
<syntaxhighlight lang="json">
[
        behaviors: [
  {
                { name: "GroundStorable", properties: { layout: 'Quadrants', collisionBox: { x1: 0, y1: 0, z1: 0, x2: 1, y2: 0.125, z2: 1 }, scale: 0.3 } }
    "op": "add",
        ],
    "path": "/behaviors",
    "value": [{ "name": "Placeable" }],
    "file": "game:itemtypes/resource/fat.json"
  }
]
</syntaxhighlight>
</syntaxhighlight>


<!--T:34-->
<!--T:34-->
'''Note''' : see the [[Modding:CompatibilityLib|Compatibility]] page for possible ways to handle conflicts and dependencies between mods.
'''Note''' : see the [[Modding:CompatibilityLib|Compatibility]] page for other ways to handle conflicts and dependencies between mods.
 


<!--T:26-->
<!--T:26-->
Confirmedusers
261

edits