diff options
Diffstat (limited to 'codegen')
| -rw-r--r-- | codegen/genblocks.py | 14 | ||||
| -rw-r--r-- | codegen/lib/code/blocks.py | 32 | ||||
| -rw-r--r-- | codegen/lib/extract.py | 10 |
3 files changed, 48 insertions, 8 deletions
diff --git a/codegen/genblocks.py b/codegen/genblocks.py index 70004820..0863ec31 100644 --- a/codegen/genblocks.py +++ b/codegen/genblocks.py @@ -4,10 +4,22 @@ import lib.code.blocks 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') + +mappings = lib.download.get_mappings_for_version(version_id) block_states_data = lib.extract.get_block_states(version_id) -lib.code.blocks.generate_blocks(block_states_data) +lib.code.blocks.generate_blocks(block_states_data, mappings) diff --git a/codegen/lib/code/blocks.py b/codegen/lib/code/blocks.py index ca178ff3..bc5083c7 100644 --- a/codegen/lib/code/blocks.py +++ b/codegen/lib/code/blocks.py @@ -1,11 +1,29 @@ -from lib.utils import to_camel_case from lib.utils import get_dir_location +from lib.utils import to_camel_case +from ..mappings import Mappings import json BLOCKS_RS_DIR = get_dir_location('../azalea-block/src/blocks.rs') +# Terminology: +# - Property: A property of a block, like "direction" +# - Variant: A potential state of a property, like "up" +# - State: A possible state of a block, a combination of variants +# - Block: Has properties and states. + + +def get_property_variants(data) -> list[str]: + if 'values' in data: + return list(map(str.lower, data['values'])) + if data['type'] == 'bool': + return ['true', 'false'] + if data['type'] == 'int': + # range between data['min'] and data['max'] + return [str(i) for i in range(data['min'], data['max'] + 1)] + raise Exception('Unknown property type: ' + data['type']) + -def generate_blocks(blocks: dict): +def generate_blocks(blocks: dict, mappings: Mappings): with open(BLOCKS_RS_DIR, 'r') as f: existing_code = f.read().splitlines() @@ -15,7 +33,14 @@ def generate_blocks(blocks: dict): # Find properties properties = {} for block_data in blocks.values(): - block_properties = block_data.get('properties', {}) + block_properties = {} + for property in block_data.get('states', []): + property_name = mappings.get_field( + property.get('declared_in', block_data['class']), property['field_name']).lower() + property_variants = get_property_variants(property) + block_properties[property_name] = property_variants + # if property_name == 'eggs': + # print(property, property_name, property_variants) properties.update(block_properties) # Property codegen @@ -35,7 +60,6 @@ def generate_blocks(blocks: dict): # Block codegen new_make_block_states_macro_code.append(' Blocks => {') for block_id, block_data in blocks.items(): - block_id = block_id.split(':')[1] block_states = block_data['states'] default_property_variants = {} diff --git a/codegen/lib/extract.py b/codegen/lib/extract.py index 2e46736e..bf116437 100644 --- a/codegen/lib/extract.py +++ b/codegen/lib/extract.py @@ -16,10 +16,14 @@ def generate_data_from_server_jar(version_id: str): ) +# the minecraft server jar doesn't give enough useful info so we use burger instead +# def get_block_states(version_id: str): +# generate_data_from_server_jar(version_id) +# with open(get_dir_location(f'downloads/generated-{version_id}/reports/blocks.json'), 'r') as f: +# return json.load(f) def get_block_states(version_id: str): - generate_data_from_server_jar(version_id) - with open(get_dir_location(f'downloads/generated-{version_id}/reports/blocks.json'), 'r') as f: - return json.load(f) + burger_data = get_burger_data_for_version(version_id) + return burger_data[0]['blocks']['block'] def get_burger_data_for_version(version_id: str): |
