4 void item_stack_initialize(ItemStack *stack)
6 stack->type = ITEM_NONE;
10 if (item_defs[stack->type].callbacks.create)
11 item_defs[stack->type].callbacks.create(stack);
14 void item_stack_destroy(ItemStack *stack)
16 if (item_defs[stack->type].callbacks.delete)
17 item_defs[stack->type].callbacks.delete(stack);
25 void item_stack_set(ItemStack *stack, ItemType type, u32 count, Blob buffer)
27 item_stack_destroy(stack);
31 stack->data = item_defs[stack->type].data_size > 0 ?
32 malloc(item_defs[stack->type].data_size) : NULL;
34 if (item_defs[stack->type].callbacks.create)
35 item_defs[stack->type].callbacks.create(stack);
37 if (item_defs[stack->type].callbacks.deserialize)
38 item_defs[stack->type].callbacks.deserialize(&buffer, stack->data);
41 void item_stack_serialize(ItemStack *stack, SerializedItemStack *serialized)
43 serialized->type = stack->type;
44 serialized->count = stack->count;
45 serialized->data = (Blob) {0, NULL};
47 if (item_defs[stack->type].callbacks.serialize)
48 item_defs[stack->type].callbacks.serialize(&serialized->data, stack->data);
51 void item_stack_deserialize(ItemStack *stack, SerializedItemStack *serialized)
53 ItemType type = serialized->type;
55 if (type >= COUNT_ITEM)
58 item_stack_set(stack, type, serialized->count, serialized->data);
61 ItemDef item_defs[COUNT_ITEM] = {
66 .dig_class = DIG_NONE,
73 .dig_class = DIG_NONE,
80 .dig_class = DIG_STONE,
87 .dig_class = DIG_WOOD,