aboutsummaryrefslogtreecommitdiff
path: root/codegen/lib
diff options
context:
space:
mode:
Diffstat (limited to 'codegen/lib')
-rw-r--r--codegen/lib/code/packet.py32
-rw-r--r--codegen/lib/code/utils.py3
-rw-r--r--codegen/lib/code/version.py6
-rw-r--r--codegen/lib/download.py31
-rw-r--r--codegen/lib/extract.py14
5 files changed, 76 insertions, 10 deletions
diff --git a/codegen/lib/code/packet.py b/codegen/lib/code/packet.py
index de8254e7..ffa7841c 100644
--- a/codegen/lib/code/packet.py
+++ b/codegen/lib/code/packet.py
@@ -110,7 +110,8 @@ def set_packets(packet_ids: list[int], packet_class_names: list[str], direction:
packet_ids, packet_class_names = [list(x) for x in zip(
*sorted(zip(packet_ids, packet_class_names), key=lambda pair: pair[0]))] # type: ignore
- mod_rs_dir = f'../azalea-protocol/src/packets/{state}/mod.rs'
+ mod_rs_dir = get_dir_location(
+ f'../azalea-protocol/src/packets/{state}/mod.rs')
with open(mod_rs_dir, 'r') as f:
mod_rs = f.read().splitlines()
new_mod_rs = []
@@ -140,6 +141,7 @@ def set_packets(packet_ids: list[int], packet_class_names: list[str], direction:
new_mod_rs.append(
make_packet_mod_rs_line(packet_id, packet_class_name)
)
+ required_modules.append(packet_class_name)
else:
ignore_lines = False
continue
@@ -164,7 +166,8 @@ def set_packets(packet_ids: list[int], packet_class_names: list[str], direction:
def get_packets(direction: str, state: str):
- mod_rs_dir = f'../azalea-protocol/src/packets/{state}/mod.rs'
+ mod_rs_dir = get_dir_location(
+ f'../azalea-protocol/src/packets/{state}/mod.rs')
with open(mod_rs_dir, 'r') as f:
mod_rs = f.read().splitlines()
@@ -268,3 +271,28 @@ def remove_packet_ids(removing_packet_ids: list[int], direction: str, state: str
new_packet_class_names.append(packet_class_name)
set_packets(new_packet_ids, new_packet_class_names, direction, state)
+
+
+def are_packet_instructions_identical(old_packet, new_packet):
+ old_packet = old_packet or []
+ new_packet = new_packet or []
+
+ if len(old_packet) != len(new_packet):
+ return False
+
+ for old_field, new_field in zip(old_packet, new_packet):
+ if old_field['operation'] != new_field['operation']:
+ return False
+ if new_field['operation'] == 'write':
+ if burger_type_to_rust_type(old_field.get('type')) != burger_type_to_rust_type(new_field.get('type')):
+ return False
+ else:
+ # comparing is too complicated here since it's possible the type has variables
+ # so we just don't
+ pass
+
+ if 'instructions' in old_field and 'instructions' in new_field:
+ if not are_packet_instructions_identical(old_field['instructions'], new_field['instructions']):
+ return False
+
+ return True
diff --git a/codegen/lib/code/utils.py b/codegen/lib/code/utils.py
index ecfff4fb..0c22d7ba 100644
--- a/codegen/lib/code/utils.py
+++ b/codegen/lib/code/utils.py
@@ -62,8 +62,7 @@ def burger_type_to_rust_type(burger_type):
burger_type[:-2])
field_type_rs = f'Vec<{field_type_rs}>'
else:
- print('Unknown field type:', burger_type)
- exit()
+ raise Exception(f'Unknown field type: {burger_type}')
return field_type_rs, is_var, uses
diff --git a/codegen/lib/code/version.py b/codegen/lib/code/version.py
index 511d30d1..13d9472d 100644
--- a/codegen/lib/code/version.py
+++ b/codegen/lib/code/version.py
@@ -36,7 +36,7 @@ def set_version_id(version_id: str) -> None:
def get_protocol_version() -> str:
# azalea-protocol/src/packets/mod.rs
# pub const PROTOCOL_VERSION: u32 = 758;
- with open('../azalea-protocol/src/packets/mod.rs', 'r') as f:
+ with open(get_dir_location('../azalea-protocol/src/packets/mod.rs'), 'r') as f:
mod_rs = f.read().splitlines()
for line in mod_rs:
if line.strip().startswith('pub const PROTOCOL_VERSION'):
@@ -46,7 +46,7 @@ def get_protocol_version() -> str:
def set_protocol_version(protocol_version: str) -> None:
- with open('../azalea-protocol/src/packets/mod.rs', 'r') as f:
+ with open(get_dir_location('../azalea-protocol/src/packets/mod.rs'), 'r') as f:
mod_rs = f.read().splitlines()
for i, line in enumerate(mod_rs):
if line.strip().startswith('pub const PROTOCOL_VERSION'):
@@ -56,5 +56,5 @@ def set_protocol_version(protocol_version: str) -> None:
raise Exception(
'Could not find protocol version in azalea-protocol/src/packets/mod.rs')
- with open('../azalea-protocol/src/packets/mod.rs', 'w') as f:
+ with open(get_dir_location('../azalea-protocol/src/packets/mod.rs'), 'w') as f:
f.write('\n'.join(mod_rs))
diff --git a/codegen/lib/download.py b/codegen/lib/download.py
index e9712f8d..d9e2e63f 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,39 @@ 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 = []
+
+ versioning_el = fabric_api_versions_data_xml.find('versioning')
+ assert versioning_el
+ versions_el = versioning_el.find('versions')
+ assert versions_el
+
+ for version_el in versions_el.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'