fix: use composition.reg_id for entity identity in slot_of

get_children() returns fresh userdata wrappers without __eq; raw ==
compares Lua pointers (fails across separate get_children calls).
slot_of now reads composition.reg_id from each child to find the
matching slot, making contains/remove reliable across wrapper instances.
This commit is contained in:
Calic
2026-06-13 17:35:21 +02:00
parent 6822184c46
commit a814b10ef2
2 changed files with 35 additions and 6 deletions

View File

@@ -97,6 +97,11 @@ Non-item children (future use) are silently excluded.
**Syntax:** `inventory.contains(container: entity, item: entity) -> bool`
**Example:**
```lua
local has_rock = inventory.contains(backpack, rock)
```
**Description:** Returns `true` if `item` is currently a child of
`container` under a synthetic slot.
@@ -104,6 +109,11 @@ Non-item children (future use) are silently excluded.
**Syntax:** `inventory.count(container: entity) -> number`
**Example:**
```lua
local n = inventory.count(backpack)
```
**Description:** Returns the number of items currently in `container`.
Equivalent to `#inventory.contents(container)`.