Respackopts/docs/ResourceExpansion.md

96 lines
2.5 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 [StarScript](https://github.com/MeteorDevelopment/starscript/wiki).
Values can be accessed in star script in a similar way to normal condition objects: `<pack id>.<entry>` or `<pack id>.<subcategory>.<entry>`.
2022-03-17 17:06:15 +01:00
The string value of an enum can be accessed via `<pack id>.<entry>.value`
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}"
}
}
```
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