aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-06-21 19:06:18 -0500
committermat <github@matdoes.dev>2022-06-21 19:06:18 -0500
commitaf7a7b428c60021e1ef717dd7dc3888c21188693 (patch)
treee41a4c573cf29334d94976cdfb25595e6c595375
parenta1484f66290517b6c36f2e82c92613f23d2c4935 (diff)
parent317567b77a9e339b5dc9a4832b1ce4c6b045dfe7 (diff)
downloadazalea-drasl-af7a7b428c60021e1ef717dd7dc3888c21188693.tar.xz
Merge branch 'main' into 1.19.1
-rw-r--r--codegen/genblocks.py19
-rw-r--r--codegen/lib/code/blocks.py6
-rw-r--r--codegen/lib/download.py48
-rw-r--r--codegen/lib/extract.py46
-rw-r--r--codegen/lib/utils.py4
-rw-r--r--codegen/migrate.py3
6 files changed, 111 insertions, 15 deletions
diff --git a/codegen/genblocks.py b/codegen/genblocks.py
index 9e35f7f3..174d2e16 100644
--- a/codegen/genblocks.py
+++ b/codegen/genblocks.py
@@ -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)
diff --git a/codegen/lib/code/blocks.py b/codegen/lib/code/blocks.py
index 4ab4917f..7dc85137 100644
--- a/codegen/lib/code/blocks.py
+++ b/codegen/lib/code/blocks.py
@@ -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))
diff --git a/codegen/lib/download.py b/codegen/lib/download.py
index 23246c29..e9712f8d 100644
--- a/codegen/lib/download.py
+++ b/codegen/lib/download.py
@@ -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://piston-meta.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')
diff --git a/codegen/lib/extract.py b/codegen/lib/extract.py
index 40263779..893b8d5c 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
+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)
diff --git a/codegen/lib/utils.py b/codegen/lib/utils.py
index 3887bb35..c3d293c0 100644
--- a/codegen/lib/utils.py
+++ b/codegen/lib/utils.py
@@ -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)
diff --git a/codegen/migrate.py b/codegen/migrate.py
index 811a3f76..62924bb9 100644
--- a/codegen/migrate.py
+++ b/codegen/migrate.py
@@ -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)