From 2b9c453ade60bf4a37e2d77059641dc81b011be0 Mon Sep 17 00:00:00 2001 From: eihqnh <40905037+eihqnh@users.noreply.github.com> Date: Sun, 5 Oct 2025 02:25:01 +0800 Subject: fix(inventory): update 1.21.9 entity and block entity component structures (#260) --- codegen/lib/code/data_components.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'codegen/lib') 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(): -- cgit v1.2.3