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