-
Notifications
You must be signed in to change notification settings - Fork 1
Find Operation
The find patch type allows applying a patch to all elements matching a filter. It's useful when you don't know exactly where an element that you want to remove is, or when you want to modify many elements at once.
A find patch looks like this:
{
"op": "find", // specifies this is a find patch
"path": "/path/to/root", // the path to the element to search
"multi": true, // whether to continue searching after the first match, optional and defaults to false
"test": [], // a list of one or more test patches. The operation may be omitted from them
"then": [] // a list of one or more patches. These are applied when a match is found
}For example, suppose you're adding sticks for each wood type, and want to make it possible to use them for crafting. (Pretend for a moment that mod loaders don't already provide a tag for this purpose.) While you could painstakingly write a patch for every recipe that uses them, you could also just use a find patch, like so:
// replace_sticks.json.patch
{
"op": "find",
"path": "/key",
"multi": true,
"test": [
{
"path": "/item"
"value": "minecraft:stick"
}
],
"then": [
{
"op": "replace",
"path": "", // an empty path identifies the current element; a forward slash is ambiguous because it could refer to this element: { "": <value> }
"value": {
"tag": "stickvariaties:sticks"
}
}
]
}Currently this patch will work with one file, and while we could duplicate it for all 300-some recipes, or use an include wrapper patch, we could alternatively leverage Patched's 'dynamic patching' system:
// pack.mcmeta
{
"patched": {
"format_version": <current format version>,
"patch_targets": [
{ // defines a patch target, or so-called dynamic patch
"pack_type": "server_data", // this applies to server-side data, important as data packs can be packaged as mods
"patch": "replace_sticks", // the patch to apply, in this case our stick replacement patch
"targets": [
{ // defines a set of matching rules
"namespace": [ "minecraft" ], // only apply this patch to the minecraft namespace
"path": [
// only apply this patch to files matching this regular expression, in this case files in the recipe folder that end in .json
{ "pattern": "recipe/.+\\.json" }
]
}
]
}
]
}
}With this dynamic patch, the stick replacement patch will now apply to every recipe in the minecraft namespace, and now you should be able to see the power behind this patch type — combined with dynamic patching, it allows you to modify all recipes/biomes/whatever and change them based on a pattern. While this example covered changing out sticks for something else, one could easily use the same logic to bulk remove/replace biomes' features or loot table entries.