mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
Add get_generator_mod_data
Uses u9g's mod: https://github.com/u9g/minecraft-data-generator-server
This commit is contained in:
parent
405a00c0d1
commit
107f945a23
4 changed files with 94 additions and 11 deletions
|
@ -10,14 +10,16 @@ import os
|
|||
|
||||
version_id = lib.code.version.get_version_id()
|
||||
|
||||
lib.download.get_burger()
|
||||
lib.download.get_client_jar(version_id)
|
||||
lib.extract.get_generator_mod_data(version_id, 'blockCollisionShapes')
|
||||
|
||||
print('Generating data with burger')
|
||||
os.system(
|
||||
f'cd {lib.utils.get_dir_location("downloads/Burger")} && python munch.py ../client-{version_id}.jar --output ../burger-{version_id}.json --toppings blockstates'
|
||||
)
|
||||
print('Ok')
|
||||
# lib.download.get_burger()
|
||||
# lib.download.get_client_jar(version_id)
|
||||
|
||||
# print('Generating data with burger')
|
||||
# os.system(
|
||||
# f'cd {lib.utils.get_dir_location("downloads/Burger")} && python munch.py ../client-{version_id}.jar --output ../burger-{version_id}.json --toppings blockstates'
|
||||
# )
|
||||
# print('Ok')
|
||||
|
||||
mappings = lib.download.get_mappings_for_version(version_id)
|
||||
block_states_burger = lib.extract.get_block_states_burger(version_id)
|
||||
|
|
|
@ -43,7 +43,7 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, ordered_blocks: li
|
|||
|
||||
if property is None:
|
||||
return ''.join(map(to_camel_case, property_variants))
|
||||
|
||||
|
||||
property_name = None
|
||||
for class_name in [block_data_burger['class']] + block_data_burger['super']:
|
||||
property_name = mappings.get_field(
|
||||
|
@ -103,7 +103,7 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, ordered_blocks: li
|
|||
ending = property_name.split('_')[-1]
|
||||
if ending.isdigit():
|
||||
property_name = property_name[:-(len(ending) + 1)]
|
||||
|
||||
|
||||
# `type` is a reserved keyword, so we use kind instead ¯\_(ツ)_/¯
|
||||
if property_name == 'type':
|
||||
property_name = 'kind'
|
||||
|
@ -180,6 +180,8 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, ordered_blocks: li
|
|||
if in_macro:
|
||||
continue
|
||||
new_code.append(line)
|
||||
# empty line at the end
|
||||
new_code.append('')
|
||||
|
||||
with open(BLOCKS_RS_DIR, 'w') as f:
|
||||
f.write('\n'.join(new_code))
|
||||
|
|
|
@ -19,12 +19,20 @@ def get_burger():
|
|||
os.system('cd downloads/Burger && pip install six jawa')
|
||||
|
||||
|
||||
def get_generator_mod():
|
||||
if not os.path.exists(get_dir_location('downloads/minecraft-data-generator-server')):
|
||||
print('\033[92mDownloading u9g/minecraft-data-generator-server...\033[m')
|
||||
os.system(
|
||||
f'cd {get_dir_location("downloads")} && git clone https://github.com/u9g/minecraft-data-generator-server && cd minecraft-data-generator-server && git pull')
|
||||
return get_dir_location('downloads/minecraft-data-generator-server')
|
||||
|
||||
|
||||
def get_version_manifest():
|
||||
if not os.path.exists(get_dir_location(f'downloads/version_manifest.json')):
|
||||
print(
|
||||
f'\033[92mDownloading version manifest...\033[m')
|
||||
version_manifest_data = requests.get(
|
||||
'https://launchermeta.mojang.com/mc/game/version_manifest.json').json()
|
||||
'https://piston-meta.mojang.com/mc/game/version_manifest_v2.json').json()
|
||||
with open(get_dir_location(f'downloads/version_manifest.json'), 'w') as f:
|
||||
json.dump(version_manifest_data, f)
|
||||
else:
|
||||
|
@ -86,3 +94,30 @@ def get_mappings_for_version(version_id: str):
|
|||
with open(get_dir_location(f'downloads/mappings-{version_id}.txt'), 'r') as f:
|
||||
mappings_text = f.read()
|
||||
return Mappings.parse(mappings_text)
|
||||
|
||||
|
||||
def get_yarn_versions():
|
||||
# https://meta.fabricmc.net/v2/versions/yarn
|
||||
if not os.path.exists(get_dir_location('downloads/yarn_versions.json')):
|
||||
print('\033[92mDownloading yarn versions...\033[m')
|
||||
yarn_versions_data = requests.get(
|
||||
'https://meta.fabricmc.net/v2/versions/yarn').json()
|
||||
with open(get_dir_location('downloads/yarn_versions.json'), 'w') as f:
|
||||
json.dump(yarn_versions_data, f)
|
||||
else:
|
||||
with open(get_dir_location('downloads/yarn_versions.json'), 'r') as f:
|
||||
yarn_versions_data = json.load(f)
|
||||
return yarn_versions_data
|
||||
|
||||
|
||||
def get_yarn_data(version_id: str):
|
||||
for version in get_yarn_versions():
|
||||
if version['gameVersion'] == version_id:
|
||||
return version
|
||||
|
||||
|
||||
def clear_version_cache():
|
||||
files = [
|
||||
'version_manifest.json',
|
||||
'yarn_versions.json'
|
||||
]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Extracting data from the Minecraft jars
|
||||
|
||||
from lib.download import get_server_jar, get_burger, get_client_jar
|
||||
from lib.download import get_server_jar, get_burger, get_client_jar, get_generator_mod, get_yarn_data
|
||||
from lib.utils import get_dir_location
|
||||
import json
|
||||
import os
|
||||
|
@ -42,3 +42,47 @@ def get_burger_data_for_version(version_id: str):
|
|||
)
|
||||
with open(get_dir_location(f'downloads/burger-{version_id}.json'), 'r') as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
def get_generator_mod_data(version_id: str, category: str):
|
||||
'''
|
||||
Gets data from u9g's data generator mod. Note that this is not very stable, and it requires Yarn to release updates first.
|
||||
'''
|
||||
|
||||
target_dir = get_dir_location(f'downloads/generator-mod-{version_id}')
|
||||
|
||||
if not os.path.exists(get_dir_location(target_dir)):
|
||||
generator_mod_dir = get_generator_mod()
|
||||
|
||||
yarn_data = get_yarn_data(version_id)
|
||||
if not yarn_data:
|
||||
raise Exception(
|
||||
'Fabric/Yarn hasn\'t been updated to this version yet.')
|
||||
# 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
|
||||
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:
|
||||
for line in lines:
|
||||
if line.startswith('minecraft_version='):
|
||||
line = f'minecraft_version={version_id}\n'
|
||||
if line.startswith('yarn_mappings='):
|
||||
line = f'yarn_mappings={yarn_version}\n'
|
||||
f.write(line)
|
||||
|
||||
os.system(
|
||||
f'cd {generator_mod_dir} && gradlew runServer'
|
||||
)
|
||||
|
||||
if os.path.exists(target_dir):
|
||||
os.unlink(target_dir)
|
||||
os.rename(
|
||||
get_dir_location(
|
||||
f'{generator_mod_dir}/run/minecraft-data/{version_id}'),
|
||||
target_dir
|
||||
)
|
||||
|
||||
with open(f'{target_dir}/{category}.json', 'r') as f:
|
||||
return json.load(f)
|
||||
|
|
Loading…
Add table
Reference in a new issue