summaryrefslogtreecommitdiff
path: root/docs/handbook/meta/neoforge-metadata.md
blob: 63a45c36bbbd35c8f83ee7b6c5ad035f6d897e4e (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
324
325
326
327
328
329
330
331
332
333
334
# Meta — NeoForge Metadata

## Overview

NeoForge is a fork of Forge that emerged in 2023. Its metadata pipeline closely mirrors Forge's, but with key differences in version numbering and Maven repository structure. NeoForge exclusively uses the build-system installer format (equivalent to Forge's v2 installer profile), so there are no legacy paths to handle.

---

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

### Fetching Version Lists

NeoForge publishes versions under two Maven artifacts:

```python
# Legacy artifact (1.20.1 era, when NeoForge still used Forge's naming)
r = sess.get(
    "https://maven.neoforged.net/api/maven/versions/releases/net%2Fneoforged%2Fforge"
)
main_json = r.json()["versions"]

# New artifact (post-1.20.1, NeoForge's own naming)
r = sess.get(
    "https://maven.neoforged.net/api/maven/versions/releases/net%2Fneoforged%2Fneoforge"
)
new_main_json = r.json()["versions"]

main_json += new_main_json  # Merge both lists
```

### Version Parsing

Two regex patterns handle the two naming schemes:

```python
# Legacy format: "1.20.1-47.1.100"
version_expression = re.compile(
    r"^(?P<mc>[0-9a-zA-Z_\.]+)-(?P<ver>[0-9\.]+\.(?P<build>[0-9]+))(-(?P<branch>[a-zA-Z0-9\.]+))?$"
)

# New NeoForge format: "20.4.237" or "21.0.0-beta"
neoforge_version_re = re.compile(
    r"^(?P<mcminor>\d+)\.(?:(?P<mcpatch>\d+)|(?P<snapshot>[0-9a-z]+))\.(?P<number>\d+)(?:\.(?P<build>\d+))?(?:-(?P<tag>[0-9A-Za-z][0-9A-Za-z.+-]*))?$"
)
```

For the new format, the Minecraft version is reconstructed from the NeoForge version number:

```python
if match_nf:
    mc_version = match_nf.group("snapshot")
    if not mc_version:
        mc_version = f"1.{match_nf.group('mcminor')}"
        if match_nf.group("mcpatch") != "0":
            mc_version += f".{match_nf.group('mcpatch')}"
    artifact = "neoforge"
```

### File Manifest from Maven API

Unlike Forge which uses its own `meta.json`, NeoForge file manifests come from the Maven API:

```python
def get_single_forge_files_manifest(longversion, artifact: str):
    file_url = (
        f"https://maven.neoforged.net/api/maven/details/releases/net%2Fneoforged%2F{artifact}%2F"
        + urllib.parse.quote(longversion)
    )
    r = sess.get(file_url)
    files_json = r.json()

    for file in files_json.get("files"):
        name = file["name"]
        prefix = f"{artifact}-{longversion}"
        file_name = name[len(prefix):]
        if file_name.startswith("."):
            continue  # Skip top-level extension files
        classifier, ext = os.path.splitext(file_name)
        if ext in [".md5", ".sha1", ".sha256", ".sha512"]:
            continue  # Skip checksum files

        file_obj = NeoForgeFile(
            artifact=artifact, classifier=classifier, extension=ext[1:]
        )
        ret_dict[classifier] = file_obj
```

### NeoForgeFile Model

```python
class NeoForgeFile(MetaBase):
    artifact: str       # "forge" or "neoforge"
    classifier: str     # "installer", "universal"
    extension: str      # "jar"

    def filename(self, long_version):
        return "%s-%s-%s.%s" % (
            self.artifact, long_version, self.classifier, self.extension,
        )

    def url(self, long_version):
        return "https://maven.neoforged.net/releases/net/neoforged/%s/%s/%s" % (
            self.artifact, long_version, self.filename(long_version),
        )
```

### Installer Processing

The processing is virtually identical to Forge:

```python
def process_neoforge_version(key, entry):
    version = NeoForgeVersion(entry)
    if version.url() is None or not version.uses_installer():
        return

    jar_path = os.path.join(UPSTREAM_DIR, JARS_DIR, version.filename())

    # SHA-1 verification, download, extract version.json and install_profile.json
    with zipfile.ZipFile(jar_path) as jar:
        with jar.open("version.json") as profile_zip_entry:
            MojangVersion.parse_raw(version_data)
        with jar.open("install_profile.json") as profile_zip_entry:
            NeoForgeInstallerProfileV2.parse_raw(install_profile_data)

    # Cache installer info
    installer_info = InstallerInfo()
    installer_info.sha1hash = file_hash(jar_path, hashlib.sha1)
    installer_info.sha256hash = file_hash(jar_path, hashlib.sha256)
    installer_info.size = os.path.getsize(jar_path)
    installer_info.write(installer_info_path)
```

---

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

### Single Generation Path

Unlike Forge (which has three paths), NeoForge only uses the build-system installer path:

```python
def version_from_build_system_installer(
    installer: MojangVersion,
    profile: NeoForgeInstallerProfileV2,
    version: NeoForgeVersion,
) -> MetaVersion:
    v = MetaVersion(name="NeoForge", version=version.rawVersion, uid=NEOFORGE_COMPONENT)
    v.main_class = "io.github.zekerzhayard.forgewrapper.installer.Main"
```

### Library Handling

Profile libraries go into `maven_files` (install-time downloads), and installer libraries plus ForgeWrapper go into `libraries` (runtime classpath):

```python
    v.maven_files = []

    # Installer JAR as Maven file
    installer_lib = Library(
        name=GradleSpecifier("net.neoforged", version.artifact, version.long_version, "installer")
    )
    installer_lib.downloads = MojangLibraryDownloads()
    installer_lib.downloads.artifact = MojangArtifact(
        url="https://maven.neoforged.net/releases/%s" % installer_lib.name.path(),
        sha1=info.sha1hash, size=info.size,
    )
    v.maven_files.append(installer_lib)

    # Profile libraries (processor dependencies)
    for forge_lib in profile.libraries:
        if forge_lib.name.is_log4j():
            continue
        update_library_info(forge_lib)
        v.maven_files.append(forge_lib)

    # Runtime libraries
    v.libraries = [FORGEWRAPPER_LIBRARY]
    for forge_lib in installer.libraries:
        if forge_lib.name.is_log4j():
            continue
        v.libraries.append(forge_lib)
```

### Library Info Fetching

Same approach as Forge — fills in missing SHA-1 and size from Maven:

```python
def update_library_info(lib: Library):
    if not lib.downloads:
        lib.downloads = MojangLibraryDownloads()
    if not lib.downloads.artifact:
        url = lib.url or f"https://maven.neoforged.net/releases/{lib.name.path()}"
        lib.downloads.artifact = MojangArtifact(url=url, sha1=None, size=None)

    art = lib.downloads.artifact
    if art and art.url:
        if not art.sha1:
            r = sess.get(art.url + ".sha1")
            if r.status_code == 200:
                art.sha1 = r.text.strip()
        if not art.size:
            r = sess.head(art.url)
            if r.status_code == 200 and 'Content-Length' in r.headers:
                art.size = int(r.headers['Content-Length'])
```

### Minecraft Version Dependency

NeoForge extracts the Minecraft version from the installer profile's `minecraft` field:

```python
v.requires = [Dependency(uid=MINECRAFT_COMPONENT, equals=profile.minecraft)]

# Skip if we don't have the corresponding Minecraft version
if not os.path.isfile(
    os.path.join(LAUNCHER_DIR, MINECRAFT_COMPONENT, f"{profile.minecraft}.json")
):
    eprint("Skipping %s with no corresponding Minecraft version %s" % (key, profile.minecraft))
    continue
```

### Argument Construction

```python
mc_args = (
    "--username ${auth_player_name} --version ${version_name} --gameDir ${game_directory} "
    "--assetsDir ${assets_root} --assetIndex ${assets_index_name} --uuid ${auth_uuid} "
    "--accessToken ${auth_access_token} --userType ${user_type} --versionType ${version_type}"
)
for arg in installer.arguments.game:
    mc_args += f" {arg}"
v.minecraft_arguments = mc_args
```

---

## Data Models

### `NeoForgeEntry`

```python
class NeoForgeEntry(MetaBase):
    artifact: str           # "forge" or "neoforge"
    long_version: str       # "1.20.1-47.1.100" or "20.4.237"
    version: str            # Short version: "47.1.100" or "237"
    latest: Optional[bool]
    recommended: Optional[bool]
    files: Optional[Dict[str, NeoForgeFile]]
```

### `DerivedNeoForgeIndex`

```python
class DerivedNeoForgeIndex(MetaBase):
    versions: Dict[str, NeoForgeEntry]
```

Note: Unlike Forge's `DerivedForgeIndex`, this does not have a `by_mc_version` mapping.

### `NeoForgeVersion`

Post-processed version with resolved download URLs:

```python
class NeoForgeVersion:
    def __init__(self, entry: NeoForgeEntry):
        self.artifact = entry.artifact
        self.rawVersion = entry.version
        if self.artifact == "neoforge":
            self.rawVersion = entry.long_version

        self.long_version = entry.long_version
        for classifier, file in entry.files.items():
            if classifier == "installer" and extension == "jar":
                self.installer_filename = filename
                self.installer_url = url
```

### `NeoForgeInstallerProfileV2`

Same structure as Forge's v2 profile:

```python
class NeoForgeInstallerProfileV2(MetaBase):
    spec: Optional[int]
    profile: Optional[str]
    version: Optional[str]
    path: Optional[GradleSpecifier]
    minecraft: Optional[str]
    data: Optional[Dict[str, DataSpec]]
    processors: Optional[List[ProcessorSpec]]
    libraries: Optional[List[Library]]
```

---

## Key Differences from Forge

| Aspect | Forge | NeoForge |
|---|---|---|
| Maven URL | `maven.minecraftforge.net` | `maven.neoforged.net/releases` |
| File manifest API | `meta.json` per version | Maven details API |
| Artifacts | Always `forge` | `forge` (1.20.1) or `neoforge` (1.20.2+) |
| Version format | `<mc>-<forge_ver>` | `<mc>-<forge_ver>` or `<mcminor>.<mcpatch>.<build>` |
| Legacy support | Yes (MC 1.1–1.12.2) | No (MC 1.20.1+ only) |
| Component UID | `net.minecraftforge` | `net.neoforged` |
| Bad versions list | Yes | No |
| ForgeWrapper | Yes | Yes (same library) |
| Promotions/recommended | Yes | Not currently (`is_recommended = False`) |

---

## Output Structure

```
launcher/net.neoforged/
├── package.json
├── 21.4.38.json         # New NeoForge format
├── 20.4.237.json        # New NeoForge format
├── 47.1.100.json        # Legacy Forge-style format (1.20.1)
└── ...
```

---

## Constants

| Constant | Value | Location |
|---|---|---|
| `NEOFORGE_COMPONENT` | `"net.neoforged"` | `common/neoforge.py` |
| `BASE_DIR` | `"neoforge"` | `common/neoforge.py` |
| `FORGEWRAPPER_LIBRARY` | (shared with Forge) | `common/forge.py` |