diff options
Diffstat (limited to 'codegen/lib/code')
| -rwxr-xr-x | codegen/lib/code/blocks.py | 24 | ||||
| -rwxr-xr-x | codegen/lib/code/shapes.py | 2 | ||||
| -rw-r--r-- | codegen/lib/code/tags.py | 35 |
3 files changed, 58 insertions, 3 deletions
diff --git a/codegen/lib/code/blocks.py b/codegen/lib/code/blocks.py index a01df648..3af19fa8 100755 --- a/codegen/lib/code/blocks.py +++ b/codegen/lib/code/blocks.py @@ -13,7 +13,7 @@ BLOCKS_RS_DIR = get_dir_location('../azalea-block/src/generated.rs') # - Block: Has properties and states. -def generate_blocks(blocks_burger: dict, blocks_report: dict, ordered_blocks: list[str], mappings: Mappings): +def generate_blocks(blocks_burger: dict, blocks_report: dict, pixlyzer_block_datas: dict, ordered_blocks: list[str], mappings: Mappings): with open(BLOCKS_RS_DIR, 'r') as f: existing_code = f.read().splitlines() @@ -90,6 +90,7 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, ordered_blocks: li 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_properties = block_data_burger.get('states', []) block_properties_burger = block_data_burger.get('states', []) @@ -134,9 +135,28 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, ordered_blocks: li else: properties_code += '\n }' + # make the block behavior + behavior_constructor = 'BlockBehavior::new()' + # requires tool + if block_data_pixlyzer.get('requires_tool'): + behavior_constructor += '.requires_correct_tool_for_drops()' + # strength + destroy_time = block_data_pixlyzer.get('hardness') + explosion_resistance = block_data_pixlyzer.get('explosion_resistance') + if destroy_time and explosion_resistance: + behavior_constructor += f'.strength({destroy_time}, {explosion_resistance})' + elif destroy_time: + behavior_constructor += f'.destroy_time({destroy_time})' + elif explosion_resistance: + behavior_constructor += f'.explosion_resistance({explosion_resistance})' + # friction + friction = block_data_pixlyzer.get('friction') + if friction != None: + behavior_constructor += f'.friction({friction})' + # TODO: use burger to generate the blockbehavior new_make_block_states_macro_code.append( - f' {block_id} => BlockBehavior::default(), {properties_code},') + f' {block_id} => {behavior_constructor}, {properties_code},') new_make_block_states_macro_code.append(' }') new_make_block_states_macro_code.append('}') diff --git a/codegen/lib/code/shapes.py b/codegen/lib/code/shapes.py index 7682fe53..18f2ccbd 100755 --- a/codegen/lib/code/shapes.py +++ b/codegen/lib/code/shapes.py @@ -66,7 +66,7 @@ def simplify_shapes(blocks: dict, shapes: dict, aabbs: dict): def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report, block_datas_burger, mappings: Mappings): - # look at downloads/generator-mod-*/blockCollisionShapes.json for format of blocks and shapes + # look at __cache__/generator-mod-*/blockCollisionShapes.json for format of blocks and shapes generated_shape_code = '' for (shape_id, shape) in sorted(shapes.items(), key=lambda shape: int(shape[0])): diff --git a/codegen/lib/code/tags.py b/codegen/lib/code/tags.py new file mode 100644 index 00000000..40b60ae3 --- /dev/null +++ b/codegen/lib/code/tags.py @@ -0,0 +1,35 @@ +from lib.utils import to_snake_case, upper_first_letter, get_dir_location, to_camel_case + +REGISTRIES_DIR = get_dir_location('../azalea-registry/src/tags') + + +def generate_tags(registries: dict, file_name: str, struct_name: str): + tags_dir = f'{REGISTRIES_DIR}/{file_name}.rs' + + generated = f'''// This file was generated by codegen/lib/code/tags.py, don't edit it manually! + +use std::collections::HashSet; + +use once_cell::sync::Lazy; + +use crate::{struct_name}; + +''' + + for tag_name, tag in registries.items(): + tag_name = tag_name.replace('/', '_') + static_set_name = to_snake_case(tag_name).upper() + generated += f'pub static {static_set_name}: Lazy<HashSet<{struct_name}>> = Lazy::new(|| HashSet::from_iter(vec![' + + queue = tag['values'].copy() + while queue != []: + item = queue.pop(0) + namespace, item_name = item.split(':') + if namespace[0] == '#': + queue += registries[item_name]['values'] + continue + generated += f'{struct_name}::{upper_first_letter(to_camel_case(item_name))},\n' + generated += ']));\n' + + with open(tags_dir, 'w') as f: + f.write(generated)
\ No newline at end of file |
