aboutsummaryrefslogtreecommitdiff
path: root/codegen
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-06-21 19:48:01 -0500
committermat <github@matdoes.dev>2022-06-21 19:48:01 -0500
commit392c553d5688f3d5ad19c4a861c0239c914e3578 (patch)
tree2d2a10c01b2d60c7bc3f609ff7525de4d3ecc13f /codegen
parentaf7a7b428c60021e1ef717dd7dc3888c21188693 (diff)
downloadazalea-drasl-392c553d5688f3d5ad19c4a861c0239c914e3578.tar.xz
Force the generator mod to support snapshots
Diffstat (limited to 'codegen')
-rw-r--r--codegen/lib/download.py25
-rw-r--r--codegen/lib/extract.py14
2 files changed, 36 insertions, 3 deletions
diff --git a/codegen/lib/download.py b/codegen/lib/download.py
index e9712f8d..db21145c 100644
--- a/codegen/lib/download.py
+++ b/codegen/lib/download.py
@@ -1,4 +1,5 @@
from lib.utils import get_dir_location
+import xml.etree.ElementTree as ET
from .mappings import Mappings
import requests
import json
@@ -118,11 +119,33 @@ def get_yarn_data(version_id: str):
return version
+def get_fabric_api_versions():
+ # https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/maven-metadata.xml
+ if not os.path.exists(get_dir_location('downloads/fabric_api_versions.json')):
+ print('\033[92mDownloading Fabric API versions...\033[m')
+ fabric_api_versions_xml_text = requests.get(
+ 'https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/maven-metadata.xml').text
+ # parse xml
+ fabric_api_versions_data_xml = ET.fromstring(
+ fabric_api_versions_xml_text)
+ fabric_api_versions = []
+ for version_el in fabric_api_versions_data_xml.find('versioning').find('versions').findall('version'):
+ fabric_api_versions.append(version_el.text)
+
+ with open(get_dir_location('downloads/fabric_api_versions.json'), 'w') as f:
+ f.write(json.dumps(fabric_api_versions))
+ else:
+ with open(get_dir_location('downloads/fabric_api_versions.json'), 'r') as f:
+ fabric_api_versions = json.loads(f.read())
+ return fabric_api_versions
+
+
def clear_version_cache():
print('\033[92mClearing version cache...\033[m')
files = [
'version_manifest.json',
- 'yarn_versions.json'
+ 'yarn_versions.json',
+ 'fabric_api_versions.json'
]
for file in files:
if os.path.exists(get_dir_location(f'downloads/{file}')):
diff --git a/codegen/lib/extract.py b/codegen/lib/extract.py
index 893b8d5c..4c2d2399 100644
--- a/codegen/lib/extract.py
+++ b/codegen/lib/extract.py
@@ -1,6 +1,6 @@
# Extracting data from the Minecraft jars
-from lib.download import get_server_jar, get_burger, get_client_jar, get_generator_mod, get_yarn_data
+from lib.download import get_server_jar, get_burger, get_client_jar, get_generator_mod, get_yarn_data, get_fabric_api_versions
from lib.utils import get_dir_location
import json
import os
@@ -61,7 +61,9 @@ def get_generator_mod_data(version_id: str, category: str):
# looks like 1.19+build.1
yarn_version = yarn_data['version']
- # the mod has the minecraft version hard-coded by default, so we just change the gradle.properties
+ fabric_api_version = get_fabric_api_versions()[-1]
+
+ # the mod has the minecraft version hard-coded by default, so we just change the gradle.properties and fabric.mod.json
with open(get_dir_location(f'{generator_mod_dir}/gradle.properties'), 'r') as f:
lines = f.readlines()
with open(get_dir_location(f'{generator_mod_dir}/gradle.properties'), 'w') as f:
@@ -70,7 +72,15 @@ def get_generator_mod_data(version_id: str, category: str):
line = f'minecraft_version={version_id}\n'
if line.startswith('yarn_mappings='):
line = f'yarn_mappings={yarn_version}\n'
+ if line.startswith('fabric_version='):
+ line = f'fabric_version={fabric_api_version}\n'
f.write(line)
+ # edit the fabric.mod.json to support this version
+ with open(get_dir_location(f'{generator_mod_dir}/src/main/resources/fabric.mod.json'), 'r') as f:
+ fabric_mod_json = json.load(f)
+ fabric_mod_json['depends']['minecraft'] = '*'
+ with open(get_dir_location(f'{generator_mod_dir}/src/main/resources/fabric.mod.json'), 'w') as f:
+ json.dump(fabric_mod_json, f, indent=2)
os.system(
f'cd {generator_mod_dir} && gradlew runServer'