]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/client/client_item.c
Rework structure
[dragonblocks_alpha.git] / src / client / client_item.c
1 #include "client/client_item.h"
2 #include "client/interact.h"
3 #include "common/node.h"
4
5 static bool use_dig(__attribute__((unused)) ItemStack *stack)
6 {
7         return interact_pointed.exists
8                 && (node_def[interact_pointed.node].dig_class & item_def[stack->type].dig_class);
9 }
10
11 ClientItemDef client_item_def[COUNT_ITEM] = {
12         // unknown
13         {
14                 .mesh_path = ASSET_PATH "meshes/unknown.txt",
15                 .mesh = {0},
16                 .use = NULL,
17         },
18         // none
19         {
20                 .mesh_path = NULL,
21                 .mesh = {0},
22                 .use = NULL,
23         },
24         // pickaxe
25         {
26                 .mesh_path = ASSET_PATH "meshes/pickaxe.txt",
27                 .mesh = {0},
28                 .use = &use_dig,
29         },
30         // axe
31         {
32                 .mesh_path = ASSET_PATH "meshes/axe.txt",
33                 .mesh = {0},
34                 .use = &use_dig,
35         },
36         // shovel
37         {
38                 .mesh_path = ASSET_PATH "meshes/shovel.txt",
39                 .mesh = {0},
40                 .use = &use_dig,
41         },
42 };
43
44 void client_item_init()
45 {
46         for (ItemType i = 0; i < COUNT_ITEM; i++)
47                 if (client_item_def[i].mesh_path)
48                         mesh_load(&client_item_def[i].mesh, client_item_def[i].mesh_path);
49 }
50
51 void client_item_deinit()
52 {
53         for (ItemType i = 0; i < COUNT_ITEM; i++)
54                 if (client_item_def[i].mesh_path)
55                         mesh_destroy(&client_item_def[i].mesh);
56 }
57
58 Mesh *client_item_mesh(ItemType type)
59 {
60         return client_item_def[type].mesh_path ? &client_item_def[type].mesh : NULL;
61 }