content.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. #ifndef _CONTENT_H_
  2. #define _CONTENT_H_
  3. #include "common.h"
  4. #include "array.h"
  5. #include <stdint.h>
  6. #define CONTENT_MAX 0x0FFF
  7. #define CONTENT_ARRAY_SIZE 0x1000
  8. /* the top nibble of content_t is a type identifier
  9. * this allows for 16 possible content types */
  10. #define CONTENT_TYPE_MASK 0xF000
  11. #define CONTENT_TYPE_BLOCK 0x0000
  12. #define CONTENT_TYPE_CLOTHES 0x1000
  13. #define CONTENT_TYPE_MOB 0x2000
  14. #define CONTENT_TYPE_TOOL 0x4000
  15. #define CONTENT_TYPE_CRAFTITEM 0x8000
  16. #define CONTENT_INDEX_BLOCK 0x00
  17. #define CONTENT_INDEX_CLOTHES 0x01
  18. #define CONTENT_INDEX_MOB 0x02
  19. #define CONTENT_INDEX_TOOL 0x04
  20. #define CONTENT_INDEX_CRAFTITEM 0x08
  21. #define CONTENT_TYPE(x) (x&CONTENT_TYPE_MASK)
  22. /* the universal "nothing" value */
  23. #define CONTENT_IGNORE 0x007F
  24. /* Parameter types */
  25. #define CPT_NONE 0x00
  26. #define CPT_LIGHT 0x01
  27. #define CPT_MINERAL 0x02
  28. #define CPT_FACEDIR_SIMPLE 0x03 /* chests and such */
  29. #define CPT_FACEDIR_WALLMOUNT 0x04 /* signs and such */
  30. #define CPT_FACEDIR_MANUAL 0x05 /* planks and such */
  31. #define CPT_LIQUID 0x06
  32. #define CPT_PLANTGROWTH 0x07
  33. #define CPT_ENCHANTMENT 0x08
  34. #define CPT_DROP 0x09
  35. #define CPT_BLOCKDATA 0x0A
  36. #define CPT_SPECIAL 0x0B
  37. /* material type */
  38. #define CMT_AIR 0x00
  39. #define CMT_WOOD 0x01
  40. #define CMT_TREE 0x02
  41. #define CMT_STONE 0x03
  42. #define CMT_LIQUID_SOURCE 0x04
  43. #define CMT_LIQUID 0x05
  44. #define CMT_PLANT 0x06
  45. #define CMT_DIRT 0x07
  46. #define CMT_GLASS 0x08
  47. #define CMT_FLESH 0x09
  48. #define CMT_BONE 0x0A
  49. /* the below are not for blocks */
  50. #define CMT_COTTON 0x0B
  51. #define CMT_CANVAS 0x0C
  52. #define CMT_FUR 0x0D
  53. #define CMT_LEATHER 0x0E
  54. #define CMT_ARMOUR 0x0F
  55. /* clothing types */
  56. #define CCT_NONE 0x00
  57. #define CCT_PANTS 0x01
  58. #define CCT_SHIRT 0x02
  59. #define CCT_HAT 0x03
  60. #define CCT_BOOTS 0x04
  61. #define CCT_JACKET 0x05
  62. #define CCT_BELT 0x06
  63. #define CCT_DECORATIVE 0x07
  64. #define CCT_MEDALLION 0x08
  65. /* tool types */
  66. #define CTT_NONE 0x00
  67. #define CTT_SPECIAL 0x01 /* special tools can't dig */
  68. #define CTT_AXE 0x02
  69. #define CTT_PICK 0x03
  70. #define CTT_SHOVEL 0x04
  71. #define CTT_SHEAR 0x05
  72. #define CTT_BUCKET 0x06
  73. #define CTT_SWORD 0x07
  74. #define CTT_SPEAR 0x08
  75. #define CTT_CLUB 0x09
  76. #define CTT_HAMMER 0x0A
  77. #define CTT_SAW 0x0B
  78. /* flags used for graphics materials */
  79. #define CMF_NONE 0x00
  80. #define CMF_ROTATE 0x01 /* rotate top/bottom with nodebox */
  81. #define CMF_TILED 0X02 /* for plantlike, use bottom/middle/top halves seperately */
  82. /* flags used for collision data */
  83. /* also determines the behaviour when pushed by a piston */
  84. #define CCD_NONE 0x0000
  85. #define CCD_WALKABLE 0x0001 /* can be walked through */
  86. #define CCD_SELECTABLE 0x0002 /* can be pointed at */
  87. #define CCD_TOOL_SELECTABLE 0x0004 /* can be pointed at with a tool, CCD_SELECTABLE applies this */
  88. #define CCD_CLIMBABLE 0x0008 /* think ladders */
  89. #define CCD_REPLACEABLE 0x0010 /* can be replaced by a material placed on/in it (old buildable_to) */
  90. #define CCD_CRUSHABLE 0x0020 /* will be obliterated if pushed against another node */
  91. #define CCD_DROPABLE 0x0040 /* may drop when above an upward-facing piston */
  92. #define CCD_SOLID 0x0080
  93. #define CCD_CRUSHED 0x0100 /* always obliterated when pushed */
  94. #define CCD_MOBSAFE 0x0200 /* destructive_mob_safe */
  95. #define CCD_UNJUMPABLE 0x0400
  96. /* draw types */
  97. #define CDT_AIRLIKE 0x00
  98. #define CDT_CUBELIKE 0x01
  99. #define CDT_RAILLIKE 0x02
  100. #define CDT_PLANTLIKE 0x03
  101. #define CDT_PLANTLIKE_FERN 0x04
  102. #define CDT_MELONLIKE 0x05
  103. #define CDT_LIQUID 0x06
  104. #define CDT_LIQUID_SOURCE 0x07
  105. #define CDT_NODEBOX 0x08
  106. #define CDT_GLASSLIKE 0x09
  107. #define CDT_TORCHLIKE 0x0A
  108. #define CDT_FENCELIKE 0x0B
  109. #define CDT_FIRELIKE 0x0C
  110. #define CDT_WALLLIKE 0x0D
  111. #define CDT_ROOFLIKE 0x0E
  112. #define CDT_LEAFLIKE 0x0F
  113. #define CDT_NODEBOX_META 0x10
  114. #define CDT_WIRELIKE 0x11
  115. #define CDT_3DWIRELIKE 0x12
  116. #define CDT_STAIRLIKE 0x13
  117. #define CDT_SLABLIKE 0x14
  118. #define CDT_TRUNKLIKE 0x15
  119. #define CDT_DIRTLIKE 0x16
  120. #define CDT_FLAGLIKE 0x17
  121. /* lighting info */
  122. #define CLM_BLOCKS 0x00
  123. #define CLM_BRIGHT 0x01 /* disable lighting */
  124. #define CLM_CLEAR 0x02 /* sunlight_propogates */
  125. #define CLM_TRANSLUCENT 0x03 /* light_propogates */
  126. /* digging effects */
  127. #define CDE_UNDIGGABLE 0x00
  128. #define CDE_DIGGABLE 0x01
  129. #define CDE_IGNORE_BORDERSTONE 0x08 /* borderstone_diggable */
  130. #define CDE_GIVE_INVENTORY 0x10 /* gives its inventory when dug */
  131. #define CDE_GIVE_INV_AON 0x20 /* all or nothing for inventory */
  132. /* circuits/energy type */
  133. #define CET_NONE 0x00
  134. #define CET_CONDUCTIVE 0x01
  135. #define CET_SOURCE 0x02
  136. #define CET_SWITCH 0x03
  137. #define CET_GATE 0x04
  138. #define CET_SINK 0x05
  139. /* texture types */
  140. #define CT_TOP0 0x00
  141. #define CT_TOP1 0x01
  142. #define CT_TOP2 0x02
  143. #define CT_TOP3 0x03
  144. #define CT_BOTTOM0 0x10
  145. #define CT_BOTTOM1 0x11
  146. #define CT_BOTTOM2 0x12
  147. #define CT_BOTTOM3 0x13
  148. #define CT_RIGHT0 0x20
  149. #define CT_RIGHT1 0x21
  150. #define CT_RIGHT2 0x22
  151. #define CT_RIGHT3 0x23
  152. #define CT_LEFT0 0x30
  153. #define CT_LEFT1 0x31
  154. #define CT_LEFT2 0x32
  155. #define CT_LEFT3 0x33
  156. #define CT_BACK0 0x40
  157. #define CT_BACK1 0x41
  158. #define CT_BACK2 0x42
  159. #define CT_BACK3 0x43
  160. #define CT_FRONT0 0x50
  161. #define CT_FRONT1 0x51
  162. #define CT_FRONT2 0x52
  163. #define CT_FRONT3 0x53
  164. #define CT_SIDES0 0x60
  165. #define CT_SIDES1 0x61
  166. #define CT_SIDES2 0x62
  167. #define CT_SIDES3 0x63
  168. #define CT_BASE0 0x70
  169. #define CT_BASE1 0x71
  170. #define CT_BASE2 0x72
  171. #define CT_BASE3 0x73
  172. #define CT_META_TOP0 0x80
  173. #define CT_META_TOP1 0x81
  174. #define CT_META_TOP2 0x82
  175. #define CT_META_TOP3 0x83
  176. #define CT_META_BOTTOM0 0x90
  177. #define CT_META_BOTTOM1 0x91
  178. #define CT_META_BOTTOM2 0x92
  179. #define CT_META_BOTTOM3 0x93
  180. #define CT_META_RIGHT0 0xA0
  181. #define CT_META_RIGHT1 0xA1
  182. #define CT_META_RIGHT2 0xA2
  183. #define CT_META_RIGHT3 0xA3
  184. #define CT_META_LEFT0 0xB0
  185. #define CT_META_LEFT1 0xB1
  186. #define CT_META_LEFT2 0xB2
  187. #define CT_META_LEFT3 0xB3
  188. #define CT_META_BACK0 0xC0
  189. #define CT_META_BACK1 0xC1
  190. #define CT_META_BACK2 0xC2
  191. #define CT_META_BACK3 0xC3
  192. #define CT_META_FRONT0 0xD0
  193. #define CT_META_FRONT1 0xD1
  194. #define CT_META_FRONT2 0xD2
  195. #define CT_META_FRONT3 0xD3
  196. #define CT_META_SIDES0 0xE0
  197. #define CT_META_SIDES1 0xE1
  198. #define CT_META_SIDES2 0xE2
  199. #define CT_META_SIDES3 0xE3
  200. #define CT_META_BASE0 0xF0
  201. #define CT_META_BASE1 0xF1
  202. #define CT_META_BASE2 0xF2
  203. #define CT_META_BASE3 0xF3
  204. #define CT_INVENTORY 0x100
  205. #define CMD_NONE 0x00
  206. #define CMD_TEXTURE 0x01
  207. #define CMD_COLOUR 0x02
  208. /* these map directly to MATOPT_ in materials */
  209. #define CMI_NONE 0x00
  210. #define CMI_BFCULL 0x02 /* back face culling */
  211. #define CMI_UPNORMAL 0x04 /* forces normals to up vector */
  212. #define CMI_ALPHA_BLEND 0x08 /* use alpha blending GL_ONE_MINUS_SRC_ALPHA */
  213. #define CMI_ADDITIVE_BLEND 0x10 /* use additive blending GL_ONE */
  214. #define CMI_ALPHA_TEST 0x20 /* semi-caps alpha values (signed distance field) */
  215. #define CMI_SDF_ALPHA 0x40 /* pseudo signed distance field */
  216. /* face text types */
  217. #define CFT_NONE 0x00
  218. #define CFT_INFO 0x01
  219. #define CFT_BOOKCONTENT 0x02
  220. #define CFT_OWNER 0x03
  221. #define CFT_INVOWNER 0x04
  222. #ifndef _HAVE_CONTENT_TYPE
  223. #define _HAVE_CONTENT_TYPE
  224. typedef uint16_t content_t;
  225. #endif
  226. #ifndef _HAVE_NODEBOX_TYPE
  227. #define _HAVE_NODEBOX_TYPE
  228. typedef struct nodebox_s {
  229. aabox_t box;
  230. v3_t angle;
  231. v3_t centre;
  232. } nodebox_t;
  233. #endif
  234. #ifndef _HAVE_ITEM_TYPE
  235. #define _HAVE_ITEM_TYPE
  236. typedef struct item_s {
  237. content_t content;
  238. uint16_t param1;
  239. uint16_t param2;
  240. } item_t;
  241. #endif
  242. #ifndef _HAVE_FACETEXT_TYPE
  243. #define _HAVE_FACETEXT_TYPE
  244. typedef struct facetext_s {
  245. uint16_t type;
  246. rectf_t pos;
  247. } facetext_t;
  248. #endif
  249. #ifndef _HAVE_BLOCKFEATURES_TYPE
  250. #define _HAVE_BLOCKFEATURES_TYPE
  251. typedef struct blockfeatures_s {
  252. uint8_t vertex_alpha;
  253. colour_t post_effect_colour;
  254. /* when dug/punched also affects this */
  255. pos_t onact_also_affects;
  256. /* can set the players home */
  257. uint8_t home;
  258. facetext_t facetexts[6];
  259. /* essentially "can mapgen put a tree/plant on this" */
  260. uint8_t is_ground_content;
  261. /* 1 - fire can spread to and destroy this
  262. * 2 - can be set on fire */
  263. uint8_t flammable;
  264. /* basically "can grass grow under this" */
  265. uint8_t air_equivalent;
  266. /* what happens if/when dug */
  267. uint16_t digging_info;
  268. /* if it has metadata, this is the metadata type */
  269. content_t metaid;
  270. struct {
  271. content_t wallmount; /* when placed on a wall */
  272. content_t floormount; /* when placed on a floor */
  273. content_t roofmount; /* when placed on a roof */
  274. /* special content for things like slabs combining into cubes,
  275. * walls connecting to blocks, or seeds growing to plants */
  276. content_t special;
  277. /* if locked/unlocked, replace with this */
  278. content_t lockstate;
  279. /* if power state changes powered/unpowerd, replace with this */
  280. content_t powerstate;
  281. } alternate;
  282. struct {
  283. /* liquid, both types of matching liquid */
  284. content_t source;
  285. content_t flowing;
  286. /* a value from 1-7, with 7 being thickest */
  287. uint8_t viscosity;
  288. } liquid;
  289. /* when dropped on dirt, place this instead of inserting in a parcel */
  290. struct {
  291. content_t block;
  292. /* if there's a ^block nearby, place this instead */
  293. content_t alternate;
  294. } ondrop;
  295. /* for circuits, the type of circuit object, and how much energy drops as it pases through */
  296. struct {
  297. uint8_t type;
  298. uint8_t drop;
  299. } energy;
  300. struct {
  301. content_t replace; /* when dug, this block will replace the dug block */
  302. content_t replace_requires; /* ^replacement will only occur if this block is nearby (3 node radius) */
  303. /* if a tool of param2 type is used, give this instead */
  304. item_t special_drop;
  305. } ondig;
  306. struct {
  307. content_t replace; /* when punched, replace with this block */
  308. uint8_t borderstone; /* if 0 ignore borderstone protection */
  309. } onpunch;
  310. struct {
  311. uint16_t max_height;
  312. /* when CPT_PLANTGROWTH < 8 digging gives this */
  313. content_t small_drop;
  314. /* when CPT_PLANTGROWTH > 7 digging gives this */
  315. content_t large_drop;
  316. /* the maximum number of large items given */
  317. uint16_t large_count;
  318. /* whether to also give small when large is given */
  319. uint8_t large_gives_small;
  320. /* if this spreads to trellis to continue growing, then this is the on-trellis id */
  321. content_t trellis_block;
  322. /* whether punching with fertilizer advances the growth rate */
  323. uint8_t fertilizer_affects;
  324. } plant;
  325. } blockfeatures_t;
  326. #endif
  327. #ifndef _HAVE_CLOTHESFEATURES_TYPE
  328. #define _HAVE_CLOTHESFEATURES_TYPE
  329. typedef struct clothesfeatures_s {
  330. /* the type of this clothing */
  331. uint8_t type;
  332. /* the strength as armour */
  333. float armour;
  334. /* the effectiveness against the cold zone */
  335. float warmth;
  336. /* the effectiveness against vacuum / space */
  337. float vacuum;
  338. /* the effectiveness against suffocation */
  339. float suffocate;
  340. /* this determines how fast the item wears out from use */
  341. uint8_t durability;
  342. /* for medallions, how much the affect durability of other items */
  343. float effect;
  344. } clothesfeatures_t;
  345. #endif
  346. #ifndef _HAVE_MOBFEATURES_TYPE
  347. #define _HAVE_MOBFEATURES_TYPE
  348. typedef struct mobfeatures_s {
  349. int stuff; /* TODO: mobfeatures_t */
  350. } mobfeatures_t;
  351. #endif
  352. #ifndef _HAVE_TOOLFEATURES_TYPE
  353. #define _HAVE_TOOLFEATURES_TYPE
  354. typedef struct toolfeatures_s {
  355. /* the type of this tool */
  356. uint8_t type;
  357. /* the number dropped on right click, -1 for all */
  358. int16_t drop_count;
  359. /* whether this tool can point at liquid nodes */
  360. uint8_t liquids_pointable;
  361. /* whether this tool should die when trying to pick up damaging nodes */
  362. uint8_t damaging_nodes_diggable;
  363. /* whether this tool has a punch effect, such as open doors */
  364. uint8_t has_punch_effect;
  365. /* whether this tool can lock/unlock nodes (1 for true, 2 for super) */
  366. uint8_t has_unlock_effect;
  367. /* whether this tool can rotate nodes */
  368. uint8_t has_rotate_effect;
  369. /* whether this tool can start fires */
  370. uint8_t has_fire_effect;
  371. /* the dig time of this tool */
  372. float dig_time;
  373. /* the level of the tool, this affects the amount of minerals etc */
  374. uint8_t level;
  375. /* used for eg. bows throwing an arrow */
  376. content_t thrown_item;
  377. } toolfeatures_t;
  378. #endif
  379. #ifndef _HAVE_CRAFTITEMFEATURES_TYPE
  380. #define _HAVE_CRAFTITEMFEATURES_TYPE
  381. typedef struct craftitemfeatures_s {
  382. /* whether the item can be stacked in inventory */
  383. uint8_t stackable;
  384. /* whether the item can be eaten/drank, must be non-zero for *_effect to work */
  385. uint8_t consumable;
  386. /* if an item has both hunger and health effects, it will
  387. * not affect health unless hunger is full
  388. * number of hunger points this will refill */
  389. int16_t hunger_effect;
  390. /* number of health points this will refill */
  391. int16_t health_effect;
  392. /* number of seconds will protect player against cold damage */
  393. int16_t cold_effect;
  394. /* will refill energy at double full speed for this many seconds */
  395. int16_t energy_effect;
  396. /* the number dropped on right click, -1 for all */
  397. int16_t drop_count;
  398. /* if this teleports the player home, -2 = no, -1 = default home
  399. * 0-7 for specific flag colours */
  400. int8_t teleports;
  401. /* used by mobs that are picked up */
  402. content_t drop_item;
  403. /* used by snowballs and such... things that are thrown */
  404. content_t thrown_item;
  405. /* used by arrows and such... things that are shot by a tool */
  406. content_t shot_item;
  407. } craftitemfeatures_t;
  408. #endif
  409. #ifndef _HAVE_CONTENTFEATURES_TYPE
  410. #define _HAVE_CONTENTFEATURES_TYPE
  411. typedef struct contentfeatures_s {
  412. content_t content;
  413. uint8_t param1_type;
  414. uint8_t param2_type;
  415. /* determines digging properties */
  416. uint8_t material_type;
  417. float hardness;
  418. char* description;
  419. /* graphics stuff */
  420. uint8_t draw_type;
  421. array_t materials;
  422. uint16_t materials_info;
  423. char* overlay;
  424. /* collision info, for players, mobs, piston pushes, digging, placing etc */
  425. array_t collision_boxes;
  426. uint16_t collision_info;
  427. /* same info about how light reacts on this */
  428. uint8_t light_data;
  429. uint8_t light_source;
  430. /* what is returned when this is dug, a primary item, and a secondary item
  431. * plus randomness for the extra item, and tool levels to obtain it */
  432. item_t dug_item;
  433. item_t extra_dug_item;
  434. int extra_dug_item_rarity;
  435. uint8_t extra_dug_item_min_level;
  436. uint8_t extra_dug_item_max_level;
  437. item_t cook_result;
  438. float fuel_time;
  439. /* wield it and use it, replaced with this */
  440. item_t onuse_replace;
  441. /* if it can be enchanted, it gives this */
  442. content_t enchanted_item;
  443. /* sound effects for the content */
  444. struct {
  445. char* access; /* formspec accessed */
  446. char* step; /* stepped on/in */
  447. char* dig; /* when dug or killed */
  448. char* place; /* when placed or spawned */
  449. char* punch; /* when punched */
  450. char* ambient; /* constant sound effect */
  451. char* use; /* when weilded and used */
  452. } sound;
  453. /* damage effects per second to players/mobs */
  454. struct {
  455. uint8_t hard; /* hard damage cannot be protected against */
  456. uint8_t suffocation;
  457. uint8_t temperature; /* hot/cold */
  458. uint8_t pressure; /* vacuum */
  459. } damage;
  460. /* the features for individual types */
  461. union {
  462. blockfeatures_t block;
  463. clothesfeatures_t clothes;
  464. mobfeatures_t mob;
  465. toolfeatures_t tool;
  466. craftitemfeatures_t craftitem;
  467. } data;
  468. } contentfeatures_t;
  469. #endif
  470. #ifdef _CONTENT_LOCAL
  471. /* defined in content.c */
  472. extern contentfeatures_t *contentfeatures[16];
  473. void content_defaults(contentfeatures_t *f);
  474. #endif
  475. /* defined in content.c */
  476. contentfeatures_t *content_features(content_t id);
  477. item_t *content_item(item_t *i, content_t content, uint8_t param1, uint8_t param2);
  478. aabox_t *content_box(aabox_t *b, float min_x, float min_y, float min_z, float max_x, float max_y, float max_z);
  479. facetext_t *content_facetext(facetext_t *f, uint16_t type, float x, float y, float w, float h);
  480. int content_init(void);
  481. void content_exit(void);
  482. /* defined in content_block.c */
  483. int content_block_init(void);
  484. /* defined in content_clothes.c */
  485. int content_clothes_init(void);
  486. /* defined in content_craftitem.c */
  487. int content_craftitem_init(void);
  488. /* defined in content_mob.c */
  489. int content_mob_init(void);
  490. /* defined in content_tool.c */
  491. int content_tool_init(void);
  492. /* defined in content_meshgen.c - dummies on server */
  493. void content_meshgen_textures(contentfeatures_t *f,...);
  494. #endif