summaryrefslogtreecommitdiff
path: root/docs/handbook/meta/fabric-metadata.md
blob: 070fb9334de7839cc929df6faee09d953a13228f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# Meta — Fabric Metadata

## Overview

Fabric is a lightweight modding toolchain with a simpler metadata structure than Forge. Fabric has two components that Meta tracks:

1. **Fabric Loader** — the mod loading framework itself
2. **Intermediary Mappings** — obfuscation mappings that allow mods to work across Minecraft versions

The processing is straightforward compared to Forge because Fabric publishes structured JSON metadata directly, with no need to download and extract installer JARs.

---

## Phase 1: Update — `update_fabric.py`

### Fetching Component Metadata

Fabric Meta v2 exposes version lists at:

```python
for component in ["intermediary", "loader"]:
    index = get_json_file(
        os.path.join(UPSTREAM_DIR, META_DIR, f"{component}.json"),
        "https://meta.fabricmc.net/v2/versions/" + component,
    )
```

This fetches two files:
- `upstream/fabric/meta-v2/loader.json` — list of loader versions
- `upstream/fabric/meta-v2/intermediary.json` — list of intermediary mappings

Each entry contains:
```json
{
    "separator": ".",
    "build": 1,
    "maven": "net.fabricmc:fabric-loader:0.16.9",
    "version": "0.16.9",
    "stable": true
}
```

### JAR Timestamp Extraction

For each loader and intermediary version, the updater determines the release timestamp. It tries an efficient HTTP HEAD first, falling back to downloading the JAR:

```python
def compute_jar_file(path, url):
    try:
        headers = head_file(url)
        tstamp = datetime.strptime(headers["Last-Modified"], DATETIME_FORMAT_HTTP)
    except requests.HTTPError:
        print(f"Falling back to downloading jar for {url}")
        jar_path = path + ".jar"
        get_binary_file(jar_path, url)
        tstamp = datetime.fromtimestamp(0)
        with zipfile.ZipFile(jar_path) as jar:
            allinfo = jar.infolist()
            for info in allinfo:
                tstamp_new = datetime(*info.date_time)
                if tstamp_new > tstamp:
                    tstamp = tstamp_new

    data = FabricJarInfo(release_time=tstamp)
    data.write(path + ".json")
```

The `DATETIME_FORMAT_HTTP` is `"%a, %d %b %Y %H:%M:%S %Z"`.

The result is saved as a `FabricJarInfo` JSON:

```python
class FabricJarInfo(MetaBase):
    release_time: Optional[datetime] = Field(alias="releaseTime")
```

### Loader Installer JSON

For each loader version, the updater downloads the installer JSON from Fabric's Maven:

```python
def get_json_file_concurrent(it):
    maven_url = get_maven_url(it["maven"], "https://maven.fabricmc.net/", ".json")
    get_json_file(
        os.path.join(UPSTREAM_DIR, INSTALLER_INFO_DIR, f"{it['version']}.json"),
        maven_url,
    )
```

The `get_maven_url()` function constructs Maven repository URLs:

```python
def get_maven_url(maven_key, server, ext):
    parts = maven_key.split(":", 3)
    maven_ver_url = (
        server + parts[0].replace(".", "/") + "/" + parts[1] + "/" + parts[2] + "/"
    )
    maven_url = maven_ver_url + parts[1] + "-" + parts[2] + ext
    return maven_url
```

For `net.fabricmc:fabric-loader:0.16.9`, this produces:
`https://maven.fabricmc.net/net/fabricmc/fabric-loader/0.16.9/fabric-loader-0.16.9.json`

### Concurrency

The Fabric updater uniquely uses `multiprocessing.Pool` (not `ThreadPoolExecutor`):

```python
with Pool(None) as pool:
    deque(pool.imap_unordered(compute_jar_file_concurrent, index, 32), 0)
```

The `deque(..., 0)` pattern consumes the iterator without storing results, purely for side effects.

---

## Phase 2: Generate — `generate_fabric.py`

### Processing Loader Versions

```python
def process_loader_version(entry) -> MetaVersion:
    jar_info = load_jar_info(transform_maven_key(entry["maven"]))
    installer_info = load_installer_info(entry["version"])

    v = MetaVersion(
        name="Fabric Loader",
        uid="net.fabricmc.fabric-loader",
        version=entry["version"]
    )
    v.release_time = jar_info.release_time
    v.requires = [Dependency(uid="net.fabricmc.intermediary")]
    v.order = 10
    v.type = "release"
```

#### Main Class Resolution

The loader installer info may specify the main class as either a string or a `FabricMainClasses` object:

```python
if isinstance(installer_info.main_class, FabricMainClasses):
    v.main_class = installer_info.main_class.client
else:
    v.main_class = installer_info.main_class
```

The `FabricMainClasses` model:
```python
class FabricMainClasses(MetaBase):
    client: Optional[str]
    common: Optional[str]
    server: Optional[str]
```

#### Library Assembly

Loader libraries come from the installer's `common` and `client` sections, plus the loader itself:

```python
v.libraries = []
v.libraries.extend(installer_info.libraries.common)
v.libraries.extend(installer_info.libraries.client)
loader_lib = Library(
    name=GradleSpecifier.from_string(entry["maven"]),
    url="https://maven.fabricmc.net",
)
v.libraries.append(loader_lib)
```

### Processing Intermediary Versions

```python
def process_intermediary_version(entry) -> MetaVersion:
    jar_info = load_jar_info(transform_maven_key(entry["maven"]))

    v = MetaVersion(
        name="Intermediary Mappings",
        uid="net.fabricmc.intermediary",
        version=entry["version"],
    )
    v.release_time = jar_info.release_time
    v.requires = [Dependency(uid="net.minecraft", equals=entry["version"])]
    v.order = 11
    v.type = "release"
    v.volatile = True
    intermediary_lib = Library(
        name=GradleSpecifier.from_string(entry["maven"]),
        url="https://maven.fabricmc.net",
    )
    v.libraries = [intermediary_lib]
    return v
```

Key points:
- Intermediary mappings are `volatile=True` — they may change between runs.
- The `version` matches the Minecraft version (e.g., `1.21.5`).
- The `requires` field pins the intermediary to an exact Minecraft version via `equals`.

### Recommended Versions

Fabric Meta has a `stable` field in its loader index. The **first** stable loader version is recommended:

```python
for entry in loader_version_index:
    v = process_loader_version(entry)
    if not recommended_loader_versions and entry["stable"]:
        recommended_loader_versions.append(version)
```

All intermediary versions are recommended (since each maps to exactly one Minecraft version).

### Package Metadata

```python
package = MetaPackage(uid=LOADER_COMPONENT, name="Fabric Loader")
package.recommended = recommended_loader_versions
package.description = "Fabric Loader is a tool to load Fabric-compatible mods in game environments."
package.project_url = "https://fabricmc.net"
package.authors = ["Fabric Developers"]

package = MetaPackage(uid=INTERMEDIARY_COMPONENT, name="Intermediary Mappings")
package.recommended = recommended_intermediary_versions
package.description = "Intermediary mappings allow using Fabric Loader with mods for Minecraft in a more compatible manner."
package.project_url = "https://fabricmc.net"
package.authors = ["Fabric Developers"]
```

---

## Data Models

### `FabricInstallerDataV1`

The installer JSON from Fabric's Maven:

```python
class FabricInstallerDataV1(MetaBase):
    version: int
    libraries: FabricInstallerLibraries
    main_class: Optional[Union[str, FabricMainClasses]]
    arguments: Optional[FabricInstallerArguments]
    launchwrapper: Optional[FabricInstallerLaunchwrapper]

class FabricInstallerLibraries(MetaBase):
    client: Optional[List[Library]]
    common: Optional[List[Library]]
    server: Optional[List[Library]]

class FabricInstallerArguments(MetaBase):
    client: Optional[List[str]]
    common: Optional[List[str]]
    server: Optional[List[str]]
```

### `FabricJarInfo`

```python
class FabricJarInfo(MetaBase):
    release_time: Optional[datetime] = Field(alias="releaseTime")
```

---

## Constants

| Constant | Value | Location |
|---|---|---|
| `LOADER_COMPONENT` | `"net.fabricmc.fabric-loader"` | `common/fabric.py` |
| `INTERMEDIARY_COMPONENT` | `"net.fabricmc.intermediary"` | `common/fabric.py` |
| `BASE_DIR` | `"fabric"` | `common/fabric.py` |
| `META_DIR` | `"fabric/meta-v2"` | `common/fabric.py` |
| `INSTALLER_INFO_DIR` | `"fabric/loader-installer-json"` | `common/fabric.py` |
| `JARS_DIR` | `"fabric/jars"` | `common/fabric.py` |
| `DATETIME_FORMAT_HTTP` | `"%a, %d %b %Y %H:%M:%S %Z"` | `common/fabric.py` |

---

## Component Dependency Chain

```
org.quiltmc.quilt-loader ──► net.fabricmc.intermediary ──► net.minecraft
net.fabricmc.fabric-loader ──► net.fabricmc.intermediary ──► net.minecraft
```

Fabric Loader requires Intermediary Mappings, which require a specific Minecraft version.

---

## Output Structure

```
launcher/
├── net.fabricmc.fabric-loader/
│   ├── package.json
│   ├── 0.16.9.json
│   ├── 0.16.8.json
│   └── ...
└── net.fabricmc.intermediary/
    ├── package.json
    ├── 1.21.5.json
    ├── 1.20.4.json
    └── ...
```

---

## Upstream Data Structure

```
upstream/fabric/
├── meta-v2/
│   ├── loader.json          # Full loader version index
│   └── intermediary.json    # Full intermediary version index
├── loader-installer-json/
│   ├── 0.16.9.json          # Installer JSON per loader version
│   └── ...
└── jars/
    ├── net.fabricmc.fabric-loader.0.16.9.json  # JAR timestamp info
    ├── net.fabricmc.intermediary.1.21.5.json
    └── ...
```