Confirmedusers
510
edits
(Note that the RFC is not complete and point to the source) |
(Make the output of addmerge more specific in the example) |
||
Line 159: | Line 159: | ||
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 -'''): | 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"> | ||
// Bad patch example | |||
[ | [ | ||
{ | { | ||
Line 169: | Line 170: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
However, in version 1.19.4 the vanilla fat object was changed to include a behaviors array | However, in version 1.19.4 the vanilla fat object was changed to include a behaviors array. | ||
<syntaxhighlight lang="json"> | <syntaxhighlight lang="json"> | ||
// Section of fat.json from 1.19.4 | |||
behaviors: [ | behaviors: [ | ||
{ name: "GroundStorable", properties: { layout: 'Quadrants', collisionBox: { x1: 0, y1: 0, z1: 0, x2: 1, y2: 0.125, z2: 1 }, scale: 0.3 } } | { name: "GroundStorable", properties: { layout: 'Quadrants', collisionBox: { x1: 0, y1: 0, z1: 0, x2: 1, y2: 0.125, z2: 1 }, scale: 0.3 } } | ||
], | ], | ||
</syntaxhighlight> | </syntaxhighlight> | ||
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. | |||
<syntaxhighlight lang="json"> | |||
// Result of bad patch on 1.19.4 | |||
behaviors: [{ "name": "SealPlacedCrock" }], | |||
</syntaxhighlight> | |||
Whereas, instead the patch could use the "addmerge" operation (putting aside that the "addmerge" operation didn't exist in 1.19.3). | |||
<syntaxhighlight lang="json"> | |||
// Good patch example | |||
[ | |||
{ | |||
"op": "addmerge", | |||
"path": "/behaviors", | |||
"value": [{ "name": "SealPlacedCrock" }], | |||
"file": "game:itemtypes/resource/fat.json" | |||
} | |||
] | |||
</syntaxhighlight> | |||
If the target array exists (which it does in this example), then addmerge will append the patch array to the target array instead of replacing it. | |||
<syntaxhighlight lang="json"> | |||
// Result of good patch on 1.19.4 | |||
behaviors: [ | |||
{ name: "GroundStorable", properties: { layout: 'Quadrants', collisionBox: { x1: 0, y1: 0, z1: 0, x2: 1, y2: 0.125, z2: 1 }, scale: 0.3 } } | |||
], | |||
behaviors: [{ "name": "SealPlacedCrock" }], | |||
</syntaxhighlight> | |||
Note that when the path ends with a number, "addmerge" will not merge the patch value into the existing array entry at that index. It will instead insert the patch value as a new entry at that index. | |||
<!--T:34--> | <!--T:34--> |