]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/client/client_item.c
3e6d47b4cb0cc513d5ff5accc9456cf9dd0ce4c1
[dragonblocks_alpha.git] / src / client / client_item.c
1 #include "client/client_item.h"
2 #include "client/interact.h"
3 #include "node.h"
4
5 static bool use_dig(__attribute__((unused)) ItemStack *stack)
6 {
7         return interact_pointed.exists
8                 && (node_defs[interact_pointed.node].dig_class & item_defs[stack->type].dig_class);
9 }
10
11 ClientItemDef client_item_defs[COUNT_ITEM] = {
12         // unknown
13         {
14                 .mesh_path = RESSOURCE_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 = RESSOURCE_PATH "meshes/pickaxe.txt",
27                 .mesh = {0},
28                 .use = &use_dig,
29         },
30         // axe
31         {
32                 .mesh_path = RESSOURCE_PATH "meshes/axe.txt",
33                 .mesh = {0},
34                 .use = &use_dig,
35         },
36 };
37
38 void client_item_init()
39 {
40         for (ItemType i = 0; i < COUNT_ITEM; i++)
41                 if (client_item_defs[i].mesh_path)
42                         mesh_load(&client_item_defs[i].mesh, client_item_defs[i].mesh_path);
43 }
44
45 void client_item_deinit()
46 {
47         for (ItemType i = 0; i < COUNT_ITEM; i++)
48                 if (client_item_defs[i].mesh_path)
49                         mesh_destroy(&client_item_defs[i].mesh);
50 }
51
52 Mesh *client_item_mesh(ItemType type)
53 {
54         return client_item_defs[type].mesh_path ? &client_item_defs[type].mesh : NULL;
55 }