[docs] Resource expansion

This commit is contained in:
Johannes Frohnmeyer 2022-02-19 16:15:44 +01:00
parent 29d5288707
commit 5a8628532e
Signed by: Johannes
GPG Key ID: E76429612C2929F4
11 changed files with 178 additions and 47 deletions

View File

@ -53,3 +53,8 @@ Corresponds to version 2.7.2 - 2.9.1
- Fabulous shader support
- additional StarScript properties
- OPEN_ROOT support (allows custom icon.pngs among other things)
## v7
Corresponds to version 2.10.0
- Replace StarScript representation of enums

93
docs/ResourceExpansion.md Normal file
View File

@ -0,0 +1,93 @@
# 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>`.
### 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},
"uvlock": ${uvlock}
}
},
{
"when": {
"east": "${orientation}"
},
"apply": {
"model": "minecraft:block/oak_fence_side",
"y": ${y090},
"uvlock": ${uvlock}
}
},
{
"when": {
"south": "${orientation}"
},
"apply": {
"model": "minecraft:block/oak_fence_side",
"y": ${y180},
"uvlock": ${uvlock}
}
},
{
"when": {
"west": "${orientation}"
},
"apply": {
"model": "minecraft:block/oak_fence_side",
"y": ${y270},
"uvlock": ${uvlock}
}
}
]
}
```
## 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

View File

@ -1,6 +0,0 @@
# Old wiki
The pages here are for reference and may include information not present in the updated wiki.
However, the quality of the documentation here is worse.
## Migration status
All documentation except that for resource expansion has been migrated.

View File

@ -1,31 +0,0 @@
# 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).
All values are available in starscript like this: `<pack id>.<entry>`
## Example:
en_us.json.rpo:
```
"expansions": {
"lights": "{lumi.subcategoryTest.enableLang}",
"mode": "{lumi.debugMode}",
"normal": "{lumi.numTest * lumi.subcategoryTest.numberInSub}",
"lumi": "model",
"regeneration": "Industrie"
}
```
en_us.json:
```
{
"rpo.lumi": "${lumi} ${lights}",
"rpo.lumi.tonemap": "Tonemap mode",
"rpo.tooltip.lumi.tonemap": "Tooltip test",
"rpo.lumi.pbr": "Enable PBR",
"rpo.lumi.debugMode": "Debug Mode",
"rpo.lumi.debugMode.normal": "${normal} Mode",
"rpo.lumi.waterVertexWavy": "Wavy water model",
"rpo.tooltip.lumi.subcategoryTest.sliderTest": "Yayyy"
}
```
# Explanation
The expansions block contains a key ("lights") 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

View File

@ -1,10 +1,10 @@
# https://fabricmc.net/develop/
minecraft_version=22w07a
yarn_mappings=build.2
minecraft_version=1.18.2-pre1
yarn_mappings=build.6
loader_version=0.13.2
maven_group=io.gitlab.jfronny
archives_base_name=respackopts
fabric_version=0.47.2+1.18.2
fabric_version=0.47.4+1.18.2
jfapi_version=2.4.0-1645119407
modrinth_id=TiF5QWZY

View File

@ -22,8 +22,5 @@ nav:
- 'Additional':
- 'AdvancedConditions.md'
- 'Shaders.md'
- 'Migrations.md'
- 'Old wiki':
- About: 'old/README.md'
- conditional: 'old/conditional.md'
- expand: 'old/expand.md'
- 'ResourceExpansion.md'
- 'Migrations.md'

View File

@ -0,0 +1,49 @@
{
"multipart": [
{
"apply": {
"model": "minecraft:block/oak_fence_post"
}
},
{
"when": {
"north": "${orientation}"
},
"apply": {
"model": "minecraft:block/oak_fence_side",
"y": ${y000},
"uvlock": ${uvlock}
}
},
{
"when": {
"east": "${orientation}"
},
"apply": {
"model": "minecraft:block/oak_fence_side",
"y": ${y090},
"uvlock": ${uvlock}
}
},
{
"when": {
"south": "${orientation}"
},
"apply": {
"model": "minecraft:block/oak_fence_side",
"y": ${y180},
"uvlock": ${uvlock}
}
},
{
"when": {
"west": "${orientation}"
},
"apply": {
"model": "minecraft:block/oak_fence_side",
"y": ${y270},
"uvlock": ${uvlock}
}
}
]
}

View File

@ -0,0 +1,10 @@
{
"expansions": {
"uvlock": "{lumi.oakFence.uvLock}",
"orientation": "{!lumi.oakFence.invertOrientation}",
"y000": "{lumi.oakFence.yFactor + 0}",
"y090": "{lumi.oakFence.yFactor + 90}",
"y180": "{lumi.oakFence.yFactor + 180}",
"y270": "{lumi.oakFence.yFactor + 270}"
}
}

View File

@ -20,6 +20,11 @@
],
"waterVertexWavy": false,
"numTest": 15.4,
"oakFence": {
"uvLock": true,
"invertOrientation": false,
"yFactor": 0
},
"subcategoryTest": {
"thisIsCool": true,
"numberInSub": 15,

View File

@ -49,7 +49,7 @@ import java.util.concurrent.CompletableFuture;
@Environment(EnvType.CLIENT)
public class Respackopts implements ClientModInitializer {
public static final Integer META_VERSION = 6;
public static final Integer META_VERSION = 7;
public static final String FILE_EXTENSION = ".rpo";
public static final Gson GSON;

View File

@ -6,6 +6,7 @@ import io.gitlab.jfronny.respackopts.util.GuiFactory;
import io.gitlab.jfronny.respackopts.util.IndentingStringBuilder;
import me.shedaniel.clothconfig2.api.AbstractConfigListEntry;
import meteordevelopment.starscript.value.Value;
import meteordevelopment.starscript.value.ValueMap;
import net.minecraft.text.Text;
import java.util.*;
@ -115,7 +116,15 @@ public class ConfigEnumEntry extends ConfigEntry<String> {
@Override
public Value buildStarScript() {
return Value.string(getValue());
String selected = getValue();
if (getVersion() <= 6)
return Value.string(selected);
ValueMap map = new ValueMap();
map.set("value", Value.string(selected));
for (String value : values) {
map.set(value, Value.bool(selected.equals(value)));
}
return Value.map(map);
}
@Override