User Tools

Site Tools


ru:tutorial:dependency_overrides

This is an old revision of the document!


Подмена зависимостей

В загрузчике Fabric версии 0.11.1 была представлена новая возможность - “подмена зависимостей”.

Перед использованием: Эта возможность разработана в первую очередь для контроля зависимостей для разработчиков модов.

Как простой игрок, вам нет смысла от этого, но это будет полезно для разработчиков модов.

Требования

  • Загрузчик Fabric 0.11.1 или новее
  • Знание принципа работы с fabric.mod.json (в т.ч. и с пятью типами зависимостей: depends, recommends, suggests, conflicts, breaks).

Для начала

Для начала создайте файл fabric_loader_dependencies.json в папке config (которая находится в папке .minecraft).

После напишите в файл следующее:

  1. {
  2. "version": 1,
  3. "overrides": {
  4.  
  5. }
  6. }

Давайте построчно разберём что делает этот файл.

Первое - version. Этот пункт указывает на “внутренюю” версию зависимости. На момент написания страницы актуальная версия это 1.

Второе - overrides (пока что пусто). Этот Json-объект будет хранить в себе все зависимости от нашего мода.

Как настроить

Inside the overrides object, we may add entries with a key of a loaded mod's ID and a value of a Json object. For example, if a loaded mod's ID is mymod, We can do the following:

  1. {
  2. "version": 1,
  3. "overrides": {
  4. "mymod": {}
  5. }
  6. }

As mentioned above, mymod has the value of a Json object. Inside that object, we can add dependency overrides.

Keys inside the mod object can be one of the 5 dependency types (depends, recommends, suggests, conflicts, breaks).

The key may be optionally prefixed with + or - (e.g. “+depends”, “-breaks”).

The value of any one of those keys must be a Json object. This Json object follows the exact same structure as a fabric.mod.json dependency object.

If the key is prefixed with +, the entries inside that Json object will be added (or overridden if already exist) to the mod.

If the key is prefixed with -, the value of each entry is ignored completely and Fabric Loader will remove those entries from the resulting dependency map.

If the key isn't prefixed, the dependency object will be replaced completely. Be careful to prefix your keys!

Practical Example

Let's assume that a mod with ID specificmod depends on Minecraft version 1.16.4 exactly, but we want it to work on other 1.16 versions. Let's see how we can do that:

  1. {
  2. "version": 1,
  3. "overrides": {
  4. "specificmod": {
  5. "+depends": {
  6. "minecraft": "1.16.x"
  7. }
  8. }
  9. }
  10. }

A “minecraft” dependency will now be overridden if specified (and we know it is). There is another way to do this:

  1. {
  2. "version": 1,
  3. "overrides": {
  4. "specificmod": {
  5. "-depends": {
  6. "minecraft": "IGNORED"
  7. }
  8. }
  9. }
  10. }

As specified above, the value of key “minecraft” will be ignored when removing dependencies. If a dependency with a mod ID requirement of minecraft is found, it will be removed from our target mod specificmod.

We can also override the entire depends block, but with great power comes great responsibility. Be careful.

Let's assume that specificmod's dependency specification (inside fabric.mod.json) looks something like this:

{
  "depends": {
    "fabricloader": ">=0.11.1",
    "fabric": ">=0.28.0",
    "minecraft": "1.16.4"
  },
  "breaks": {
    "optifabric": "*"
  },
  "suggests": {
    "anothermod": "*",
    "flamingo": "*",
    "modupdater": "*"
  }
}

Aside from changing the minecraft dependency, we also want to remove all suggests dependencies. We can do that like so:

  1. {
  2. "version": 1,
  3. "overrides": {
  4. "specificmod": {
  5. "-depends": {
  6. "minecraft": ""
  7. },
  8. "suggests": {}
  9. }
  10. }
  11. }

Because the suggests key was not prefixed, it was completely replaced with an empty object, essentially clearing it.

ru/tutorial/dependency_overrides.1612095921.txt.gz · Last modified: 2021/01/31 12:25 by magicsweet