-
Notifications
You must be signed in to change notification settings - Fork 11
JSON for loop
The for-loop was added to save time in implementing repeat data entries. It allows for creating data templates and injecting keys into templates. In addition to this for-loops can be nested to create complex data trees.
Not all processors or sub processors implement the for-loop. Check each processor's source or wiki entry to see if it is supported.
- Textures
- Models
- Multi-Block Data
- Render States
"processorKey": {
"for": {
"start": 0,
"end": 15,
"dataName": {
"key": "value%number%"
}
}
}This is a simple example of the format for the for-loop. Most of it is self-explanatory with the start being beginning of the loop and end being the last index of the loop. It is important to note that the end is the value of the last run and not the stopping point.
The value of "dataName" changes between each implementation of the for-loop. In most cases it is a short name of the processor key. Inside this area all data that would be normally loaded is setup. However, values can be used as templates by using %number% inside of string values. This will work for values normally requiring numbers in most cases.
From: Power and wires mod's battery cube
"texture:1": {
"for": {
"start": 0,
"end": 15,
"state": {
"key": "powerandwires:battery%number%",
"domain": "powerandwires",
"name": "battery/battery%number%",
"type": "block"
}
}
}This example implements 16 texture loading for a battery box tile. It loops 0 to 15 creating a new texture entry each time form the template. Each entry has its key and name include the index number.
From: ICBM's standard launcher
"multiblock:3": {
"key": "icbm:mediumLauncher",
"tiles": [
{
"for": {
"start": 0,
"end": 18,
"id": "y",
"for": {
"start": -1,
"end": 1,
"id": "x",
"for": {
"start": -1,
"end": 1,
"id": "z",
"multiblock": {
"pos": {
"x": "%x%",
"y": "%y%",
"z": "%z%"
}
}
}
}
}
}
]
}This example generates a multi-block cube structure that is 3x3 wide and 18 blocks tall. It is used as part of the standard launcher's collision box for the missile render.
Looking at the example data it can be seen it uses a more complex setup of the for-loop. This is what is called a nest for-loop in many coding languages. This can mostly be ignored as the example shows, more importantly, the use of naming the for-loop value. Doing this allows for use of all of the for-loops as part of the template injection.