3 Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU 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.
20 #include "content_mapnode.h"
22 #include "irrlichttypes.h"
26 #include "nameidmapping.h"
30 Legacy node content type IDs
32 0x000...0x07f (0...127): param2 is fully usable
33 126 and 127 are reserved (CONTENT_AIR and CONTENT_IGNORE).
34 0x800...0xfff (2048...4095): higher 4 bits of param2 are not usable
36 #define CONTENT_STONE 0
37 #define CONTENT_WATER 2
38 #define CONTENT_TORCH 3
39 #define CONTENT_WATERSOURCE 9
40 #define CONTENT_SIGN_WALL 14
41 #define CONTENT_CHEST 15
42 #define CONTENT_FURNACE 16
43 #define CONTENT_LOCKABLE_CHEST 17
44 #define CONTENT_FENCE 21
45 #define CONTENT_RAIL 30
46 #define CONTENT_LADDER 31
47 #define CONTENT_LAVA 32
48 #define CONTENT_LAVASOURCE 33
49 #define CONTENT_GRASS 0x800 //1
50 #define CONTENT_TREE 0x801 //4
51 #define CONTENT_LEAVES 0x802 //5
52 #define CONTENT_GRASS_FOOTSTEPS 0x803 //6
53 #define CONTENT_MESE 0x804 //7
54 #define CONTENT_MUD 0x805 //8
55 #define CONTENT_CLOUD 0x806 //10
56 #define CONTENT_COALSTONE 0x807 //11
57 #define CONTENT_WOOD 0x808 //12
58 #define CONTENT_SAND 0x809 //13
59 #define CONTENT_COBBLE 0x80a //18
60 #define CONTENT_STEEL 0x80b //19
61 #define CONTENT_GLASS 0x80c //20
62 #define CONTENT_MOSSYCOBBLE 0x80d //22
63 #define CONTENT_GRAVEL 0x80e //23
64 #define CONTENT_SANDSTONE 0x80f //24
65 #define CONTENT_CACTUS 0x810 //25
66 #define CONTENT_BRICK 0x811 //26
67 #define CONTENT_CLAY 0x812 //27
68 #define CONTENT_PAPYRUS 0x813 //28
69 #define CONTENT_BOOKSHELF 0x814 //29
70 #define CONTENT_JUNGLETREE 0x815
71 #define CONTENT_JUNGLEGRASS 0x816
72 #define CONTENT_NC 0x817
73 #define CONTENT_NC_RB 0x818
74 #define CONTENT_APPLE 0x819
75 #define CONTENT_SAPLING 0x820
78 A conversion table for backwards compatibility.
79 Maps <=v19 content types to current ones.
80 Should never be touched.
82 content_t trans_table_19[21][2] = {
86 {CONTENT_GRASS_FOOTSTEPS, 6},
90 {CONTENT_COALSTONE, 11},
96 {CONTENT_MOSSYCOBBLE, 22},
98 {CONTENT_SANDSTONE, 24},
102 {CONTENT_PAPYRUS, 28},
103 {CONTENT_BOOKSHELF, 29},
106 MapNode mapnode_translate_from_internal(MapNode n_from, u8 version)
108 MapNode result = n_from;
111 content_t c_from = n_from.getContent();
112 for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
114 if(trans_table_19[i][0] == c_from)
116 result.setContent(trans_table_19[i][1]);
123 MapNode mapnode_translate_to_internal(MapNode n_from, u8 version)
125 MapNode result = n_from;
128 content_t c_from = n_from.getContent();
129 for(u32 i=0; i<sizeof(trans_table_19)/sizeof(trans_table_19[0]); i++)
131 if(trans_table_19[i][1] == c_from)
133 result.setContent(trans_table_19[i][0]);
141 void content_mapnode_get_name_id_mapping(NameIdMapping *nimap)
143 nimap->set(0, "default:stone");
144 nimap->set(2, "default:water_flowing");
145 nimap->set(3, "default:torch");
146 nimap->set(9, "default:water_source");
147 nimap->set(14, "default:sign_wall");
148 nimap->set(15, "default:chest");
149 nimap->set(16, "default:furnace");
150 nimap->set(17, "default:chest_locked");
151 nimap->set(21, "default:fence_wood");
152 nimap->set(30, "default:rail");
153 nimap->set(31, "default:ladder");
154 nimap->set(32, "default:lava_flowing");
155 nimap->set(33, "default:lava_source");
156 nimap->set(0x800, "default:dirt_with_grass");
157 nimap->set(0x801, "default:tree");
158 nimap->set(0x802, "default:leaves");
159 nimap->set(0x803, "default:dirt_with_grass_footsteps");
160 nimap->set(0x804, "default:mese");
161 nimap->set(0x805, "default:dirt");
162 nimap->set(0x806, "default:cloud");
163 nimap->set(0x807, "default:coalstone");
164 nimap->set(0x808, "default:wood");
165 nimap->set(0x809, "default:sand");
166 nimap->set(0x80a, "default:cobble");
167 nimap->set(0x80b, "default:steelblock");
168 nimap->set(0x80c, "default:glass");
169 nimap->set(0x80d, "default:mossycobble");
170 nimap->set(0x80e, "default:gravel");
171 nimap->set(0x80f, "default:sandstone");
172 nimap->set(0x810, "default:cactus");
173 nimap->set(0x811, "default:brick");
174 nimap->set(0x812, "default:clay");
175 nimap->set(0x813, "default:papyrus");
176 nimap->set(0x814, "default:bookshelf");
177 nimap->set(0x815, "default:jungletree");
178 nimap->set(0x816, "default:junglegrass");
179 nimap->set(0x817, "default:nyancat");
180 nimap->set(0x818, "default:nyancat_rainbow");
181 nimap->set(0x819, "default:apple");
182 nimap->set(0x820, "default:sapling");
184 nimap->set(CONTENT_IGNORE, "ignore");
185 nimap->set(CONTENT_AIR, "air");
193 old_to_new["CONTENT_STONE"] = "default:stone";
194 old_to_new["CONTENT_WATER"] = "default:water_flowing";
195 old_to_new["CONTENT_TORCH"] = "default:torch";
196 old_to_new["CONTENT_WATERSOURCE"] = "default:water_source";
197 old_to_new["CONTENT_SIGN_WALL"] = "default:sign_wall";
198 old_to_new["CONTENT_CHEST"] = "default:chest";
199 old_to_new["CONTENT_FURNACE"] = "default:furnace";
200 old_to_new["CONTENT_LOCKABLE_CHEST"] = "default:locked_chest";
201 old_to_new["CONTENT_FENCE"] = "default:wooden_fence";
202 old_to_new["CONTENT_RAIL"] = "default:rail";
203 old_to_new["CONTENT_LADDER"] = "default:ladder";
204 old_to_new["CONTENT_LAVA"] = "default:lava_flowing";
205 old_to_new["CONTENT_LAVASOURCE"] = "default:lava_source";
206 old_to_new["CONTENT_GRASS"] = "default:dirt_with_grass";
207 old_to_new["CONTENT_TREE"] = "default:tree";
208 old_to_new["CONTENT_LEAVES"] = "default:leaves";
209 old_to_new["CONTENT_GRASS_FOOTSTEPS"] = "default:dirt_with_grass_footsteps";
210 old_to_new["CONTENT_MESE"] = "default:mese";
211 old_to_new["CONTENT_MUD"] = "default:dirt";
212 old_to_new["CONTENT_CLOUD"] = "default:cloud";
213 old_to_new["CONTENT_COALSTONE"] = "default:coalstone";
214 old_to_new["CONTENT_WOOD"] = "default:wood";
215 old_to_new["CONTENT_SAND"] = "default:sand";
216 old_to_new["CONTENT_COBBLE"] = "default:cobble";
217 old_to_new["CONTENT_STEEL"] = "default:steel";
218 old_to_new["CONTENT_GLASS"] = "default:glass";
219 old_to_new["CONTENT_MOSSYCOBBLE"] = "default:mossycobble";
220 old_to_new["CONTENT_GRAVEL"] = "default:gravel";
221 old_to_new["CONTENT_SANDSTONE"] = "default:sandstone";
222 old_to_new["CONTENT_CACTUS"] = "default:cactus";
223 old_to_new["CONTENT_BRICK"] = "default:brick";
224 old_to_new["CONTENT_CLAY"] = "default:clay";
225 old_to_new["CONTENT_PAPYRUS"] = "default:papyrus";
226 old_to_new["CONTENT_BOOKSHELF"] = "default:bookshelf";
227 old_to_new["CONTENT_JUNGLETREE"] = "default:jungletree";
228 old_to_new["CONTENT_JUNGLEGRASS"] = "default:junglegrass";
229 old_to_new["CONTENT_NC"] = "default:nyancat";
230 old_to_new["CONTENT_NC_RB"] = "default:nyancat_rainbow";
231 old_to_new["CONTENT_APPLE"] = "default:apple";
232 old_to_new["CONTENT_SAPLING"] = "default:sapling";
234 old_to_new["CONTENT_IGNORE"] = "ignore";
235 old_to_new["CONTENT_AIR"] = "air";
237 std::string get(const std::string &old)
239 std::map<std::string, std::string>::const_iterator i;
240 i = old_to_new.find(old);
241 if(i == old_to_new.end())
246 std::map<std::string, std::string> old_to_new;
249 NewNameGetter newnamegetter;
251 std::string content_mapnode_get_new_name(const std::string &oldname)
253 return newnamegetter.get(oldname);
256 content_t legacy_get_id(const std::string &oldname, INodeDefManager *ndef)
258 std::string newname = content_mapnode_get_new_name(oldname);
260 return CONTENT_IGNORE;
262 bool found = ndef->getId(newname, id);
264 return CONTENT_IGNORE;