Respackopts/docs/ResourceExpansion.md

99 lines
2.7 KiB
Markdown
Raw Normal View History

2022-02-19 16:15:44 +01:00
# Resource expansion
Sometimes, you may wish to use respackopts values inside your text files (for example as model transforms),
without switching between a bunch of similar files. For this purpose, respackopts allows replacing text in files via resource expansion.
You can use the `expansions` block in your .rpo to replace content with a value computed through executing a custom [μScript](https://gitlab.com/JFronny/java-commons/-/tree/master/muscript) block.
Values can be accessed in the script in a the same exact way as in condition objects,
as the same language and object representation is used, though the result of a script is a string and not a boolean here.
2022-02-19 16:15:44 +01:00
I should probably point out here that, since the result here is always a string,
string concatenation via the `||` operator is possible and recommended.
For example, the following is a valid script: `'Text ' || (someNumber * 15) || someBoolean`
2022-03-17 17:06:15 +01:00
2022-02-19 16:15:44 +01:00
### Example:
conf.json:
```json
{
"id": "examplePack",
"version": 6,
"capabilities": ["FileFilter", "DirFilter"],
"conf": {
"oakFence": {
"uvLock": true,
"invertOrientation": false,
"yFactor": 0
}
}
}
```
oak_fence.json.rpo:
```json
{
"expansions": {
"uvlock": "examplePack.oakFence.uvLock",
"orientation": "!examplePack.oakFence.invertOrientation",
"y000": "examplePack.oakFence.yFactor + 0",
"y090": "examplePack.oakFence.yFactor + 90",
"y180": "examplePack.oakFence.yFactor + 180",
"y270": "examplePack.oakFence.yFactor + 270"
2022-02-19 16:15:44 +01:00
}
}
```
oak_fence.json:
```json
{
"multipart": [
{
"apply": {
"model": "minecraft:block/oak_fence_post"
}
},
{
"when": {
"north": "${orientation}"
},
"apply": {
"model": "minecraft:block/oak_fence_side",
"y": ${y000},
2022-03-17 17:06:15 +01:00
"uvlock": ${uvlock}
}
},
2022-02-19 16:15:44 +01:00
{
"when": {
"east": "${orientation}"
},
"apply": {
"model": "minecraft:block/oak_fence_side",
"y": ${y090},
2022-03-17 17:06:15 +01:00
"uvlock": ${uvlock}
}
},
2022-02-19 16:15:44 +01:00
{
"when": {
"south": "${orientation}"
},
"apply": {
"model": "minecraft:block/oak_fence_side",
"y": ${y180},
2022-03-17 17:06:15 +01:00
"uvlock": ${uvlock}
}
},
2022-02-19 16:15:44 +01:00
{
"when": {
"west": "${orientation}"
},
"apply": {
"model": "minecraft:block/oak_fence_side",
"y": ${y270},
2022-03-17 17:06:15 +01:00
"uvlock": ${uvlock}
}
}
2022-02-19 16:15:44 +01:00
]
}
```
## Explanation
The expansions block contains a key ("uvlock") and a script, which is executed when the file is loaded.
All instances of the key (formatted as ${name} -> ${lights} in this example) will be replaced by the result of the script.
Make sure to only use this feature on text files as unexpected results my occur otherwise