Modding:CompatibilityLib: Difference between revisions

From Vintage Story Wiki
(Add array tip)
m (Fixed simple example to match text and reworded dependsOn explainer)
Line 12: Line 12:
=== Usage example ===
=== Usage example ===


I have a More Variants mod (modid - morevariants), I want to add a patch to support Carry Capacity (modid - carrycapacity) and add recipes for Extra Chests (modid - extrachests). As a result, the assets will look like this:
I have a More Variants mod (<code>morevariants</code>), I want to add a patch to support Carry Capacity (<code>carrycapacity</code>) and add recipes for Better Chests (<code>betterchests</code>). As a result, the assets will look like this:


   - assets
   - assets
Line 31: Line 31:
== Mod-dependent json-patch ==
== Mod-dependent json-patch ==


You can use dependsOn[] in json-patch for create mod-dependent patch.
You can use <code>dependsOn[]</code> in a JSON patch to create a mod-dependent patch.


Be careful. Do not use this for patches of other patches. This will lead to undefined behavior, you can patch a patch that already done. If you want to change a patch from another mod - use the first method
Do not use this for patches of other patches as this will lead to undefined behavior. If you want to change a patch from another mod, use the method detailed above to overwrite those assets.


=== Usage example ===
=== Usage example ===


<code>dependsOn[{"modid": "morerecipes"}]</code> - loaded if enabled morerecipes mod <br>
<code>dependsOn[{"modid": "morerecipes"}]</code> - loaded if the <code>morerecipes</code> mod is enabled <br>
<code>dependsOn[{"modid": "morerecipes", "invert": true}]</code> - loaded if disabled morerecipes mod <br>
<code>dependsOn[{"modid": "morerecipes", "invert": true}]</code> - loaded if the <code>morerecipes</code> mod is disabled <br>
<code>dependsOn[{"modid": "morerecipes"}, {"modid": "captureanimals"}]</code> - loaded if enabled morerecipes AND captureanimals mods <br>
<code>dependsOn[{"modid": "morerecipes"}, {"modid": "captureanimals"}]</code> - loaded if the <code>morerecipes</code> AND <code>captureanimals</code> mods are enabled <br>
<code>dependsOn[{"modid": "morerecipes"}, {"modid": "captureanimals", "invert": true}]</code> - loaded if enabled morerecipes AND disabled captureanimals <br>
<code>dependsOn[{"modid": "morerecipes"}, {"modid": "captureanimals", "invert": true}]</code> - loaded if the <code>morerecipes</code> mod is enabled AND the <code>captureanimals</code> mod is disabled <br>


<syntaxhighlight lang="json">
<syntaxhighlight lang="json">

Revision as of 15:59, 20 October 2024

This page was last verified for Vintage Story version 1.19.

A simple embeded library for Vintage Story that makes it easy to add compatibility with other mods for assets.

Easy way (overwriting assets)

You just need to add your asset to assets/<yourmodid>/compatibility/<othermodid>/<path-to-asset>. They will only be loaded if <othermodid> is loaded.

If assets/<yourmodid>/<vanilla-path> and assets/<yourmodid>/compatibility/<othermodid>/<vanilla-path> exists then if <othermodid> is loaded, the first asset will be rewrited.

Usage example

I have a More Variants mod (morevariants), I want to add a patch to support Carry Capacity (carrycapacity) and add recipes for Better Chests (betterchests). As a result, the assets will look like this:

 - assets
   - morevariants
     - blocktypes
     - patches
     - recipes
     - compatibility
       - carrycapacity
         - patches
           - carryable.json
       - betterchests
         - recipes
           - grid
             - copperchest.json
             - copperlabeledchest.json

Mod-dependent json-patch

You can use dependsOn[] in a JSON patch to create a mod-dependent patch.

Do not use this for patches of other patches as this will lead to undefined behavior. If you want to change a patch from another mod, use the method detailed above to overwrite those assets.

Usage example

dependsOn[{"modid": "morerecipes"}] - loaded if the morerecipes mod is enabled
dependsOn[{"modid": "morerecipes", "invert": true}] - loaded if the morerecipes mod is disabled
dependsOn[{"modid": "morerecipes"}, {"modid": "captureanimals"}] - loaded if the morerecipes AND captureanimals mods are enabled
dependsOn[{"modid": "morerecipes"}, {"modid": "captureanimals", "invert": true}] - loaded if the morerecipes mod is enabled AND the captureanimals mod is disabled

[
  {
    // If you add enabled: false to your recipe, you can simply enable it when the desired mod is loaded
    "file": "recipes/grid/best-other-fish-recipe.json",
    "op": "replace",
    "path": "/enabled",
    "value": true,
    "dependsOn": [{ "modid": "primitivesurvival" }]
  },
  {
    // Otherwise, just disable the recipe when the mod is not loaded
    "file": "recipes/grid/best-fish-recipe.json",
    "op": "add",
    "path": "/enabled",
    "value": false,
    "dependsOn": [{ "modid": "primitivesurvival", "invert": true }]
  }, 
  {
    // Or when two mods are loaded :P
    "file": "recipes/grid/best-fish-recipe-with-acorns.json",
    "op": "replace",
    "path": "/enabled",
    "value": true,
    "dependsOn": [
        { "modid": "primitivesurvival" },
        { "modid": "acorns" }
     ]
  },
  {
    // For simplicity, you can patch all recipes in a folder at once with *
    "file": "recipes/grid/morerecipes-disable/*",
    "op": "add",
    "path": "/enabled",
    "value": false,
    "dependsOn": [{ "modid": "morerecipes" }]
  },
  {
    // In some cases you need to specify which recipe you want to change if they were created in an array. For more see JSON Patching wiki page
    "file": "recipes/grid/best-fish-recipes.json",
    "op": "add",
    "path": "/0/enabled",
    "value": false,
    "dependsOn": [{ "modid": "primitivesurvival" }]
  }
]


Content Modding
Basics Content Mods Developing a Content Mod Packaging & Release
Tutorials
Concepts Modding Concepts Modinfo Variants Domains Patching Remapping World Properties
Moddable Assets
Uncategorized
Icon Sign.png

Wondering where some links have gone?
The modding navbox is going through some changes! Check out Navigation Box Updates for more info and help finding specific pages.

Modding
Modding Introduction Getting Started Theme Pack
Content Modding Content Mods Developing a Content Mod Basic Tutorials Intermediate Tutorials Advanced Tutorials Content Mod Concepts
Code Modding Code Mods Setting up your Development Environment
Property Overview ItemEntityEntity BehaviorsBlockBlock BehaviorsBlock ClassesBlock EntitiesBlock Entity BehaviorsCollectible BehaviorsWorld properties
Workflows & Infrastructure Modding Efficiency TipsMod-engine compatibilityMod ExtensibilityVS Engine
Additional Resources Community Resources Modding API Updates Programming Languages List of server commandsList of client commandsClient startup parametersServer startup parameters
Example ModsAPI DocsGitHub Repository