Skip to content

JSON API

Dana edited this page Aug 8, 2024 · 20 revisions

Documentation of JSON API of Recipe Patcher

Introduction

Recipe Patcher is server-side dependency, which means that it should be installed only server-side, for example, when you host server or playing single-player. When you add integration with this library, make sure to notify users of your mod about this!

Patches

Recipe Patcher implements its own patching system. Any recipe can be patched (at the moment only grid recipes are supported!)

Patches are loaded from assets/<modid>/config/recipepatches folder. Example.

There are currently three types of patches, each of them have their specific reasons to be used:

  • Replace - replaces ingredients without changing output.
  • Copy - copies original recipe and then replaces ingredients and output.
  • CopyReplaceIngredients - copies original recipe and then replaces ingredients, but without changing output.

When all patches are applied, it will write log to server-main.txt, for example:

28.4.2024 11:04:24 [Notification] [Recipe Patcher] RecipePatch Loader: completed in 131 ms, 516 patches total, successfully replaced 61 recipes, successfully created 183 recipes, unmet conditions on 322 patches
Load order

Replace patches applied first, Copy patches applied last.

Example:

{
    "type": "Copy",
    "conditions": [{ "when": "VanillaVariants_ArmorStand_Enabled", "isValue": "true" }],
    "dependsOn": [{ "modid": "wildcrafttree" }],
    "outputCode": "armorstand",
    "outputCodeNew": "wildcrafttree:armorstand-{wood}",
    "ingredients": [{ "ingredientCode": "plank-*", "Code": "wildcrafttree:plank-*", "Name": "wood", "SkipVariants": ["oak"] }]
}

Patch Properties

Enabled (bool)

If set to false, patch won't be applied. For example:

"enabled": false

Type (EnumRecipePatchType)

Available types: Replace, Copy, CopyReplaceIngredients. For example:

"type": "Replace"

Conditions (PatchCondition[])

You need code for this to work.

Applies patch only if all config values in world config were matched. For example:

"conditions": [{ "when": "SomethingEnabled", "isValue": "true" }]

DependsOn (PatchModDependence[])

Applies patch only when specific mods are loaded / not loaded. For example:

"dependsOn": [{ "modid": "wildcrafttree" }]

Example for not loaded mod:

"dependsOn": [{ "modid": "wildcrafttree", "invert": true }]

OutputCode (string)

Applies patch only when output code is matched. Supports wildcards and regex. For example:

"OutputCode": "bed-wood-head-north"

Example for wildcard:

"OutputCode": "log-*"

OutputCodeNew (string)

Changes output code to new code. For example:

"OutputCode": "bed-wood-head-north",
"OutputCodeNew": "modid:bed-{wood}-head-north",

In this example I used {wood}, because some ingredients have "name": "wood" property

Quantity (int)

Applies patch only when output quantity is matched. For example:

"quantity": 1

QuantityNew (int)

Changes quantity of output. For example:

"quantityNew": 4

Attributes (JsonObject)

Applies patch only when attributes of output are matched. For example:

"attributes": { "type": "normal-generic" }

AttributesNew (JsonObject)

Changes attributes of output. For example:

"attributesNew": { "wood": "purpleheart" }

RecipeGroup (int)

Changes recipe group of recipe. For example:

"recipeGroup": 2

Ingredients (IngredientPatch[])

Applies patch only to ingredients which code matches IngredientCode.

IngredientCode (string)

Applies patch only to ingredients that match code. Supports wildcards and regex. For example:

"ingredientCode": "log-placed-oak-ud"

Example for wildcard:

"ingredientCode": "log-*"

Code (string)

Will be marked as obsolete and renamed to IngredientCodeNew in the future

Changes matched ingredient code to new code. If not set, IngredientCode will be used instead. For example:

"ingredientCode": "log-placed-*-ud"

Name (string)

Changes Name property in matched ingredient to new name.

If not set, typed recipes with output code like "game:table-{wood}" won't work. For example:

"name": "wood"

Attributes (JsonObject)

Applies patch only to ingredient that matches attributes. For example:

"attributes": { "type": "normal-generic" }

AttributesNew (JsonObject)

Changes attributes of matched ingredient. For example:

"attributesNew": { "wood": "purpleheart" }

AllowedVariants (string[])

Sets AllowedVariants of matched ingredient, used in tandem with Name and typed OutputCodeNew. For example:

"allowedVariants": ["acacia", "maple", "pine"]

SkipVariants (string[])

Sets SkipVariants of matched ingredient, used in tandem with Name and typed OutputCodeNew. For example:

"skipVariants": ["oak"]