1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

Force the generator mod to support snapshots

This commit is contained in:
mat 2022-06-21 19:48:01 -05:00
parent af7a7b428c
commit 392c553d56
2 changed files with 36 additions and 3 deletions

View file

@ -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}')):

View file

@ -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'