Skip to content

Paste Operation

EnderTurret edited this page Nov 7, 2024 · 2 revisions

Not to be confused with copy, the paste patch type allows placing code-defined elements in a json file. It's mainly intended for mods to use. It was added in version 7.3.0+1.21.1 and 3.4.0+1.20.1.

A paste patch looks like this:

{
  "op": "paste", // specifies this is a paste patch
  "type": "mod:data_source_type", // the data source to query
  "path": "/path/to/destination", // the location to put the element given by the data source
  "from": "/path/to/input/element", // optional, allows passing an input element to the data source
  "value": "some input value" // optional, allows passing an input value to the data source
}

The primary purpose of paste is to allow getting configuration values into difficult places, such as biomes. Suppose for example that you want to add a configuration option to adjust the frequency of a structure, so that modpack developers (or players) can easily make the structure rarer without resorting to custom data packs. Ordinarily this is rather difficult since structures are data-driven and therefore code cannot easily modify them. However, one could create a data source to expose the value:

// somewhere in CommonSetup or ModInitializer or whatever
Patched.registerDataSource(id("config_value"), (from, value) -> {
	switch (value.getAsString()) {
		case "dungeon_frequency" -> MyConfig.getDungeonFrequency();
	}
});

And now you write the patch:

// dungeon.json.patch
{
  "op": "paste",
  "type": "mymod:config_value",
  "path": "/placement/frequency",
  "value": "dungeon_frequency"
}

Clone this wiki locally