-
Notifications
You must be signed in to change notification settings - Fork 0
dpconfig methods
A method describes what value in the data pack to modify, how, and where to find it. It takes input from a dpconfig widget, and then uses that to change a value somewhere in the data pack.
A method is an object made up of a transformer and accessors.
A transformer transforms the input into a different, final value. If the users inputs, say, 1, i.e. "True", we can change that to, say, 76 - that's what a transformer does.
A transformer argument can either be an integer, a float, a string, or a function object.
Use either "$input" or "$in" for method input.
Use "$slot_name" to get the value of a slot, $ being a prefix to the slot name.
Anything else will be taken literally, i.e. "owo" will be "owo".
Function objects need a type key describing the function name. Here's the list of supported functions and the arguments they require:
Compares argument and argument1 together.
Uses the key operator as the comparison operator. Value can be either "==" (full equality), ">" (more than) or ">=".
If the result is true, outputs value in key true. If false, outputs value in key false.
Rounds and converts argument into an integer.
Adds argument and argument1 together.
Multiplies argument by argument1.
Returns the argument squared.
Returns the square root of argument.
This transformer looks at whether the user input is equal to 2 when rounded, then outputs a string dependent on the result.
"transformer": {
"function": "if_else",
"operator": "==",
"argument": {
"function": "int",
"argument": "input"
},
"argument1": 2,
"true": "it is two!!!!!!!!!!!",
"false": "it is not two :("
},
An accessor describes how to change a value in a particular file - it accesses the value. A method may have multiple accessors if it needs to change multiple different values in either one file or many.
An accessor is described by the following settings:
A value transformer. Not required - if present in an accessor, overwrites the method-wide transformer for this accessor.
Describes the way the value should be modified by the input.
Must be one of the following things:
-
multiplymultiplies the original value by the input -
dividedivides the original value by the input -
addadds the input to the original value -
subtractsubtracts the input from the original value -
setoverwrites the value with the input -
multiply_int- multiplies the original value by the input, then converts to an integer -
divide_int- does a full division, then converts to an integer -
add_int- adds, then converts to an integer -
subtract_int- subtracts, then converts to an integer -
remove- removes a value from an array -
pop- removes an index from an array
⚠ 0 is the index of the first member of a list/array, not 1.
Either a single string or a list of strings describing the file path(s).
All files whose paths end in the described file_path will match and be edited.
For an exact match, add ./ to the beginning of the path string.
For example, data/foo/bar/my_file.json is acceptable as a file path.
It will match files whose paths look like this: data/foo/bar/my_file.json AND this: overlay/data/foo/bar/my_file.json.
If ./overlay/data/foo/bar/my_file.json is used as a file path, only this one file will match.
my_file.json is also acceptable, but it will match every file named this way, which is potentially risky.
my_file is not acceptable as a file path.
The path to the key in the JSON file whose value we're trying to change. The forward slash (/) is used as the dividing character.
For the sky color in a biome file it would look like this: effects/sky_color
If there's a list/array in the way, use an integer describing the index of the element. In a placed feature file it might look like this: placement/3/max_water_depth.
⚠ 0 is the index of the first member of a list/array, not 1.
Here is an example method:
"test_method": {
"transformer": {
"function": "if_else",
"operator": "==",
"argument": {
"function": "int",
"argument": "input"
},
"argument1": 2,
"true": "it is two!!!!!!!!!!!",
"false": "it is not two :("
},
"accessors": [
{
"method": "set",
"file_path": "data/my_datapack/test_file.json",
"value_path": "my_string"
}
]
}