diff options
| author | eihqnh <40905037+eihqnh@users.noreply.github.com> | 2025-10-05 02:25:01 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-04 13:25:01 -0500 |
| commit | 2b9c453ade60bf4a37e2d77059641dc81b011be0 (patch) | |
| tree | 0b6d83e6b632842a8cb40e1aa14a5dac8d85bbe6 /codegen | |
| parent | 43f20b821ce26af148156e705f4c1fd3f956beb5 (diff) | |
| download | azalea-drasl-2b9c453ade60bf4a37e2d77059641dc81b011be0.tar.xz | |
fix(inventory): update 1.21.9 entity and block entity component structures (#260)
Diffstat (limited to 'codegen')
| -rw-r--r-- | codegen/lib/code/data_components.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/codegen/lib/code/data_components.py b/codegen/lib/code/data_components.py index bba952e1..b1444860 100644 --- a/codegen/lib/code/data_components.py +++ b/codegen/lib/code/data_components.py @@ -315,6 +315,19 @@ use crate::{ list(python_value.values())[0], target_rust_type ) return str(python_value) + elif target_rust_type == "EntityKind": + # Special handling for EntityKind - can be from NBT compound id field or direct string + entity_id = None + if isinstance(python_value, dict) and "id" in python_value: + entity_id = python_value["id"] + elif isinstance(python_value, str): + entity_id = python_value + + if entity_id and entity_id.startswith("minecraft:"): + entity_name = entity_id[10:] # Remove "minecraft:" prefix + entity_name_camel = lib.utils.to_camel_case(entity_name) + return f"EntityKind::{entity_name_camel}" + raise ValueError(f"Unknown or missing EntityKind: {python_value}") elif target_rust_type == "NbtCompound": # NbtCompound::from_values([ # ("id".into(), "minecraft:allay".into()), @@ -495,6 +508,14 @@ use crate::{ rust_value = f"{rust_value}.into()" field_type = "&str" + elif component_resource_id == "entity_data": + # Special handling for EntityData to use EntityData structure + # Keep rust_value as "value" so it gets processed correctly + field_type = "EntityKind" + + def transform_value_fn(rust_value: str): + return f"{component_struct_name} {{ kind: {rust_value}, data: NbtCompound::new() }}" + item_defaults_original = item_defaults item_defaults = {} for k, v in item_defaults_original.items(): |
