content.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. /* lighting info */
  97. #define CLM_BLOCKS 0x00
  98. #define CLM_BRIGHT 0x01 /* disable lighting */
  99. #define CLM_CLEAR 0x02 /* sunlight_propogates */
  100. #define CLM_TRANSLUCENT 0x03 /* light_propogates */
  101. /* digging effects */
  102. #define CDE_UNDIGGABLE 0x00
  103. #define CDE_DIGGABLE 0x01
  104. #define CDE_IGNORE_BORDERSTONE 0x08 /* borderstone_diggable */
  105. #define CDE_GIVE_INVENTORY 0x10 /* gives its inventory when dug */
  106. #define CDE_GIVE_INV_AON 0x20 /* all or nothing for inventory */
  107. /* circuits/energy type */
  108. #define CET_NONE 0x00
  109. #define CET_CONDUCTIVE 0x01
  110. #define CET_SOURCE 0x02
  111. #define CET_SWITCH 0x03
  112. #define CET_GATE 0x04
  113. #define CET_SINK 0x05
  114. /* texture types */
  115. #define CT_TOP0 0x00
  116. #define CT_TOP1 0x01
  117. #define CT_TOP2 0x02
  118. #define CT_TOP3 0x03
  119. #define CT_BOTTOM0 0x10
  120. #define CT_BOTTOM1 0x11
  121. #define CT_BOTTOM2 0x12
  122. #define CT_BOTTOM3 0x13
  123. #define CT_RIGHT0 0x20
  124. #define CT_RIGHT1 0x21
  125. #define CT_RIGHT2 0x22
  126. #define CT_RIGHT3 0x23
  127. #define CT_LEFT0 0x30
  128. #define CT_LEFT1 0x31
  129. #define CT_LEFT2 0x32
  130. #define CT_LEFT3 0x33
  131. #define CT_BACK0 0x40
  132. #define CT_BACK1 0x41
  133. #define CT_BACK2 0x42
  134. #define CT_BACK3 0x43
  135. #define CT_FRONT0 0x50
  136. #define CT_FRONT1 0x51
  137. #define CT_FRONT2 0x52
  138. #define CT_FRONT3 0x53
  139. #define CT_BASE0 0x60
  140. #define CT_BASE1 0x61
  141. #define CT_BASE2 0x62
  142. #define CT_BASE3 0x63
  143. #define CT_INVENTORY 0x70
  144. #define CT_META_TOP0 0x80
  145. #define CT_META_TOP1 0x81
  146. #define CT_META_TOP2 0x82
  147. #define CT_META_TOP3 0x83
  148. #define CT_META_BOTTOM0 0x90
  149. #define CT_META_BOTTOM1 0x91
  150. #define CT_META_BOTTOM2 0x92
  151. #define CT_META_BOTTOM3 0x93
  152. #define CT_META_RIGHT0 0xA0
  153. #define CT_META_RIGHT1 0xA1
  154. #define CT_META_RIGHT2 0xA2
  155. #define CT_META_RIGHT3 0xA3
  156. #define CT_META_LEFT0 0xB0
  157. #define CT_META_LEFT1 0xB1
  158. #define CT_META_LEFT2 0xB2
  159. #define CT_META_LEFT3 0xB3
  160. #define CT_META_BACK0 0xC0
  161. #define CT_META_BACK1 0xC1
  162. #define CT_META_BACK2 0xC2
  163. #define CT_META_BACK3 0xC3
  164. #define CT_META_FRONT0 0xD0
  165. #define CT_META_FRONT1 0xD1
  166. #define CT_META_FRONT2 0xD2
  167. #define CT_META_FRONT3 0xD3
  168. #define CT_META_BASE0 0xE0
  169. #define CT_META_BASE1 0xE1
  170. #define CT_META_BASE2 0xE2
  171. #define CT_META_BASE3 0xE3
  172. /* face text types */
  173. #define CFT_NONE 0x00
  174. #define CFT_INFO 0x01
  175. #define CFT_BOOKCONTENT 0x02
  176. #define CFT_OWNER 0x03
  177. #define CFT_INVOWNER 0x04
  178. #ifndef _HAVE_CONTENT_TYPE
  179. #define _HAVE_CONTENT_TYPE
  180. typedef uint16_t content_t;
  181. #endif
  182. #ifndef _HAVE_NODEBOX_TYPE
  183. #define _HAVE_NODEBOX_TYPE
  184. typedef struct nodebox_s {
  185. aabox_t box;
  186. v3_t angle;
  187. v3_t centre;
  188. } nodebox_t;
  189. #endif
  190. #ifndef _HAVE_ITEM_TYPE
  191. #define _HAVE_ITEM_TYPE
  192. typedef struct item_s {
  193. content_t content;
  194. uint16_t param1;
  195. uint16_t param2;
  196. } item_t;
  197. #endif
  198. #ifndef _HAVE_FACETEXT_TYPE
  199. #define _HAVE_FACETEXT_TYPE
  200. typedef struct facetext_s {
  201. uint16_t type;
  202. rectf_t pos;
  203. } facetext_t;
  204. #endif
  205. #ifndef _HAVE_BLOCKFEATURES_TYPE
  206. #define _HAVE_BLOCKFEATURES_TYPE
  207. typedef struct blockfeatures_s {
  208. uint8_t vertex_alpha;
  209. colour_t post_effect_colour;
  210. /* when dug/punched also affects this */
  211. pos_t onact_also_affects;
  212. /* can set the players home */
  213. uint8_t home;
  214. facetext_t facetexts[6];
  215. /* essentially "can mapgen put a tree/plant on this" */
  216. uint8_t is_ground_content;
  217. /* 1 - fire can spread to and destroy this
  218. * 2 - can be set on fire */
  219. uint8_t flammable;
  220. /* basically "can grass grow under this" */
  221. uint8_t air_equivalent;
  222. /* what happens if/when dug */
  223. uint16_t digging_info;
  224. /* if it has metadata, this is the metadata type */
  225. content_t metaid;
  226. struct {
  227. content_t wallmount; /* when placed on a wall */
  228. content_t floormount; /* when placed on a floor */
  229. content_t roofmount; /* when placed on a roof */
  230. /* special content for things like slabs combining into cubes,
  231. * walls connecting to blocks, or seeds growing to plants */
  232. content_t special;
  233. /* if locked/unlocked, replace with this */
  234. content_t lockstate;
  235. /* if power state changes powered/unpowerd, replace with this */
  236. content_t powerstate;
  237. } alternate;
  238. struct {
  239. /* liquid, both types of matching liquid */
  240. content_t source;
  241. content_t flowing;
  242. /* a value from 1-7, with 7 being thickest */
  243. uint8_t viscosity;
  244. } liquid;
  245. /* when dropped on dirt, place this instead of inserting in a parcel */
  246. struct {
  247. content_t block;
  248. /* if there's a ^block nearby, place this instead */
  249. content_t alternate;
  250. } ondrop;
  251. /* for circuits, the type of circuit object, and how much energy drops as it pases through */
  252. struct {
  253. uint8_t type;
  254. uint8_t drop;
  255. } energy;
  256. struct {
  257. content_t replace; /* when dug, this block will replace the dug block */
  258. content_t replace_requires; /* ^replacement will only occur if this block is nearby (3 node radius) */
  259. /* if a tool of param2 type is used, give this instead */
  260. item_t special_drop;
  261. } ondig;
  262. struct {
  263. content_t replace; /* when punched, replace with this block */
  264. uint8_t borderstone; /* if 0 ignore borderstone protection */
  265. } onpunch;
  266. struct {
  267. uint16_t max_height;
  268. /* when CPT_PLANTGROWTH < 8 digging gives this */
  269. content_t small_drop;
  270. /* when CPT_PLANTGROWTH > 7 digging gives this */
  271. content_t large_drop;
  272. /* the maximum number of large items given */
  273. uint16_t large_count;
  274. /* whether to also give small when large is given */
  275. uint8_t large_gives_small;
  276. /* if this spreads to trellis to continue growing, then this is the on-trellis id */
  277. content_t trellis_block;
  278. /* whether punching with fertilizer advances the growth rate */
  279. uint8_t fertilizer_affects;
  280. } plant;
  281. } blockfeatures_t;
  282. #endif
  283. #ifndef _HAVE_CLOTHESFEATURES_TYPE
  284. #define _HAVE_CLOTHESFEATURES_TYPE
  285. typedef struct clothesfeatures_s {
  286. /* the type of this clothing */
  287. uint8_t type;
  288. /* the strength as armour */
  289. float armour;
  290. /* the effectiveness against the cold zone */
  291. float warmth;
  292. /* the effectiveness against vacuum / space */
  293. float vacuum;
  294. /* the effectiveness against suffocation */
  295. float suffocate;
  296. /* this determines how fast the item wears out from use */
  297. uint8_t durability;
  298. /* for medallions, how much the affect durability of other items */
  299. float effect;
  300. } clothesfeatures_t;
  301. #endif
  302. #ifndef _HAVE_MOBFEATURES_TYPE
  303. #define _HAVE_MOBFEATURES_TYPE
  304. typedef struct mobfeatures_s {
  305. int stuff; /* TODO: mobfeatures_t */
  306. } mobfeatures_t;
  307. #endif
  308. #ifndef _HAVE_TOOLFEATURES_TYPE
  309. #define _HAVE_TOOLFEATURES_TYPE
  310. typedef struct toolfeatures_s {
  311. /* the type of this tool */
  312. uint8_t type;
  313. /* the number dropped on right click, -1 for all */
  314. int16_t drop_count;
  315. /* whether this tool can point at liquid nodes */
  316. uint8_t liquids_pointable;
  317. /* whether this tool should die when trying to pick up damaging nodes */
  318. uint8_t damaging_nodes_diggable;
  319. /* whether this tool has a punch effect, such as open doors */
  320. uint8_t has_punch_effect;
  321. /* whether this tool can lock/unlock nodes (1 for true, 2 for super) */
  322. uint8_t has_unlock_effect;
  323. /* whether this tool can rotate nodes */
  324. uint8_t has_rotate_effect;
  325. /* whether this tool can start fires */
  326. uint8_t has_fire_effect;
  327. /* the dig time of this tool */
  328. float dig_time;
  329. /* the level of the tool, this affects the amount of minerals etc */
  330. uint8_t level;
  331. /* used for eg. bows throwing an arrow */
  332. content_t thrown_item;
  333. } toolfeatures_t;
  334. #endif
  335. #ifndef _HAVE_CRAFTITEMFEATURES_TYPE
  336. #define _HAVE_CRAFTITEMFEATURES_TYPE
  337. typedef struct craftitemfeatures_s {
  338. /* whether the item can be stacked in inventory */
  339. uint8_t stackable;
  340. /* whether the item can be eaten/drank, must be non-zero for *_effect to work */
  341. uint8_t consumable;
  342. /* if an item has both hunger and health effects, it will
  343. * not affect health unless hunger is full
  344. * number of hunger points this will refill */
  345. int16_t hunger_effect;
  346. /* number of health points this will refill */
  347. int16_t health_effect;
  348. /* number of seconds will protect player against cold damage */
  349. int16_t cold_effect;
  350. /* will refill energy at double full speed for this many seconds */
  351. int16_t energy_effect;
  352. /* the number dropped on right click, -1 for all */
  353. int16_t drop_count;
  354. /* if this teleports the player home, -2 = no, -1 = default home
  355. * 0-7 for specific flag colours */
  356. int8_t teleports;
  357. /* used by mobs that are picked up */
  358. content_t drop_item;
  359. /* used by snowballs and such... things that are thrown */
  360. content_t thrown_item;
  361. /* used by arrows and such... things that are shot by a tool */
  362. content_t shot_item;
  363. } craftitemfeatures_t;
  364. #endif
  365. #ifndef _HAVE_CONTENTFEATURES_TYPE
  366. #define _HAVE_CONTENTFEATURES_TYPE
  367. typedef struct contentfeatures_s {
  368. content_t content;
  369. uint8_t param1_type;
  370. uint8_t param2_type;
  371. /* determines digging properties */
  372. uint8_t material_type;
  373. float hardness;
  374. char* description;
  375. /* graphics stuff */
  376. array_t materials;
  377. uint16_t materials_info;
  378. char* overlay;
  379. /* collision info, for players, mobs, piston pushes, digging, placing etc */
  380. array_t collision_boxes;
  381. uint16_t collision_info;
  382. /* if an item has a nodebox style wield, use this */
  383. array_t wield_boxes;
  384. /* same info about how light reacts on this */
  385. uint8_t light_data;
  386. uint8_t light_source;
  387. /* what is returned when this is dug, a primary item, and a secondary item
  388. * plus randomness for the extra item, and tool levels to obtain it */
  389. item_t dug_item;
  390. item_t extra_dug_item;
  391. int extra_dug_item_rarity;
  392. uint8_t extra_dug_item_min_level;
  393. uint8_t extra_dug_item_max_level;
  394. item_t cook_result;
  395. float fuel_time;
  396. /* wield it and use it, replaced with this */
  397. item_t onuse_replace;
  398. /* if it can be enchanted, it gives this */
  399. content_t enchanted_item;
  400. /* sound effects for the content */
  401. struct {
  402. char* access; /* formspec accessed */
  403. char* step; /* stepped on/in */
  404. char* dig; /* when dug or killed */
  405. char* place; /* when placed or spawned */
  406. char* punch; /* when punched */
  407. char* ambient; /* constant sound effect */
  408. char* use; /* when weilded and used */
  409. } sound;
  410. /* damage effects per second to players/mobs */
  411. struct {
  412. uint8_t hard; /* hard damage cannot be protected against */
  413. uint8_t suffocation;
  414. uint8_t temperature; /* hot/cold */
  415. uint8_t pressure; /* vacuum */
  416. } damage;
  417. /* the features for individual types */
  418. union {
  419. blockfeatures_t block;
  420. clothesfeatures_t clothes;
  421. mobfeatures_t mob;
  422. toolfeatures_t tool;
  423. craftitemfeatures_t craftitem;
  424. } data;
  425. } contentfeatures_t;
  426. #endif
  427. #ifdef _CONTENT_LOCAL
  428. /* defined in content.c */
  429. extern contentfeatures_t *contentfeatures[16];
  430. void content_defaults(contentfeatures_t *f);
  431. #endif
  432. /* defined in content.c */
  433. contentfeatures_t *content_features(content_t id);
  434. item_t *content_item(item_t *i, content_t content, uint8_t param1, uint8_t param2);
  435. 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);
  436. facetext_t *content_facetext(facetext_t *f, uint16_t type, float x, float y, float w, float h);
  437. int content_init(void);
  438. void content_exit(void);
  439. /* defined in content_block.c */
  440. int content_block_init(void);
  441. /* defined in content_clothes.c */
  442. int content_clothes_init(void);
  443. /* defined in content_craftitem.c */
  444. int content_craftitem_init(void);
  445. /* defined in content_mob.c */
  446. int content_mob_init(void);
  447. /* defined in content_tool.c */
  448. int content_tool_init(void);
  449. #endif