mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
Merge branch 'main' into azalea-entity
This commit is contained in:
commit
0d1e17197b
6 changed files with 111 additions and 15 deletions
|
@ -5,19 +5,20 @@ import lib.code.utils
|
|||
import lib.download
|
||||
import lib.extract
|
||||
import lib.utils
|
||||
import sys
|
||||
import os
|
||||
|
||||
version_id = lib.code.version.get_version_id()
|
||||
|
||||
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')
|
||||
lib.extract.get_generator_mod_data(version_id, 'blockCollisionShapes')
|
||||
|
||||
# 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))
|
||||
|
|
|
@ -5,7 +5,9 @@ import json
|
|||
import os
|
||||
|
||||
# make sure the downloads directory exists
|
||||
print('Making downloads')
|
||||
if not os.path.exists(get_dir_location('downloads')):
|
||||
print('Made downloads directory.', get_dir_location('downloads'))
|
||||
os.mkdir(get_dir_location('downloads'))
|
||||
|
||||
|
||||
|
@ -19,12 +21,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 +96,39 @@ 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():
|
||||
print('\033[92mClearing version cache...\033[m')
|
||||
files = [
|
||||
'version_manifest.json',
|
||||
'yarn_versions.json'
|
||||
]
|
||||
for file in files:
|
||||
if os.path.exists(get_dir_location(f'downloads/{file}')):
|
||||
os.remove(get_dir_location(f'downloads/{file}'))
|
||||
|
||||
os.system(
|
||||
f'cd {get_dir_location("downloads/Burger")} && git pull')
|
||||
os.system(
|
||||
f'cd {get_dir_location("downloads/minecraft-data-generator-server")} && git pull')
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -18,9 +18,11 @@ def to_camel_case(name: str):
|
|||
s = f'_{s}'
|
||||
return s
|
||||
|
||||
|
||||
def upper_first_letter(name: str):
|
||||
return name[0].upper() + name[1:]
|
||||
|
||||
|
||||
def padded_hex(n: int):
|
||||
return f'0x{n:02x}'
|
||||
|
||||
|
@ -55,4 +57,4 @@ def group_packets(packets: list[PacketIdentifier]):
|
|||
|
||||
|
||||
def get_dir_location(name: str):
|
||||
return os.path.join(os.path.dirname(__file__), '..', name)
|
||||
return os.path.join(os.path.dirname(os.path.dirname(__file__)), name)
|
||||
|
|
|
@ -6,7 +6,8 @@ import lib.code.packet
|
|||
import lib.download
|
||||
import lib.extract
|
||||
import sys
|
||||
import os
|
||||
|
||||
lib.download.clear_version_cache()
|
||||
|
||||
old_version_id = lib.code.version.get_version_id()
|
||||
old_mappings = lib.download.get_mappings_for_version(old_version_id)
|
||||
|
|
Loading…
Add table
Reference in a new issue