aboutsummaryrefslogtreecommitdiff
path: root/codegen/lib/code/shapes.py
diff options
context:
space:
mode:
Diffstat (limited to 'codegen/lib/code/shapes.py')
-rwxr-xr-xcodegen/lib/code/shapes.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/codegen/lib/code/shapes.py b/codegen/lib/code/shapes.py
index 12b333d1..c4964fa6 100755
--- a/codegen/lib/code/shapes.py
+++ b/codegen/lib/code/shapes.py
@@ -5,11 +5,11 @@ COLLISION_BLOCKS_RS_DIR = get_dir_location(
'../azalea-physics/src/collision/blocks.rs')
-def generate_block_shapes(blocks_pixlyzer: dict, shapes: dict, aabbs: dict, block_states_report, block_datas_burger, mappings: Mappings):
+def generate_block_shapes(blocks_pixlyzer: dict, shapes: dict, aabbs: dict, block_states_report):
blocks, shapes = simplify_shapes(blocks_pixlyzer, shapes, aabbs)
code = generate_block_shapes_code(
- blocks, shapes, block_states_report, block_datas_burger, mappings)
+ blocks, shapes, block_states_report)
with open(COLLISION_BLOCKS_RS_DIR, 'w') as f:
f.write(code)
@@ -63,7 +63,7 @@ def simplify_shapes(blocks: dict, shapes: dict, aabbs: dict):
return new_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):
# look at __cache__/generator-mod-*/blockCollisionShapes.json for format of blocks and shapes
generated_shape_code = ''
@@ -75,7 +75,9 @@ def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report,
empty_shapes = []
full_shapes = []
- block_state_ids_to_shape_ids = []
+ # the index into this list is the block state id
+ shapes_map = []
+
for block_id, shape_ids in blocks.items():
if isinstance(shape_ids, int):
shape_ids = [shape_ids]
@@ -89,17 +91,19 @@ def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report,
elif shape_id == 1 :
full_shapes.append(block_state_id)
- block_state_ids_to_shape_ids.append((block_state_id, shape_id))
-
+ while len(shapes_map) <= block_state_id:
+ # default to shape 1 for missing shapes (full block)
+ shapes_map.append(1)
+ shapes_map[block_state_id] = shape_id
- generated_map_code = f'static SHAPES_MAP: [&LazyLock<VoxelShape>; {len(block_state_ids_to_shape_ids)}] = ['
+
- block_state_ids_to_shape_ids = sorted(block_state_ids_to_shape_ids, key=lambda x: x[0])
+ generated_map_code = f'static SHAPES_MAP: [&LazyLock<VoxelShape>; {len(shapes_map)}] = ['
empty_shape_match_code = convert_ints_to_rust_ranges(empty_shapes)
block_shape_match_code = convert_ints_to_rust_ranges(full_shapes)
- for block_state_id, shape_id in block_state_ids_to_shape_ids:
+ for block_state_id, shape_id in enumerate(shapes_map):
generated_map_code += f'&SHAPE{shape_id},\n'
generated_map_code += '];'
@@ -109,7 +113,7 @@ def generate_block_shapes_code(blocks: dict, shapes: dict, block_states_report,
return f'''
//! Autogenerated block collisions for every block
-// This file is generated from codegen/lib/code/block_shapes.py. If you want to
+// This file is generated from codegen/lib/code/shapes.py. If you want to
// modify it, change that file.
#![allow(clippy::explicit_auto_deref)]