1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

Fix ordering of blocks

This commit is contained in:
mat 2022-06-11 17:33:58 -05:00
parent e36095c2b1
commit 8aa8baa20d
4 changed files with 4819 additions and 12 deletions

File diff suppressed because it is too large Load diff

View file

@ -21,6 +21,8 @@ print('Ok')
mappings = lib.download.get_mappings_for_version(version_id) mappings = lib.download.get_mappings_for_version(version_id)
block_states_burger = lib.extract.get_block_states_burger(version_id) block_states_burger = lib.extract.get_block_states_burger(version_id)
ordered_blocks = lib.extract.get_ordered_blocks_burger(version_id)
block_states_report = lib.extract.get_block_states_report(version_id) block_states_report = lib.extract.get_block_states_report(version_id)
lib.code.blocks.generate_blocks(block_states_burger, block_states_report, mappings) lib.code.blocks.generate_blocks(
block_states_burger, block_states_report, ordered_blocks, mappings)

View file

@ -10,7 +10,8 @@ BLOCKS_RS_DIR = get_dir_location('../azalea-block/src/blocks.rs')
# - State: A possible state of a block, a combination of variants # - State: A possible state of a block, a combination of variants
# - Block: Has properties and states. # - Block: Has properties and states.
def generate_blocks(blocks_burger: dict, blocks_report: dict, mappings: Mappings):
def generate_blocks(blocks_burger: dict, blocks_report: dict, ordered_blocks: list[str], mappings: Mappings):
with open(BLOCKS_RS_DIR, 'r') as f: with open(BLOCKS_RS_DIR, 'r') as f:
existing_code = f.read().splitlines() existing_code = f.read().splitlines()
@ -20,13 +21,15 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, mappings: Mappings
def get_property_struct_name(property: dict, block_data_burger: dict) -> str: def get_property_struct_name(property: dict, block_data_burger: dict) -> str:
property_name = None property_name = None
for class_name in [block_data_burger['class']] + block_data_burger['super']: for class_name in [block_data_burger['class']] + block_data_burger['super']:
property_name = mappings.get_field(class_name, property['field_name']) property_name = mappings.get_field(
class_name, property['field_name'])
if property_name: if property_name:
break break
assert property_name assert property_name
property_name = to_camel_case(property_name.lower()) property_name = to_camel_case(property_name.lower())
if property['type'] == 'int': if property['type'] == 'int':
property_name = to_camel_case(block_data_burger['text_id']) + property_name property_name = to_camel_case(
block_data_burger['text_id']) + property_name
return property_name return property_name
# Find properties # Find properties
@ -34,7 +37,8 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, mappings: Mappings
# This dict looks like { 'FloweringAzaleaLeavesDistance': 'distance' } # This dict looks like { 'FloweringAzaleaLeavesDistance': 'distance' }
property_struct_names_to_names = {} property_struct_names_to_names = {}
for block_id, block_data_burger in blocks_burger.items(): for block_id in ordered_blocks:
block_data_burger = blocks_burger[block_id]
block_data_report = blocks_report[f'minecraft:{block_id}'] block_data_report = blocks_report[f'minecraft:{block_id}']
block_properties = {} block_properties = {}
@ -45,14 +49,16 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, mappings: Mappings
property_burger = property property_burger = property
break break
if property_burger is None: if property_burger is None:
print('Error: The reports have states for a block, but Burger doesn\'t!', block_data_burger) print(
'Error: The reports have states for a block, but Burger doesn\'t!', block_data_burger)
continue continue
# assert property_burger is not None # assert property_burger is not None
property_variants = block_data_report['properties'][property_struct_name] property_variants = block_data_report['properties'][property_struct_name]
property_struct_name = get_property_struct_name(property_burger, block_data_burger) property_struct_name = get_property_struct_name(
property_burger, block_data_burger)
block_properties[property_struct_name] = property_variants block_properties[property_struct_name] = property_variants
property_name = property_burger['name'] property_name = property_burger['name']
# if the name ends with _<number>, remove that part # if the name ends with _<number>, remove that part
ending = property_name.split('_')[-1] ending = property_name.split('_')[-1]
@ -84,7 +90,8 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, mappings: Mappings
# Block codegen # Block codegen
new_make_block_states_macro_code.append(' Blocks => {') new_make_block_states_macro_code.append(' Blocks => {')
for block_id, block_data_burger in blocks_burger.items(): for block_id in ordered_blocks:
block_data_burger = blocks_burger[block_id]
block_data_report = blocks_report['minecraft:' + block_id] block_data_report = blocks_report['minecraft:' + block_id]
block_properties_burger = block_data_burger['states'] block_properties_burger = block_data_burger['states']
@ -99,7 +106,8 @@ def generate_blocks(blocks_burger: dict, blocks_report: dict, mappings: Mappings
f' {block_id} => BlockBehavior::default(), {{') f' {block_id} => BlockBehavior::default(), {{')
for property in block_properties_burger: for property in block_properties_burger:
property_default = default_property_variants.get(property['name']) property_default = default_property_variants.get(property['name'])
property_struct_name = get_property_struct_name(property, block_data_burger) property_struct_name = get_property_struct_name(
property, block_data_burger)
assert property_default is not None assert property_default is not None
new_make_block_states_macro_code.append( new_make_block_states_macro_code.append(
f' {property_struct_name}={to_camel_case(property_default)},') f' {property_struct_name}={to_camel_case(property_default)},')

View file

@ -21,11 +21,17 @@ def get_block_states_report(version_id: str):
with open(get_dir_location(f'downloads/generated-{version_id}/reports/blocks.json'), 'r') as f: with open(get_dir_location(f'downloads/generated-{version_id}/reports/blocks.json'), 'r') as f:
return json.load(f) return json.load(f)
def get_block_states_burger(version_id: str): def get_block_states_burger(version_id: str):
burger_data = get_burger_data_for_version(version_id) burger_data = get_burger_data_for_version(version_id)
return burger_data[0]['blocks']['block'] return burger_data[0]['blocks']['block']
def get_ordered_blocks_burger(version_id: str):
burger_data = get_burger_data_for_version(version_id)
return burger_data[0]['blocks']['ordered_blocks']
def get_burger_data_for_version(version_id: str): def get_burger_data_for_version(version_id: str):
if not os.path.exists(get_dir_location(f'downloads/burger-{version_id}.json')): if not os.path.exists(get_dir_location(f'downloads/burger-{version_id}.json')):
get_burger() get_burger()