content_mapnode.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "content_mapnode.h"
  17. #include "irrlichttypes_bloated.h"
  18. #include "mapnode.h"
  19. #include "nodedef.h"
  20. #include "nameidmapping.h"
  21. #include "util/string.h"
  22. /*
  23. Legacy node content type IDs
  24. Ranges:
  25. 0x000...0x07f (0...127): param2 is fully usable
  26. 126 and 127 are reserved (CONTENT_AIR and CONTENT_IGNORE).
  27. 0x800...0xfff (2048...4095): higher 4 bits of param2 are not usable
  28. */
  29. #define CONTENT_STONE 0
  30. #define CONTENT_WATER 2
  31. #define CONTENT_TORCH 3
  32. #define CONTENT_WATERSOURCE 9
  33. #define CONTENT_SIGN_WALL 14
  34. #define CONTENT_CHEST 15
  35. #define CONTENT_FURNACE 16
  36. #define CONTENT_LOCKABLE_CHEST 17
  37. #define CONTENT_FENCE 21
  38. #define CONTENT_RAIL 30
  39. #define CONTENT_LADDER 31
  40. #define CONTENT_LAVA 32
  41. #define CONTENT_LAVASOURCE 33
  42. #define CONTENT_GRASS 0x800 //1
  43. #define CONTENT_TREE 0x801 //4
  44. #define CONTENT_LEAVES 0x802 //5
  45. #define CONTENT_GRASS_FOOTSTEPS 0x803 //6
  46. #define CONTENT_MESE 0x804 //7
  47. #define CONTENT_MUD 0x805 //8
  48. #define CONTENT_CLOUD 0x806 //10
  49. #define CONTENT_COALSTONE 0x807 //11
  50. #define CONTENT_WOOD 0x808 //12
  51. #define CONTENT_SAND 0x809 //13
  52. #define CONTENT_COBBLE 0x80a //18
  53. #define CONTENT_STEEL 0x80b //19
  54. #define CONTENT_GLASS 0x80c //20
  55. #define CONTENT_MOSSYCOBBLE 0x80d //22
  56. #define CONTENT_GRAVEL 0x80e //23
  57. #define CONTENT_SANDSTONE 0x80f //24
  58. #define CONTENT_CACTUS 0x810 //25
  59. #define CONTENT_BRICK 0x811 //26
  60. #define CONTENT_CLAY 0x812 //27
  61. #define CONTENT_PAPYRUS 0x813 //28
  62. #define CONTENT_BOOKSHELF 0x814 //29
  63. #define CONTENT_JUNGLETREE 0x815
  64. #define CONTENT_JUNGLEGRASS 0x816
  65. #define CONTENT_NC 0x817
  66. #define CONTENT_NC_RB 0x818
  67. #define CONTENT_APPLE 0x819
  68. #define CONTENT_SAPLING 0x820
  69. /*
  70. A conversion table for backwards compatibility.
  71. Maps <=v19 content types to current ones.
  72. Should never be touched.
  73. */
  74. content_t trans_table_19[21][2] = {
  75. {CONTENT_GRASS, 1},
  76. {CONTENT_TREE, 4},
  77. {CONTENT_LEAVES, 5},
  78. {CONTENT_GRASS_FOOTSTEPS, 6},
  79. {CONTENT_MESE, 7},
  80. {CONTENT_MUD, 8},
  81. {CONTENT_CLOUD, 10},
  82. {CONTENT_COALSTONE, 11},
  83. {CONTENT_WOOD, 12},
  84. {CONTENT_SAND, 13},
  85. {CONTENT_COBBLE, 18},
  86. {CONTENT_STEEL, 19},
  87. {CONTENT_GLASS, 20},
  88. {CONTENT_MOSSYCOBBLE, 22},
  89. {CONTENT_GRAVEL, 23},
  90. {CONTENT_SANDSTONE, 24},
  91. {CONTENT_CACTUS, 25},
  92. {CONTENT_BRICK, 26},
  93. {CONTENT_CLAY, 27},
  94. {CONTENT_PAPYRUS, 28},
  95. {CONTENT_BOOKSHELF, 29},
  96. };
  97. MapNode mapnode_translate_to_internal(MapNode n_from, u8 version)
  98. {
  99. MapNode result = n_from;
  100. if(version <= 19)
  101. {
  102. content_t c_from = n_from.getContent();
  103. for (const auto &tt_i : trans_table_19) {
  104. if (tt_i[1] == c_from) {
  105. result.setContent(tt_i[0]);
  106. break;
  107. }
  108. }
  109. }
  110. return result;
  111. }
  112. void content_mapnode_get_name_id_mapping(NameIdMapping *nimap)
  113. {
  114. nimap->set(0, "default:stone");
  115. nimap->set(2, "default:water_flowing");
  116. nimap->set(3, "default:torch");
  117. nimap->set(9, "default:water_source");
  118. nimap->set(14, "default:sign_wall");
  119. nimap->set(15, "default:chest");
  120. nimap->set(16, "default:furnace");
  121. nimap->set(17, "default:chest_locked");
  122. nimap->set(21, "default:fence_wood");
  123. nimap->set(30, "default:rail");
  124. nimap->set(31, "default:ladder");
  125. nimap->set(32, "default:lava_flowing");
  126. nimap->set(33, "default:lava_source");
  127. nimap->set(0x800, "default:dirt_with_grass");
  128. nimap->set(0x801, "default:tree");
  129. nimap->set(0x802, "default:leaves");
  130. nimap->set(0x803, "default:dirt_with_grass_footsteps");
  131. nimap->set(0x804, "default:mese");
  132. nimap->set(0x805, "default:dirt");
  133. nimap->set(0x806, "default:cloud");
  134. nimap->set(0x807, "default:coalstone");
  135. nimap->set(0x808, "default:wood");
  136. nimap->set(0x809, "default:sand");
  137. nimap->set(0x80a, "default:cobble");
  138. nimap->set(0x80b, "default:steelblock");
  139. nimap->set(0x80c, "default:glass");
  140. nimap->set(0x80d, "default:mossycobble");
  141. nimap->set(0x80e, "default:gravel");
  142. nimap->set(0x80f, "default:sandstone");
  143. nimap->set(0x810, "default:cactus");
  144. nimap->set(0x811, "default:brick");
  145. nimap->set(0x812, "default:clay");
  146. nimap->set(0x813, "default:papyrus");
  147. nimap->set(0x814, "default:bookshelf");
  148. nimap->set(0x815, "default:jungletree");
  149. nimap->set(0x816, "default:junglegrass");
  150. nimap->set(0x817, "default:nyancat");
  151. nimap->set(0x818, "default:nyancat_rainbow");
  152. nimap->set(0x819, "default:apple");
  153. nimap->set(0x820, "default:sapling");
  154. // Static types
  155. nimap->set(CONTENT_IGNORE, "ignore");
  156. nimap->set(CONTENT_AIR, "air");
  157. }