From 5d764c79d0b2be9a57a863cd2cb31ca47c16beca Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 28 May 2022 18:20:15 -0500 Subject: genblocks --- azalea-block/block-macros/src/lib.rs | 6 +++--- azalea-block/src/blocks.rs | 4 ++-- codegen/genblocks.py | 13 +++++++++++++ codegen/lib/code/blocks.py | 17 +++++++++++++++++ codegen/newpacket.py | 7 +++++-- 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 codegen/genblocks.py create mode 100644 codegen/lib/code/blocks.py diff --git a/azalea-block/block-macros/src/lib.rs b/azalea-block/block-macros/src/lib.rs index 3d937ac4..63e21e58 100644 --- a/azalea-block/block-macros/src/lib.rs +++ b/azalea-block/block-macros/src/lib.rs @@ -101,16 +101,16 @@ impl Parse for BlockDefinitions { impl Parse for MakeBlockStates { fn parse(input: ParseStream) -> Result { - // PROPERTIES => { ... } BLOCKS => { ... } + // Properties => { ... } Blocks => { ... } let properties_ident = input.parse::()?; - assert_eq!(properties_ident.to_string(), "PROPERTIES"); + assert_eq!(properties_ident.to_string(), "Properties"); input.parse::]>()?; let content; braced!(content in input); let properties = content.parse()?; let blocks_ident = input.parse::()?; - assert_eq!(blocks_ident.to_string(), "BLOCKS"); + assert_eq!(blocks_ident.to_string(), "Blocks"); input.parse::]>()?; let content; braced!(content in input); diff --git a/azalea-block/src/blocks.rs b/azalea-block/src/blocks.rs index beba877e..88253e34 100644 --- a/azalea-block/src/blocks.rs +++ b/azalea-block/src/blocks.rs @@ -7,7 +7,7 @@ pub trait Block { } make_block_states! { - PROPERTIES => { + Properties => { Face { Floor, Wall, @@ -36,7 +36,7 @@ make_block_states! { False }; } - BLOCKS => { + Blocks => { acacia_button => BlockBehavior::default().no_collision(), { Face, Facing, diff --git a/codegen/genblocks.py b/codegen/genblocks.py new file mode 100644 index 00000000..70004820 --- /dev/null +++ b/codegen/genblocks.py @@ -0,0 +1,13 @@ +import lib.code.version +import lib.code.packet +import lib.code.blocks +import lib.code.utils +import lib.download +import lib.extract +import sys + +version_id = lib.code.version.get_version_id() + +block_states_data = lib.extract.get_block_states(version_id) + +lib.code.blocks.generate_blocks(block_states_data) diff --git a/codegen/lib/code/blocks.py b/codegen/lib/code/blocks.py new file mode 100644 index 00000000..bf1260ba --- /dev/null +++ b/codegen/lib/code/blocks.py @@ -0,0 +1,17 @@ +BLOCKS_RS_DIR = '../azalea-blocks/src/blocks.rs' + + +def generate_blocks(blocks: dict): + with open(BLOCKS_RS_DIR, 'r') as f: + existing_code = f.read().splitlines() + + new_make_block_states_macro_code = [] + new_make_block_states_macro_code.append('make_block_states! {') + + properties = {} + for block_name, block_data in blocks.items(): + block_properties = block_data['properties'] + + properties.update(block_properties) + + print(properties) diff --git a/codegen/newpacket.py b/codegen/newpacket.py index 52d6a2b4..48d97640 100644 --- a/codegen/newpacket.py +++ b/codegen/newpacket.py @@ -1,11 +1,14 @@ +import lib.code.version import lib.code.packet import lib.code.utils import lib.download import lib.extract import sys -mappings = lib.download.get_mappings_for_version('1.18.2') -burger_data = lib.extract.get_burger_data_for_version('1.18.2') +version_id = lib.code.version.get_version_id() + +mappings = lib.download.get_mappings_for_version(version_id) +burger_data = lib.extract.get_burger_data_for_version(version_id) burger_packets_data = burger_data[0]['packets']['packet'] packet_id, direction, state = int(sys.argv[1]), sys.argv[2], sys.argv[3] -- cgit v1.2.3