From bfcda608695b83ce6a3caefceaa79c8e392405d7 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Sun, 13 Jun 2021 20:41:17 +0200 Subject: Add on_create callback for items --- plugins/inventory/inventory.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'plugins/inventory/inventory.c') diff --git a/plugins/inventory/inventory.c b/plugins/inventory/inventory.c index c3b533d..9923561 100644 --- a/plugins/inventory/inventory.c +++ b/plugins/inventory/inventory.c @@ -29,7 +29,11 @@ void inventory_add(struct inventory *self, struct itemstack stack) } } - *ptr = add_element(*ptr, make_buffer(&stack, sizeof(struct itemstack))); + struct itemstack *buf = make_buffer(&stack, sizeof(struct itemstack)); + *ptr = add_element(*ptr, buf); + + if (buf->item->on_create) + buf->item->on_create(buf); } /* @@ -81,6 +85,9 @@ static void decrease_item_count(struct list **ptr, struct itemstack *stack) if (stack->item->on_destroy) stack->item->on_destroy(stack); + if (stack->meta) + free(stack->meta); + free(stack); free(*ptr); -- cgit v1.2.3