mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
fix identical shapes being defined multiple times
This commit is contained in:
parent
489cdb01aa
commit
b2e54a7ff0
2 changed files with 15123 additions and 33965 deletions
File diff suppressed because it is too large
Load diff
|
@ -8,11 +8,43 @@ COLLISION_BLOCKS_RS_DIR = get_dir_location(
|
||||||
|
|
||||||
|
|
||||||
def generate_block_shapes(blocks: dict, shapes: dict, block_states_report, block_datas_burger, mappings: Mappings):
|
def generate_block_shapes(blocks: dict, shapes: dict, block_states_report, block_datas_burger, mappings: Mappings):
|
||||||
code = generate_block_shapes_code(blocks, shapes, block_states_report, block_datas_burger, mappings)
|
blocks, shapes = simplify_shapes(blocks, shapes)
|
||||||
|
|
||||||
|
code = generate_block_shapes_code(
|
||||||
|
blocks, shapes, block_states_report, block_datas_burger, mappings)
|
||||||
with open(COLLISION_BLOCKS_RS_DIR, 'w') as f:
|
with open(COLLISION_BLOCKS_RS_DIR, 'w') as f:
|
||||||
f.write(code)
|
f.write(code)
|
||||||
|
|
||||||
|
|
||||||
|
def simplify_shapes(blocks: dict, shapes: dict):
|
||||||
|
shape_to_new_id = {}
|
||||||
|
new_id_increment = 0
|
||||||
|
|
||||||
|
new_shapes = {}
|
||||||
|
old_id_to_new_id = {}
|
||||||
|
|
||||||
|
for shape_id, shape in sorted(shapes.items(), key=lambda shape: int(shape[0])):
|
||||||
|
# tuples are hashable
|
||||||
|
shape_as_tuple = tuple(map(tuple, shape))
|
||||||
|
if shape_as_tuple not in shape_to_new_id:
|
||||||
|
shape_to_new_id[shape_as_tuple] = new_id_increment
|
||||||
|
old_id_to_new_id[shape_id] = new_id_increment
|
||||||
|
new_shapes[new_id_increment] = shape
|
||||||
|
new_id_increment += 1
|
||||||
|
else:
|
||||||
|
old_id_to_new_id[shape_id] = shape_to_new_id[shape_as_tuple]
|
||||||
|
|
||||||
|
# now map the blocks to the new shape ids
|
||||||
|
for block_id, shape_ids in blocks.items():
|
||||||
|
if isinstance(shape_ids, int):
|
||||||
|
blocks[block_id] = old_id_to_new_id[str(shape_ids)]
|
||||||
|
else:
|
||||||
|
blocks[block_id] = [old_id_to_new_id[str(shape_id)]
|
||||||
|
for shape_id in shape_ids]
|
||||||
|
|
||||||
|
return blocks, new_shapes
|
||||||
|
|
||||||
|
|
||||||
def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report, block_datas_burger, mappings: Mappings):
|
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 downloads/generator-mod-*/blockCollisionShapes.json for format of blocks and shapes
|
||||||
|
|
||||||
|
@ -39,7 +71,7 @@ def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report,
|
||||||
variant_values = []
|
variant_values = []
|
||||||
for value in tuple(possible_state.get('properties', {}).values()):
|
for value in tuple(possible_state.get('properties', {}).values()):
|
||||||
variant_values.append(to_camel_case(value))
|
variant_values.append(to_camel_case(value))
|
||||||
|
|
||||||
if variant_values == []:
|
if variant_values == []:
|
||||||
variant_name = to_camel_case(block_id)
|
variant_name = to_camel_case(block_id)
|
||||||
else:
|
else:
|
||||||
|
@ -47,13 +79,13 @@ def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report,
|
||||||
|
|
||||||
if shape_id not in shape_ids_to_variants:
|
if shape_id not in shape_ids_to_variants:
|
||||||
shape_ids_to_variants[shape_id] = []
|
shape_ids_to_variants[shape_id] = []
|
||||||
shape_ids_to_variants[shape_id].append(f'BlockState::{variant_name}')
|
shape_ids_to_variants[shape_id].append(
|
||||||
|
f'BlockState::{variant_name}')
|
||||||
# shape 1 is the most common so we have a _ => &SHAPE1 at the end
|
# shape 1 is the most common so we have a _ => &SHAPE1 at the end
|
||||||
del shape_ids_to_variants[1]
|
del shape_ids_to_variants[1]
|
||||||
for shape_id, variants in shape_ids_to_variants.items():
|
for shape_id, variants in shape_ids_to_variants.items():
|
||||||
generated_match_inner_code += f'{"|".join(variants)} => &SHAPE{shape_id},\n'
|
generated_match_inner_code += f'{"|".join(variants)} => &SHAPE{shape_id},\n'
|
||||||
|
|
||||||
|
|
||||||
return f'''
|
return f'''
|
||||||
//! Autogenerated block collisions for every block
|
//! Autogenerated block collisions for every block
|
||||||
|
|
||||||
|
@ -67,7 +99,7 @@ use crate::collision::{{self, Shapes}};
|
||||||
use azalea_block::*;
|
use azalea_block::*;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
trait BlockWithShape {{
|
pub trait BlockWithShape {{
|
||||||
fn shape(&self) -> &'static VoxelShape;
|
fn shape(&self) -> &'static VoxelShape;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
@ -106,5 +138,3 @@ def generate_code_for_shape(shape_id: str, parts: list[list[float]]):
|
||||||
code += f' {steps[-1]}\n'
|
code += f' {steps[-1]}\n'
|
||||||
code += '};\n'
|
code += '};\n'
|
||||||
return code
|
return code
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue