Modding:CompatibilityLib

From Vintage Story Wiki

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 (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:

 - 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 json-patch for create 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

Usage example

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

[
  {
    // 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" }]
  }
]


Modding
Green Items require C# coding
Basics

Getting Started | Mod Types | Simple Examples | Theme Pack

Asset System | Textures | Items | Recipes | Blocks | Entities | Model Creator | Animation Basics | VTML & Icons | Mod Packaging & Release | Modinfo | Debugging

Advanced

JSON Patching | Advanced JSON Items | The Remapper | Server-Client Considerations | Compatibility with other mods

Setting Up Your Development Environment (General - Windows - Linux)

Advanced Blocks | Advanced Items | Item-Block Interactions | Block Behavior | Block Entities | Particle Effects | World Access | Inventory Handling | Chat Commands | GUIs | Server-Client Networking | Monkey patching (Harmony)

Data Management

Savegame Data Storage | ModConfig File | Chunk Data Storage | Tree Attribute

Worldgen

WorldGen Concepts | Terrain | Ores | Trees | WorldGen API | NatFloat | EvolvingNatFloat | Json Random Generator

Rendering

Shaders and Renderers

Property Overview

Item | Entity | Block | Block Behaviors | Block Classes | Block Entities | Block Entity Behaviors

Workflows & Infrastructure

Modding Efficiency Tips | Mod-engine compatibility | Mod Extensibility | Load Order

Additional Resources

List of server commands | List of client commands | Client startup parameters | Creative Starter Guide | ServerBlockTicking | Bot System | WorldEdit | Cinematic Camera | Adjustable FPS Video Recording

Example Mods | API Docs | GitHub Repository