Jump to content

Compatibility Lib v1.2.2 (easy way to add assets for compatibility with other mods)


DArkHekRoMaNT

Recommended Posts

Embedded in vanilla since 1.15.0, do not use the library as mod in later versions, the game will crash.
All functionality is preserved, so nothing will change for mod authors other than library dependency.

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

Easy way

Spoiler

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

For 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

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

Advanced (v1.2+)

Spoiler

You can use dependsOn[] in json-patch for create mod-dependent patch. For 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

Warning! Unlike the easy way, if you use mod-dependent patches, it is advisable to add compatibilitylib in the mod dependencies, otherwise all patches will be loaded without the library installed.

How to add to modinfo.json:

{
  "modid": "bestmod",
  <...>
  "dependencies": {
    "game": "1.13.4", <-- minimal game version for your mod
    "compatibilitylib": "1.2.0" <-- minimal CL version
  }
}

 

Full patch example:

[
  {
    "_comment": "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" }]
  },
  {
    "_comment": "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 }]
  },
  {
    "_comment": "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" }
     ]
  },
  { "_comment": "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" }]
  }
]

 

Download: ModDB or GitHub

Install as a regular mod, just add archive to your mods folder.

Edited by DArkHekRoMaNT
embedded warning
  • Like 4
  • Thanks 4
Link to comment
Share on other sites

  • DArkHekRoMaNT changed the title to Compatibility Lib v1.1 (easy way to add compatibility with other mods)
  • 2 weeks later...
  • DArkHekRoMaNT changed the title to Compatibility Lib v1.1 (easy way to add assets for compatibility with other mods)
  • 2 weeks later...

so would this work with my Clay+Misc mod or do I need to finish cleaning it up and replacing everything in a more traditional mod form to work?

right now it's only released as it is made using the mod maker provided by VS and as result it doesn't transfer textures so I opened the mod zip it created and added the texture folder manually, other than that it is however the mod maker makes it.

I haven't gotten any feed back so I don't know if my mod even works for other people as of right now. it works for me but that's because I have the original JSON that I added in the vanilla Roaming > Vintagestory > assets > survival folder and everything is working on my end except the poring of the saw mold and I'm working on that. 

I'll be re-writing the whole thing in a proper mod folder using the game: reference line and everything but right now it's being hard to make work that way. it works best right in the folders themselves but I'm still learning and working on it. 

I wish it was as easy as modding 7 days to die and simply have a UIAtlases for my textures and a mod folder with <mymodname> <append xpath="/items"> put all the new items I want to add between here then close it with </append> </mymodname> this would be so much easier but this whole JSON thing is new to me and I'm still trying to figure it out.

Link to comment
Share on other sites

2 hours ago, Sukotto82 said:

Roaming > Vintagestory > assets > survival

Don't do this, it will NOT work for other people.  Put this file in assets/game in your mod folder.

But in general, the library just looks at the assets in the compatibility category and checks for the modid in the list of loaded mods.  This should work for vanilla too.

 

Edited by DArkHekRoMaNT
  • Thanks 1
Link to comment
Share on other sites

  • 1 month later...

Okay, I have a lot of mods now and would like a few more but need this, but have been avoiding this because I don't understand this. I have only ever been a designer and dabbled in flash animation a long while ago but am better at graphics than code. So I can't comfortable use something I don't understand. So, can I get a step by step for dummies on how to use this and when to use this mod and what you use and where the assets might be? Sorry...

Link to comment
Share on other sites

  • DArkHekRoMaNT changed the title to Compatibility Lib v1.2 (easy way to add assets for compatibility with other mods)
  • DArkHekRoMaNT changed the title to Compatibility Lib v1.2.1 (easy way to add assets for compatibility with other mods)

Hey. I tried some things with your mod and the 'dependsOn ' but couldn't get the 'invert' to work. So i looked at the source code of your mod and noticed that in the ModJsonPatchLoaderPatch.cs file the line 108 is:

 flag = flag && (loaded & !dependence.invert);

But doesn't that mean that it will be false whenever loaded ís false? So it is not inverted. Shouldn't it be something like:

flag = flag && (loaded ^ dependence.invert);

For an exclusive or. Or do I get something wrong and don't understand how it's supposed to work?

  • Confused 1
Link to comment
Share on other sites

  • DArkHekRoMaNT changed the title to Compatibility Lib v1.2.2 (easy way to add assets for compatibility with other mods)
  • 3 months later...
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.