aboutsummaryrefslogtreecommitdiff
path: root/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'codegen')
-rwxr-xr-xcodegen/README.md2
-rwxr-xr-xcodegen/genblocks.py5
-rwxr-xr-xcodegen/lib/code/blocks.py8
-rw-r--r--codegen/lib/code/entity.py28
-rwxr-xr-xcodegen/lib/download.py2
-rwxr-xr-xcodegen/lib/extract.py17
-rwxr-xr-xcodegen/migrate.py152
7 files changed, 121 insertions, 93 deletions
diff --git a/codegen/README.md b/codegen/README.md
index ba5e54a3..60b881ce 100755
--- a/codegen/README.md
+++ b/codegen/README.md
@@ -40,7 +40,7 @@ If it all works, make a pull request. If the version you updated to is a snapsho
At the time of writing, the following data generators are used:
- [Vanilla data generator](https://wiki.vg/Data_Generators)
-- [Burger](https://github.com/Pokechu22/Burger)
+- [Burger](https://github.com/mat-1/Burger)
- [PixLyzer](https://gitlab.bixilon.de/bixilon/pixlyzer)
Some things can be obtained from multiple generators. You should prefer them by the order above (the vanilla generator is the most reliable).
diff --git a/codegen/genblocks.py b/codegen/genblocks.py
index 5e28b60a..1af0ad10 100755
--- a/codegen/genblocks.py
+++ b/codegen/genblocks.py
@@ -9,10 +9,11 @@ import lib.utils
version_id = lib.code.version.get_version_id()
+# TODO: pixlyzer is broken so we use old data
shape_datas = lib.extract.get_pixlyzer_data(
- version_id, 'shapes')
+ '1.20.3-pre4', 'shapes')
pixlyzer_block_datas = lib.extract.get_pixlyzer_data(
- version_id, 'blocks')
+ '1.20.3-pre4', 'blocks')
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 f96b1116..64347849 100755
--- a/codegen/lib/code/blocks.py
+++ b/codegen/lib/code/blocks.py
@@ -41,7 +41,7 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, pixlyzer_block_dat
if property_burger is None:
print(
- 'Warning: The reports have states for a block, but Burger doesn\'t!', block_data_burger)
+ f'Warning: The reports have states for a block, but Burger doesn\'t! (missing "{property_name}")', block_data_burger)
property_struct_name = get_property_struct_name(
property_burger, block_data_burger, property_variants, mappings)
@@ -90,7 +90,7 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, pixlyzer_block_dat
for block_id in ordered_blocks:
block_data_burger = blocks_burger[block_id]
block_data_report = blocks_report['minecraft:' + block_id]
- block_data_pixlyzer = pixlyzer_block_datas[f'minecraft:{block_id}']
+ block_data_pixlyzer = pixlyzer_block_datas.get(f'minecraft:{block_id}', {})
block_properties = block_data_burger.get('states', [])
block_properties_burger = block_data_burger.get('states', [])
@@ -202,6 +202,10 @@ def get_property_struct_name(property: Optional[dict], block_data_burger: dict,
return 'ChestType'
if property_variants == ['compare', 'subtract']:
return 'ComparatorType'
+ if property_variants == ['inactive', 'waiting_for_players', 'active', 'waiting_for_reward_ejection', 'ejecting_reward', 'cooldown']:
+ return 'TrialSpawnerState'
+ if property_variants == ['inactive', 'active', 'unlocking', 'ejecting']:
+ return 'VaultState'
if 'harp' in property_variants and 'didgeridoo' in property_variants:
return 'Sound'
diff --git a/codegen/lib/code/entity.py b/codegen/lib/code/entity.py
index 8fa11430..5f0bc3d9 100644
--- a/codegen/lib/code/entity.py
+++ b/codegen/lib/code/entity.py
@@ -89,7 +89,7 @@ def generate_entity_metadata(burger_entities_data: dict, mappings: Mappings):
with open(DATA_RS_DIR, 'w') as f:
f.write('\n'.join(lines))
print('Expected metadata types:\n' + '\n'.join(new_metadata_names))
- print('Updated metadata types in azalea-world/src/entity/data.rs, go make sure they\'re correct and then press enter')
+ print('Updated metadata types in azalea-entity/src/data.rs, go make sure they\'re correct (check EntityDataSerializers.java) and then press enter')
input()
metadata_types = parse_metadata_types_from_code()
@@ -100,12 +100,17 @@ def generate_entity_metadata(burger_entities_data: dict, mappings: Mappings):
// This file is generated from codegen/lib/code/entity.py.
// Don't change it manually!
+use crate::particle::Particle;
+
use super::{
- EntityDataItem, EntityDataValue, OptionalUnsignedInt, Pose, Quaternion, Rotations,
- SnifferState, VillagerData
+ ArmadilloStateKind, EntityDataItem, EntityDataValue, OptionalUnsignedInt, Pose, Quaternion,
+ Rotations, SnifferState, VillagerData,
};
use azalea_chat::FormattedText;
-use azalea_core::{particle::Particle, position::{BlockPos, Vec3}, direction::Direction};
+use azalea_core::{
+ direction::Direction,
+ position::{BlockPos, Vec3},
+};
use azalea_inventory::ItemSlot;
use bevy_ecs::{bundle::Bundle, component::Component};
use derive_more::{Deref, DerefMut};
@@ -218,8 +223,7 @@ impl From<EntityDataValue> for UpdateMetadataError {
struct_name = upper_first_letter(
to_camel_case(name_or_bitfield))
- type_id = next(filter(lambda i: i['index'] == index, entity_metadatas))[
- 'type_id']
+ type_id = next(filter(lambda i: i['index'] == index, entity_metadatas))['type_id']
metadata_type_data = metadata_types[type_id]
rust_type = metadata_type_data['type']
@@ -281,8 +285,7 @@ impl From<EntityDataValue> for UpdateMetadataError {
if name_or_bitfield in single_use_imported_types:
field_struct_name = ''
- type_id = next(filter(lambda i: i['index'] == index, entity_metadatas))[
- 'type_id']
+ type_id = next(filter(lambda i: i['index'] == index, entity_metadatas))['type_id']
metadata_type_data = metadata_types[type_id]
rust_type = metadata_type_data['type']
type_name = metadata_type_data['name']
@@ -384,8 +387,7 @@ impl From<EntityDataValue> for UpdateMetadataError {
' },')
for index, name_or_bitfield in get_entity_metadata_names(this_entity_id, burger_entity_metadata, mappings).items():
- default = next(filter(lambda i: i['index'] == index, entity_metadatas)).get(
- 'default', 'Default::default()')
+ default = next(filter(lambda i: i['index'] == index, entity_metadatas)).get('default', 'Default::default()')
if isinstance(name_or_bitfield, str):
type_id = next(filter(lambda i: i['index'] == index, entity_metadatas))[
'type_id']
@@ -454,8 +456,10 @@ impl From<EntityDataValue> for UpdateMetadataError {
for mask, name in name_or_bitfield.items():
name = maybe_rename_field(name, index)
mask = int(mask, 0)
- bit_default = 'true' if (
- default & mask != 0) else 'false'
+ if default is None:
+ bit_default = 'false'
+ else:
+ bit_default = 'true' if (default & mask != 0) else 'false'
code.append(
f' {name}: {upper_first_letter(to_camel_case(name))}({bit_default}),')
code.append(' Self {')
diff --git a/codegen/lib/download.py b/codegen/lib/download.py
index 319c6080..41576594 100755
--- a/codegen/lib/download.py
+++ b/codegen/lib/download.py
@@ -16,7 +16,7 @@ def get_burger():
if not os.path.exists(get_dir_location('__cache__/Burger')):
print('\033[92mDownloading Burger...\033[m')
os.system(
- f'cd {get_dir_location("__cache__")} && git clone https://github.com/pokechu22/Burger && cd Burger && git pull')
+ f'cd {get_dir_location("__cache__")} && git clone https://github.com/mat-1/Burger && cd Burger && git pull')
print('\033[92mInstalling dependencies...\033[m')
os.system(f'cd {get_dir_location("__cache__")}/Burger && pip install six jawa')
diff --git a/codegen/lib/extract.py b/codegen/lib/extract.py
index 608673fa..fa75c49e 100755
--- a/codegen/lib/extract.py
+++ b/codegen/lib/extract.py
@@ -1,5 +1,6 @@
# Extracting data from the Minecraft jars
+from typing import TYPE_CHECKING
from lib.download import get_server_jar, get_burger, get_client_jar, get_pixlyzer, get_yarn_data, get_fabric_api_versions, get_fabric_loader_versions
from lib.utils import get_dir_location
from zipfile import ZipFile
@@ -275,3 +276,19 @@ def get_en_us_lang(version_id: str):
return json.loads(
get_file_from_jar(version_id, 'assets/minecraft/lang/en_us.json')
)
+
+# burger packet id extraction is broken since 1.20.5 (always returns -1, so we have to determine packet id ourselves from the mappings).
+# this is very much not ideal.
+
+if TYPE_CHECKING: from codegen.lib.mappings import Mappings
+def get_packet_list(burger_data, mappings: 'Mappings'):
+ packet_list = list(burger_data[0]['packets']['packet'].values())
+
+ current_packet_id = 0
+ for packet in packet_list:
+ if packet['id'] == -1:
+ packet['id'] = current_packet_id
+ print(packet)
+ current_packet_id += 1
+
+ return packet_list
diff --git a/codegen/migrate.py b/codegen/migrate.py
index 860d860e..2be85643 100755
--- a/codegen/migrate.py
+++ b/codegen/migrate.py
@@ -26,88 +26,89 @@ if len(sys.argv) == 1:
old_version_id = lib.code.version.get_version_id()
old_mappings = lib.download.get_mappings_for_version(old_version_id)
old_burger_data = lib.extract.get_burger_data_for_version(old_version_id)
-old_packet_list = list(old_burger_data[0]['packets']['packet'].values())
new_version_id = sys.argv[1]
new_mappings = lib.download.get_mappings_for_version(new_version_id)
new_burger_data = lib.extract.get_burger_data_for_version(new_version_id)
-new_packet_list = list(new_burger_data[0]['packets']['packet'].values())
-
-
-old_packets: dict[PacketIdentifier, str] = {}
-old_packets_data: dict[PacketIdentifier, dict] = {}
-new_packets: dict[PacketIdentifier, str] = {}
-new_packets_data: dict[PacketIdentifier, dict] = {}
-
-for packet in old_packet_list:
- assert packet['class'].endswith('.class')
- packet_name = old_mappings.get_class(packet['class'][:-6])
- packet_ident = PacketIdentifier(
- packet['id'], packet['direction'].lower(), fix_state(packet['state']))
- old_packets[packet_ident] = packet_name
- old_packets_data[packet_ident] = packet
-for packet in new_packet_list:
- assert packet['class'].endswith('.class')
- packet_name = new_mappings.get_class(packet['class'][:-6])
- packet_ident = PacketIdentifier(
- packet['id'], packet['direction'].lower(), fix_state(packet['state']))
- new_packets[packet_ident] = packet_name
- new_packets_data[packet_ident] = packet
-
-# find removed packets
-removed_packets: list[PacketIdentifier] = []
-for packet, packet_name in old_packets.items():
- if packet_name not in new_packets.values():
- removed_packets.append(packet)
- print('Removed packet:', packet, packet_name)
-for (direction, state), packets in group_packets(removed_packets).items():
- lib.code.packet.remove_packet_ids(packets, direction, state)
-
-print()
-
-# find packets that changed ids
-changed_packets: dict[PacketIdentifier, int] = {}
-for old_packet, old_packet_name in old_packets.items():
- for new_packet, new_packet_name in new_packets.items():
- if old_packet_name == new_packet_name and old_packet.direction == new_packet.direction and old_packet.state == new_packet.state and old_packet.packet_id != new_packet.packet_id:
- changed_packets[old_packet] = new_packet.packet_id
- print('Changed packet id:', old_packet, '->',
- new_packet, f'({new_packet_name})')
- break
-for (direction, state), packets in group_packets(list(changed_packets.keys())).items():
- id_map: dict[int, int] = {}
- for old_packet_id in packets:
- new_packet_id = changed_packets[PacketIdentifier(
- old_packet_id, direction, state)]
- id_map[old_packet_id] = new_packet_id
- lib.code.packet.change_packet_ids(id_map, direction, state)
+old_packet_list = lib.extract.get_packet_list(old_burger_data, old_mappings)
+new_packet_list = lib.extract.get_packet_list(new_burger_data, new_mappings)
+
+
+# old_packets: dict[PacketIdentifier, str] = {}
+# old_packets_data: dict[PacketIdentifier, dict] = {}
+# new_packets: dict[PacketIdentifier, str] = {}
+# new_packets_data: dict[PacketIdentifier, dict] = {}
+
+# for packet in old_packet_list:
+# assert packet['class'].endswith('.class')
+# packet_name = old_mappings.get_class(packet['class'][:-6])
+# packet_ident = PacketIdentifier(
+# packet['id'], packet['direction'].lower(), fix_state(packet['state']))
+# old_packets[packet_ident] = packet_name
+# old_packets_data[packet_ident] = packet
+# for packet in new_packet_list:
+# assert packet['class'].endswith('.class')
+# packet_name = new_mappings.get_class(packet['class'][:-6])
+# packet_ident = PacketIdentifier(
+# packet['id'], packet['direction'].lower(), fix_state(packet['state']))
+# new_packets[packet_ident] = packet_name
+# new_packets_data[packet_ident] = packet
+
+# # find removed packets
+# removed_packets: list[PacketIdentifier] = []
+# for packet, packet_name in old_packets.items():
+# if packet_name not in new_packets.values():
+# removed_packets.append(packet)
+# print('Removed packet:', packet, packet_name)
+# for (direction, state), packets in group_packets(removed_packets).items():
+# lib.code.packet.remove_packet_ids(packets, direction, state)
print()
-# find added/changed packets
-added_or_changed_packets: list[PacketIdentifier] = []
-for new_packet, packet_name in new_packets.items():
- old_packet = None
- for old_packet_tmp, old_packet_name in old_packets.items():
- if old_packet_name == packet_name:
- old_packet = old_packet_tmp
- break
-
- if packet_name not in old_packets.values():
- added_or_changed_packets.append(new_packet)
- print('Added packet:', new_packet, packet_name)
- elif old_packet and not lib.code.packet.are_packet_instructions_identical(new_packets_data[new_packet].get('instructions'), old_packets_data[old_packet].get('instructions')):
- added_or_changed_packets.append(new_packet)
- print('Changed packet:', new_packet, packet_name)
-for packet in added_or_changed_packets:
- lib.code.packet.generate_packet(
- new_burger_data[0]['packets']['packet'], new_mappings, packet.packet_id, packet.direction, packet.state)
+# # find packets that changed ids
+# changed_packets: dict[PacketIdentifier, int] = {}
+# for old_packet, old_packet_name in old_packets.items():
+# for new_packet, new_packet_name in new_packets.items():
+# if old_packet_name == new_packet_name and old_packet.direction == new_packet.direction and old_packet.state == new_packet.state and old_packet.packet_id != new_packet.packet_id:
+# changed_packets[old_packet] = new_packet.packet_id
+# print('Changed packet id:', old_packet, '->',
+# new_packet, f'({new_packet_name})')
+# break
+# for (direction, state), packets in group_packets(list(changed_packets.keys())).items():
+# id_map: dict[int, int] = {}
+# for old_packet_id in packets:
+# new_packet_id = changed_packets[PacketIdentifier(
+# old_packet_id, direction, state)]
+# id_map[old_packet_id] = new_packet_id
+# lib.code.packet.change_packet_ids(id_map, direction, state)
+
+
+# print()
+
+# # find added/changed packets
+# added_or_changed_packets: list[PacketIdentifier] = []
+# for new_packet, packet_name in new_packets.items():
+# old_packet = None
+# for old_packet_tmp, old_packet_name in old_packets.items():
+# if old_packet_name == packet_name:
+# old_packet = old_packet_tmp
+# break
+
+# if packet_name not in old_packets.values():
+# added_or_changed_packets.append(new_packet)
+# print('Added packet:', new_packet, packet_name)
+# elif old_packet and not lib.code.packet.are_packet_instructions_identical(new_packets_data[new_packet].get('instructions'), old_packets_data[old_packet].get('instructions')):
+# added_or_changed_packets.append(new_packet)
+# print('Changed packet:', new_packet, packet_name)
+# for packet in added_or_changed_packets:
+# lib.code.packet.generate_packet(
+# new_burger_data[0]['packets']['packet'], new_mappings, packet.packet_id, packet.direction, packet.state)
lib.code.version.set_protocol_version(
new_burger_data[0]['version']['protocol'])
-print('Updated protocol!')
+# print('Updated protocol!')
old_ordered_blocks = lib.extract.get_ordered_blocks_burger(old_version_id)
@@ -118,10 +119,11 @@ if old_ordered_blocks != new_ordered_blocks:
block_states_burger = lib.extract.get_block_states_burger(new_version_id)
block_states_report = lib.extract.get_block_states_report(new_version_id)
+ # TODO: pixlyzer is currently broken so uhhhh
shape_datas = lib.extract.get_pixlyzer_data(
- new_version_id, 'shapes')
+ '1.20.3-pre4', 'shapes')
pixlyzer_block_datas = lib.extract.get_pixlyzer_data(
- new_version_id, 'blocks')
+ '1.20.3-pre4', 'blocks')
lib.code.blocks.generate_blocks(
block_states_burger, block_states_report, pixlyzer_block_datas, new_ordered_blocks, new_mappings)
@@ -136,9 +138,9 @@ print('Generating registries...')
import genregistries
genregistries.generate(new_version_id)
-print('Generating entity metadata...')
-burger_entities_data = new_burger_data[0]['entities']
-lib.code.entity.generate_entity_metadata(burger_entities_data, new_mappings)
+# print('Generating entity metadata...')
+# burger_entities_data = new_burger_data[0]['entities']
+# lib.code.entity.generate_entity_metadata(burger_entities_data, new_mappings)
print('Finishing touches, setting version in README and formatting code...')
lib.code.version.set_version_id(new_version_id)