From df8346ef4d70ba7c717c4c7b9c783df876378ca8 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Wed, 16 Nov 2011 14:08:31 +0200 Subject: [PATCH] Do not expose CONTENT_* stuff in content_mapnode.h and use a name converter wrapper in old code --- src/client.cpp | 10 -- src/content_craft.cpp | 235 +++++++++++++++++++------------------- src/content_mapnode.cpp | 135 +++++++++++++++++++++- src/content_mapnode.h | 80 ++----------- src/content_nodemeta.cpp | 14 ++- src/environment.cpp | 35 +++--- src/map.cpp | 2 +- src/mapblock.cpp | 21 ---- src/mapgen.cpp | 240 +++++++++++++++++++++------------------ src/mapgen.h | 5 +- src/scriptapi.cpp | 1 - src/server.cpp | 42 +++---- src/server.h | 2 +- src/test.cpp | 2 +- 14 files changed, 447 insertions(+), 377 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 661aecda5..716dac931 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -900,16 +900,6 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) block = new MapBlock(&m_env.getMap(), p, this); block->deSerialize(istr, ser_version); sector->insertBlock(block); - - //DEBUG - /*NodeMod mod; - mod.type = NODEMOD_CHANGECONTENT; - mod.param = CONTENT_MESE; - block->setTempMod(v3s16(8,10,8), mod); - block->setTempMod(v3s16(8,9,8), mod); - block->setTempMod(v3s16(8,8,8), mod); - block->setTempMod(v3s16(8,7,8), mod); - block->setTempMod(v3s16(8,6,8), mod);*/ } #if 0 diff --git a/src/content_craft.cpp b/src/content_craft.cpp index 024fc6f09..3c972835e 100644 --- a/src/content_craft.cpp +++ b/src/content_craft.cpp @@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content_mapnode.h" #include "player.h" #include "mapnode.h" // For content_t +#include "gamedef.h" /* items: actually *items[9] @@ -29,20 +30,22 @@ with this program; if not, write to the Free Software Foundation, Inc., */ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) { + INodeDefManager *ndef = gamedef->ndef(); + // Wood { ItemSpec specs[9]; - specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_TREE); + specs[0] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_TREE")); if(checkItemCombination(items, specs)) { - return new MaterialItem(gamedef, CONTENT_WOOD, 4); + return new MaterialItem(gamedef, LEGN(ndef, "CONTENT_WOOD"), 4); } } // Stick { ItemSpec specs[9]; - specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[0] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); if(checkItemCombination(items, specs)) { return new CraftItem(gamedef, "Stick", 4); @@ -60,24 +63,24 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) specs[8] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) { - return new MaterialItem(gamedef, CONTENT_FENCE, 2); + return new MaterialItem(gamedef, LEGN(ndef, "CONTENT_FENCE"), 2); } } // Sign { ItemSpec specs[9]; - specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[0] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[1] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[2] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[3] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[4] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[5] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) { //return new MapBlockObjectItem(gamedef, "Sign"); - return new MaterialItem(gamedef, CONTENT_SIGN_WALL, 1); + return new MaterialItem(gamedef, LEGN(ndef, "CONTENT_SIGN_WALL"), 1); } } @@ -88,16 +91,16 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) specs[3] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) { - return new MaterialItem(gamedef, CONTENT_TORCH, 4); + return new MaterialItem(gamedef, LEGN(ndef, "CONTENT_TORCH"), 4); } } // Wooden pick { ItemSpec specs[9]; - specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[0] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[1] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[2] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); specs[4] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) @@ -109,9 +112,9 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) // Stone pick { ItemSpec specs[9]; - specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); - specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); - specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); + specs[0] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); + specs[1] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); + specs[2] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); specs[4] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) @@ -137,9 +140,9 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) // Mese pick { ItemSpec specs[9]; - specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_MESE); - specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_MESE); - specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_MESE); + specs[0] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_MESE")); + specs[1] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_MESE")); + specs[2] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_MESE")); specs[4] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) @@ -151,7 +154,7 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) // Wooden shovel { ItemSpec specs[9]; - specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[1] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); specs[4] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) @@ -163,7 +166,7 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) // Stone shovel { ItemSpec specs[9]; - specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); + specs[1] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); specs[4] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) @@ -187,9 +190,9 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) // Wooden axe { ItemSpec specs[9]; - specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[0] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[1] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[3] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); specs[4] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) @@ -201,9 +204,9 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) // Stone axe { ItemSpec specs[9]; - specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); - specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); - specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); + specs[0] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); + specs[1] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); + specs[3] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); specs[4] = ItemSpec(ITEM_CRAFT, "Stick"); specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) @@ -229,8 +232,8 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) // Wooden sword { ItemSpec specs[9]; - specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[1] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[4] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) { @@ -241,8 +244,8 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) // Stone sword { ItemSpec specs[9]; - specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); - specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); + specs[1] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); + specs[4] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); specs[7] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) { @@ -276,59 +279,59 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot"); if(checkItemCombination(items, specs)) { - return new MaterialItem(gamedef, CONTENT_RAIL, 15); + return new MaterialItem(gamedef, LEGN(ndef, "CONTENT_RAIL"), 15); } } // Chest { ItemSpec specs[9]; - specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[0] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[1] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[2] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[3] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[5] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[6] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[7] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[8] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); if(checkItemCombination(items, specs)) { - return new MaterialItem(gamedef, CONTENT_CHEST, 1); + return new MaterialItem(gamedef, LEGN(ndef, "CONTENT_CHEST"), 1); } } // Locking Chest { ItemSpec specs[9]; - specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[0] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[1] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[2] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[3] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); specs[4] = ItemSpec(ITEM_CRAFT, "steel_ingot"); - specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[5] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[6] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[7] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[8] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); if(checkItemCombination(items, specs)) { - return new MaterialItem(gamedef, CONTENT_LOCKABLE_CHEST, 1); + return new MaterialItem(gamedef, LEGN(ndef, "CONTENT_LOCKABLE_CHEST"), 1); } } // Furnace { ItemSpec specs[9]; - specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); - specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); - specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); - specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); - specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); - specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); - specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); - specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_COBBLE); + specs[0] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); + specs[1] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); + specs[2] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); + specs[3] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); + specs[5] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); + specs[6] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); + specs[7] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); + specs[8] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_COBBLE")); if(checkItemCombination(items, specs)) { - return new MaterialItem(gamedef, CONTENT_FURNACE, 1); + return new MaterialItem(gamedef, LEGN(ndef, "CONTENT_FURNACE"), 1); } } @@ -346,20 +349,20 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) specs[8] = ItemSpec(ITEM_CRAFT, "steel_ingot"); if(checkItemCombination(items, specs)) { - return new MaterialItem(gamedef, CONTENT_STEEL, 1); + return new MaterialItem(gamedef, LEGN(ndef, "CONTENT_STEEL"), 1); } } // Sandstone { ItemSpec specs[9]; - specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND); - specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND); - specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND); - specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_SAND); + specs[3] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_SAND")); + specs[4] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_SAND")); + specs[6] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_SAND")); + specs[7] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_SAND")); if(checkItemCombination(items, specs)) { - return new MaterialItem(gamedef, CONTENT_SANDSTONE, 1); + return new MaterialItem(gamedef, LEGN(ndef, "CONTENT_SANDSTONE"), 1); } } @@ -372,7 +375,7 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) specs[7] = ItemSpec(ITEM_CRAFT, "lump_of_clay"); if(checkItemCombination(items, specs)) { - return new MaterialItem(gamedef, CONTENT_CLAY, 1); + return new MaterialItem(gamedef, LEGN(ndef, "CONTENT_CLAY"), 1); } } @@ -385,16 +388,16 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) specs[7] = ItemSpec(ITEM_CRAFT, "clay_brick"); if(checkItemCombination(items, specs)) { - return new MaterialItem(gamedef, CONTENT_BRICK, 1); + return new MaterialItem(gamedef, LEGN(ndef, "CONTENT_BRICK"), 1); } } // Paper { ItemSpec specs[9]; - specs[3] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS); - specs[4] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS); - specs[5] = ItemSpec(ITEM_MATERIAL, CONTENT_PAPYRUS); + specs[3] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_PAPYRUS")); + specs[4] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_PAPYRUS")); + specs[5] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_PAPYRUS")); if(checkItemCombination(items, specs)) { return new CraftItem(gamedef, "paper", 1); @@ -416,18 +419,18 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) // Book shelf { ItemSpec specs[9]; - specs[0] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[1] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[2] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[0] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[1] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[2] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); specs[3] = ItemSpec(ITEM_CRAFT, "book"); specs[4] = ItemSpec(ITEM_CRAFT, "book"); specs[5] = ItemSpec(ITEM_CRAFT, "book"); - specs[6] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[7] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); - specs[8] = ItemSpec(ITEM_MATERIAL, CONTENT_WOOD); + specs[6] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[7] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); + specs[8] = ItemSpec(ITEM_MATERIAL, LEGN(ndef, "CONTENT_WOOD")); if(checkItemCombination(items, specs)) { - return new MaterialItem(gamedef, CONTENT_BOOKSHELF, 1); + return new MaterialItem(gamedef, LEGN(ndef, "CONTENT_BOOKSHELF"), 1); } } @@ -443,7 +446,7 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) specs[8] = ItemSpec(ITEM_CRAFT, "Stick"); if(checkItemCombination(items, specs)) { - return new MaterialItem(gamedef, CONTENT_LADDER, 1); + return new MaterialItem(gamedef, LEGN(ndef, "CONTENT_LADDER"), 1); } } @@ -466,6 +469,8 @@ InventoryItem *craft_get_result(InventoryItem **items, IGameDef *gamedef) void craft_set_creative_inventory(Player *player, IGameDef *gamedef) { + INodeDefManager *ndef = gamedef->ndef(); + player->resetInventory(); // Give some good tools @@ -496,29 +501,29 @@ void craft_set_creative_inventory(Player *player, IGameDef *gamedef) // CONTENT_IGNORE-terminated list content_t material_items[] = { - CONTENT_TORCH, - CONTENT_COBBLE, - CONTENT_MUD, - CONTENT_STONE, - CONTENT_SAND, - CONTENT_SANDSTONE, - CONTENT_CLAY, - CONTENT_BRICK, - CONTENT_TREE, - CONTENT_LEAVES, - CONTENT_CACTUS, - CONTENT_PAPYRUS, - CONTENT_BOOKSHELF, - CONTENT_GLASS, - CONTENT_FENCE, - CONTENT_RAIL, - CONTENT_MESE, - CONTENT_WATERSOURCE, - CONTENT_CLOUD, - CONTENT_CHEST, - CONTENT_FURNACE, - CONTENT_SIGN_WALL, - CONTENT_LAVASOURCE, + LEGN(ndef, "CONTENT_TORCH"), + LEGN(ndef, "CONTENT_COBBLE"), + LEGN(ndef, "CONTENT_MUD"), + LEGN(ndef, "CONTENT_STONE"), + LEGN(ndef, "CONTENT_SAND"), + LEGN(ndef, "CONTENT_SANDSTONE"), + LEGN(ndef, "CONTENT_CLAY"), + LEGN(ndef, "CONTENT_BRICK"), + LEGN(ndef, "CONTENT_TREE"), + LEGN(ndef, "CONTENT_LEAVES"), + LEGN(ndef, "CONTENT_CACTUS"), + LEGN(ndef, "CONTENT_PAPYRUS"), + LEGN(ndef, "CONTENT_BOOKSHELF"), + LEGN(ndef, "CONTENT_GLASS"), + LEGN(ndef, "CONTENT_FENCE"), + LEGN(ndef, "CONTENT_RAIL"), + LEGN(ndef, "CONTENT_MESE"), + LEGN(ndef, "CONTENT_WATERSOURCE"), + LEGN(ndef, "CONTENT_CLOUD"), + LEGN(ndef, "CONTENT_CHEST"), + LEGN(ndef, "CONTENT_FURNACE"), + LEGN(ndef, "CONTENT_SIGN_WALL"), + LEGN(ndef, "CONTENT_LAVASOURCE"), CONTENT_IGNORE }; @@ -535,18 +540,18 @@ void craft_set_creative_inventory(Player *player, IGameDef *gamedef) } #if 0 - assert(USEFUL_CONTENT_COUNT <= PLAYER_INVENTORY_SIZE); + assert(USEFUL_LEGN(ndef, "CONTENT_COUNT") <= PLAYER_INVENTORY_SIZE); // add torch first - InventoryItem *item = new MaterialItem(gamedef, CONTENT_TORCH, 1); + InventoryItem *item = new MaterialItem(gamedef, LEGN(ndef, "CONTENT_TORCH"), 1); player->inventory.addItem("main", item); // Then others - for(u16 i=0; indef(); + { InventoryItem *item = new ToolItem(gamedef, "SteelPick", 0); void* r = player->inventory.addItem("main", item); assert(r == NULL); } { - InventoryItem *item = new MaterialItem(gamedef, CONTENT_TORCH, 99); + InventoryItem *item = new MaterialItem(gamedef, LEGN(ndef, "CONTENT_TORCH"), 99); void* r = player->inventory.addItem("main", item); assert(r == NULL); } @@ -585,22 +592,22 @@ void craft_give_initial_stuff(Player *player, IGameDef *gamedef) assert(r == NULL); } { - InventoryItem *item = new MaterialItem(gamedef, CONTENT_COBBLE, 99); + InventoryItem *item = new MaterialItem(gamedef, LEGN(ndef, "CONTENT_COBBLE"), 99); void* r = player->inventory.addItem("main", item); assert(r == NULL); } /*{ - InventoryItem *item = new MaterialItem(gamedef, CONTENT_MESE, 6); + InventoryItem *item = new MaterialItem(gamedef, LEGN(ndef, "CONTENT_MESE"), 6); void* r = player->inventory.addItem("main", item); assert(r == NULL); } { - InventoryItem *item = new MaterialItem(gamedef, CONTENT_COALSTONE, 6); + InventoryItem *item = new MaterialItem(gamedef, LEGN(ndef, "CONTENT_COALSTONE"), 6); void* r = player->inventory.addItem("main", item); assert(r == NULL); } { - InventoryItem *item = new MaterialItem(gamedef, CONTENT_WOOD, 6); + InventoryItem *item = new MaterialItem(gamedef, LEGN(ndef, "CONTENT_WOOD"), 6); void* r = player->inventory.addItem("main", item); assert(r == NULL); } @@ -628,7 +635,7 @@ void craft_give_initial_stuff(Player *player, IGameDef *gamedef) }*/ /*// Give some other stuff { - InventoryItem *item = new MaterialItem(gamedef, CONTENT_TREE, 999); + InventoryItem *item = new MaterialItem(gamedef, LEGN(ndef, "CONTENT_TREE"), 999); bool r = player->inventory.addItem("main", item); assert(r == true); }*/ diff --git a/src/content_mapnode.cpp b/src/content_mapnode.cpp index fdb75d468..eb8e4002a 100644 --- a/src/content_mapnode.cpp +++ b/src/content_mapnode.cpp @@ -25,6 +25,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "nodedef.h" #include "utility.h" #include "nameidmapping.h" +#include + +/* + Legacy node definitions +*/ #define WATER_ALPHA 160 @@ -91,6 +96,54 @@ void setGlassLikeMaterialProperties(MaterialProperties &mprop, float toughness) mprop.cuttability = -1.0; } +/* + Legacy node content type IDs + Ranges: + 0x000...0x07f (0...127): param2 is fully usable + 126 and 127 are reserved (CONTENT_AIR and CONTENT_IGNORE). + 0x800...0xfff (2048...4095): higher 4 bytes of param2 are not usable +*/ +#define CONTENT_STONE 0 +#define CONTENT_WATER 2 +#define CONTENT_TORCH 3 +#define CONTENT_WATERSOURCE 9 +#define CONTENT_SIGN_WALL 14 +#define CONTENT_CHEST 15 +#define CONTENT_FURNACE 16 +#define CONTENT_LOCKABLE_CHEST 17 +#define CONTENT_FENCE 21 +#define CONTENT_RAIL 30 +#define CONTENT_LADDER 31 +#define CONTENT_LAVA 32 +#define CONTENT_LAVASOURCE 33 +#define CONTENT_GRASS 0x800 //1 +#define CONTENT_TREE 0x801 //4 +#define CONTENT_LEAVES 0x802 //5 +#define CONTENT_GRASS_FOOTSTEPS 0x803 //6 +#define CONTENT_MESE 0x804 //7 +#define CONTENT_MUD 0x805 //8 +#define CONTENT_CLOUD 0x806 //10 +#define CONTENT_COALSTONE 0x807 //11 +#define CONTENT_WOOD 0x808 //12 +#define CONTENT_SAND 0x809 //13 +#define CONTENT_COBBLE 0x80a //18 +#define CONTENT_STEEL 0x80b //19 +#define CONTENT_GLASS 0x80c //20 +#define CONTENT_MOSSYCOBBLE 0x80d //22 +#define CONTENT_GRAVEL 0x80e //23 +#define CONTENT_SANDSTONE 0x80f //24 +#define CONTENT_CACTUS 0x810 //25 +#define CONTENT_BRICK 0x811 //26 +#define CONTENT_CLAY 0x812 //27 +#define CONTENT_PAPYRUS 0x813 //28 +#define CONTENT_BOOKSHELF 0x814 //29 +#define CONTENT_JUNGLETREE 0x815 +#define CONTENT_JUNGLEGRASS 0x816 +#define CONTENT_NC 0x817 +#define CONTENT_NC_RB 0x818 +#define CONTENT_APPLE 0x819 +#define CONTENT_SAPLING 0x820 + /* A conversion table for backwards compatibility. Maps <=v19 content types to current ones. @@ -202,7 +255,87 @@ void content_mapnode_get_name_id_mapping(NameIdMapping *nimap) nimap->set(CONTENT_AIR, "air"); } -// See header for description +class NewNameGetter +{ +public: + NewNameGetter() + { + old_to_new["CONTENT_STONE"] = ""; + old_to_new["CONTENT_WATER"] = ""; + old_to_new["CONTENT_TORCH"] = ""; + old_to_new["CONTENT_WATERSOURCE"] = ""; + old_to_new["CONTENT_SIGN_WALL"] = ""; + old_to_new["CONTENT_CHEST"] = ""; + old_to_new["CONTENT_FURNACE"] = ""; + old_to_new["CONTENT_LOCKABLE_CHEST"] = ""; + old_to_new["CONTENT_FENCE"] = ""; + old_to_new["CONTENT_RAIL"] = ""; + old_to_new["CONTENT_LADDER"] = ""; + old_to_new["CONTENT_LAVA"] = ""; + old_to_new["CONTENT_LAVASOURCE"] = ""; + old_to_new["CONTENT_GRASS"] = ""; + old_to_new["CONTENT_TREE"] = ""; + old_to_new["CONTENT_LEAVES"] = ""; + old_to_new["CONTENT_GRASS_FOOTSTEPS"] = ""; + old_to_new["CONTENT_MESE"] = ""; + old_to_new["CONTENT_MUD"] = ""; + old_to_new["CONTENT_CLOUD"] = ""; + old_to_new["CONTENT_COALSTONE"] = ""; + old_to_new["CONTENT_WOOD"] = ""; + old_to_new["CONTENT_SAND"] = ""; + old_to_new["CONTENT_COBBLE"] = ""; + old_to_new["CONTENT_STEEL"] = ""; + old_to_new["CONTENT_GLASS"] = ""; + old_to_new["CONTENT_MOSSYCOBBLE"] = ""; + old_to_new["CONTENT_GRAVEL"] = ""; + old_to_new["CONTENT_SANDSTONE"] = ""; + old_to_new["CONTENT_CACTUS"] = ""; + old_to_new["CONTENT_BRICK"] = ""; + old_to_new["CONTENT_CLAY"] = ""; + old_to_new["CONTENT_PAPYRUS"] = ""; + old_to_new["CONTENT_BOOKSHELF"] = ""; + old_to_new["CONTENT_JUNGLETREE"] = ""; + old_to_new["CONTENT_JUNGLEGRASS"] = ""; + old_to_new["CONTENT_NC"] = ""; + old_to_new["CONTENT_NC_RB"] = ""; + old_to_new["CONTENT_APPLE"] = ""; + old_to_new["CONTENT_SAPLING"] = ""; + // Just in case + old_to_new["CONTENT_IGNORE"] = "ignore"; + old_to_new["CONTENT_AIR"] = "air"; + } + std::string get(const std::string &old) + { + std::map::const_iterator i; + i = old_to_new.find(old); + if(i == old_to_new.end()) + return ""; + return i->second; + } +private: + std::map old_to_new; +}; + +NewNameGetter newnamegetter; + +std::string content_mapnode_get_new_name(const std::string &oldname) +{ + return newnamegetter.get(oldname); +} + +content_t legacy_get_id(const std::string &oldname, INodeDefManager *ndef) +{ + std::string newname = content_mapnode_get_new_name(oldname); + if(newname == "") + return CONTENT_IGNORE; + content_t id; + bool found = ndef->getId(newname, id); + if(!found) + return CONTENT_IGNORE; + return id; +} + +// Initialize default (legacy) node definitions void content_mapnode_init(IWritableNodeDefManager *nodemgr) { content_t i; diff --git a/src/content_mapnode.h b/src/content_mapnode.h index dea653901..57be6da72 100644 --- a/src/content_mapnode.h +++ b/src/content_mapnode.h @@ -21,20 +21,14 @@ with this program; if not, write to the Free Software Foundation, Inc., #define CONTENT_MAPNODE_HEADER #include "mapnode.h" -class IWritableNodeDefManager; /* - Initialize default node definitions - - This accesses tsrc; if it is non-NULL, textures are set - for the nodes. - - Client first calls this with tsrc=NULL to run some - unit tests and stuff, then it runs this again with tsrc - defined to get the textures. - - Server only calls this once with tsrc=NULL. + Legacy node definitions */ + +class IWritableNodeDefManager; + +// Initialize default (legacy) node definitions void content_mapnode_init(IWritableNodeDefManager *nodemgr); // Backwards compatibility for non-extended content types in v19 @@ -42,67 +36,15 @@ extern content_t trans_table_19[21][2]; MapNode mapnode_translate_from_internal(MapNode n_from, u8 version); MapNode mapnode_translate_to_internal(MapNode n_from, u8 version); -// Get legacy node name mapping +// Get legacy node name mapping for loading old blocks class NameIdMapping; void content_mapnode_get_name_id_mapping(NameIdMapping *nimap); -/* - Node content type IDs - Ranges: -*/ - -// 0x000...0x07f (0...127): param2 is fully usable -// 126 and 127 are reserved. -// Use these sparingly, only when the extra space in param2 might be needed. -// Add a space when there is unused space between numbers. -#define CONTENT_STONE 0 - -#define CONTENT_WATER 2 -#define CONTENT_TORCH 3 - -#define CONTENT_WATERSOURCE 9 - -#define CONTENT_SIGN_WALL 14 -#define CONTENT_CHEST 15 -#define CONTENT_FURNACE 16 -#define CONTENT_LOCKABLE_CHEST 17 - -#define CONTENT_FENCE 21 - -#define CONTENT_RAIL 30 -#define CONTENT_LADDER 31 -#define CONTENT_LAVA 32 -#define CONTENT_LAVASOURCE 33 - -// 0x800...0xfff (2048...4095): higher 4 bytes of param2 are not usable -#define CONTENT_GRASS 0x800 //1 -#define CONTENT_TREE 0x801 //4 -#define CONTENT_LEAVES 0x802 //5 -#define CONTENT_GRASS_FOOTSTEPS 0x803 //6 -#define CONTENT_MESE 0x804 //7 -#define CONTENT_MUD 0x805 //8 -// Pretty much useless, clouds won't be drawn this way -#define CONTENT_CLOUD 0x806 //10 -#define CONTENT_COALSTONE 0x807 //11 -#define CONTENT_WOOD 0x808 //12 -#define CONTENT_SAND 0x809 //13 -#define CONTENT_COBBLE 0x80a //18 -#define CONTENT_STEEL 0x80b //19 -#define CONTENT_GLASS 0x80c //20 -#define CONTENT_MOSSYCOBBLE 0x80d //22 -#define CONTENT_GRAVEL 0x80e //23 -#define CONTENT_SANDSTONE 0x80f //24 -#define CONTENT_CACTUS 0x810 //25 -#define CONTENT_BRICK 0x811 //26 -#define CONTENT_CLAY 0x812 //27 -#define CONTENT_PAPYRUS 0x813 //28 -#define CONTENT_BOOKSHELF 0x814 //29 -#define CONTENT_JUNGLETREE 0x815 -#define CONTENT_JUNGLEGRASS 0x816 -#define CONTENT_NC 0x817 -#define CONTENT_NC_RB 0x818 -#define CONTENT_APPLE 0x819 -#define CONTENT_SAPLING 0x820 +// Convert "CONTENT_STONE"-style names to dynamic ids +std::string content_mapnode_get_new_name(const std::string &oldname); +class INodeDefManager; +content_t legacy_get_id(const std::string &oldname, INodeDefManager *ndef); +#define LEGN(ndef, oldname) legacy_get_id(oldname, ndef) #endif diff --git a/src/content_nodemeta.cpp b/src/content_nodemeta.cpp index 17b4a3da4..ab9849668 100644 --- a/src/content_nodemeta.cpp +++ b/src/content_nodemeta.cpp @@ -19,10 +19,14 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content_nodemeta.h" #include "inventory.h" -#include "content_mapnode.h" #include "log.h" #include "utility.h" +#define NODEMETA_SIGN 14 +#define NODEMETA_CHEST 15 +#define NODEMETA_LOCKABLE_CHEST 17 +#define NODEMETA_FURNACE 16 + /* SignNodeMetadata */ @@ -38,7 +42,7 @@ SignNodeMetadata::SignNodeMetadata(IGameDef *gamedef, std::string text): } u16 SignNodeMetadata::typeId() const { - return CONTENT_SIGN_WALL; + return NODEMETA_SIGN; } NodeMetadata* SignNodeMetadata::create(std::istream &is, IGameDef *gamedef) { @@ -79,7 +83,7 @@ ChestNodeMetadata::~ChestNodeMetadata() } u16 ChestNodeMetadata::typeId() const { - return CONTENT_CHEST; + return NODEMETA_CHEST; } NodeMetadata* ChestNodeMetadata::create(std::istream &is, IGameDef *gamedef) { @@ -142,7 +146,7 @@ LockingChestNodeMetadata::~LockingChestNodeMetadata() } u16 LockingChestNodeMetadata::typeId() const { - return CONTENT_LOCKABLE_CHEST; + return NODEMETA_LOCKABLE_CHEST; } NodeMetadata* LockingChestNodeMetadata::create(std::istream &is, IGameDef *gamedef) { @@ -215,7 +219,7 @@ FurnaceNodeMetadata::~FurnaceNodeMetadata() } u16 FurnaceNodeMetadata::typeId() const { - return CONTENT_FURNACE; + return NODEMETA_FURNACE; } NodeMetadata* FurnaceNodeMetadata::clone(IGameDef *gamedef) { diff --git a/src/environment.cpp b/src/environment.cpp index e03007341..2c5c2d2b8 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -637,7 +637,7 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime) #if 1 // Test something: // Convert all mud under proper day lighting to grass - if(n.getContent() == CONTENT_MUD) + if(n.getContent() == LEGN(m_gamedef->ndef(), "CONTENT_MUD")) { if(dtime_s > 300) { @@ -645,7 +645,7 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime) if(m_gamedef->ndef()->get(n_top).air_equivalent && n_top.getLight(LIGHTBANK_DAY, m_gamedef->ndef()) >= 13) { - n.setContent(CONTENT_GRASS); + n.setContent(LEGN(m_gamedef->ndef(), "CONTENT_GRASS")); m_map->addNodeWithEvent(p, n); } } @@ -803,9 +803,9 @@ void ServerEnvironment::step(float dtime) v3s16 bottompos = floatToInt(playerpos + v3f(0,-BS/4,0), BS); try{ MapNode n = m_map->getNode(bottompos); - if(n.getContent() == CONTENT_GRASS) + if(n.getContent() == LEGN(m_gamedef->ndef(), "CONTENT_GRASS")) { - n.setContent(CONTENT_GRASS_FOOTSTEPS); + n.setContent(LEGN(m_gamedef->ndef(), "CONTENT_GRASS_FOOTSTEPS")); m_map->setNode(bottompos, n); } } @@ -1008,7 +1008,7 @@ void ServerEnvironment::step(float dtime) Test something: Convert mud under proper lighting to grass */ - if(n.getContent() == CONTENT_MUD) + if(n.getContent() == LEGN(m_gamedef->ndef(), "CONTENT_MUD")) { if(myrand()%20 == 0) { @@ -1017,7 +1017,7 @@ void ServerEnvironment::step(float dtime) n_top.getLightBlend(getDayNightRatio(), m_gamedef->ndef()) >= 13) { - n.setContent(CONTENT_GRASS); + n.setContent(LEGN(m_gamedef->ndef(), "CONTENT_GRASS")); m_map->addNodeWithEvent(p, n); } } @@ -1025,14 +1025,14 @@ void ServerEnvironment::step(float dtime) /* Convert grass into mud if under something else than air */ - if(n.getContent() == CONTENT_GRASS) + if(n.getContent() == LEGN(m_gamedef->ndef(), "CONTENT_GRASS")) { //if(myrand()%20 == 0) { MapNode n_top = m_map->getNodeNoEx(p+v3s16(0,1,0)); if(m_gamedef->ndef()->get(n_top).air_equivalent == false) { - n.setContent(CONTENT_MUD); + n.setContent(LEGN(m_gamedef->ndef(), "CONTENT_MUD")); m_map->addNodeWithEvent(p, n); } } @@ -1040,8 +1040,8 @@ void ServerEnvironment::step(float dtime) /* Rats spawn around regular trees */ - if(n.getContent() == CONTENT_TREE || - n.getContent() == CONTENT_JUNGLETREE) + if(n.getContent() == LEGN(m_gamedef->ndef(), "CONTENT_TREE") || + n.getContent() == LEGN(m_gamedef->ndef(), "CONTENT_JUNGLETREE")) { if(myrand()%200 == 0 && active_object_count_wider == 0) { @@ -1049,7 +1049,7 @@ void ServerEnvironment::step(float dtime) 0, myrand_range(-2, 2)); MapNode n1 = m_map->getNodeNoEx(p1); MapNode n1b = m_map->getNodeNoEx(p1+v3s16(0,-1,0)); - if(n1b.getContent() == CONTENT_GRASS && + if(n1b.getContent() == LEGN(m_gamedef->ndef(), "CONTENT_GRASS") && n1.getContent() == CONTENT_AIR) { v3f pos = intToFloat(p1, BS); @@ -1061,8 +1061,8 @@ void ServerEnvironment::step(float dtime) /* Fun things spawn in caves and dungeons */ - if(n.getContent() == CONTENT_STONE || - n.getContent() == CONTENT_MOSSYCOBBLE) + if(n.getContent() == LEGN(m_gamedef->ndef(), "CONTENT_STONE") || + n.getContent() == LEGN(m_gamedef->ndef(), "CONTENT_MOSSYCOBBLE")) { if(myrand()%200 == 0 && active_object_count_wider == 0) { @@ -1106,7 +1106,7 @@ void ServerEnvironment::step(float dtime) /* Make trees from saplings! */ - if(n.getContent() == CONTENT_SAPLING) + if(n.getContent() == LEGN(m_gamedef->ndef(), "CONTENT_SAPLING")) { if(myrand()%50 == 0) { @@ -1119,7 +1119,8 @@ void ServerEnvironment::step(float dtime) v3s16 tree_blockp = getNodeBlockPos(tree_p); vmanip.initialEmerge(tree_blockp - v3s16(1,1,1), tree_blockp + v3s16(1,1,1)); bool is_apple_tree = myrand()%4 == 0; - mapgen::make_tree(vmanip, tree_p, is_apple_tree); + mapgen::make_tree(vmanip, tree_p, is_apple_tree, + m_gamedef->ndef()); vmanip.blitBackAll(&modified_blocks); // update lighting @@ -2126,9 +2127,9 @@ void ClientEnvironment::step(float dtime) v3s16 bottompos = floatToInt(playerpos + v3f(0,-BS/4,0), BS); try{ MapNode n = m_map->getNode(bottompos); - if(n.getContent() == CONTENT_GRASS) + if(n.getContent() == LEGN(m_gamedef->ndef(), "CONTENT_GRASS")) { - n.setContent(CONTENT_GRASS_FOOTSTEPS); + n.setContent(LEGN(m_gamedef->ndef(), "CONTENT_GRASS_FOOTSTEPS")); m_map->setNode(bottompos, n); // Update mesh on client if(m_map->mapType() == MAPTYPE_CLIENT) diff --git a/src/map.cpp b/src/map.cpp index 2de4377d8..81befd081 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -2058,7 +2058,7 @@ void ServerMap::initBlockMake(mapgen::BlockMakeData *data, v3s16 blockpos) data->no_op = false; data->seed = m_seed; data->blockpos = blockpos; - data->nodemgr = m_gamedef->ndef(); + data->nodedef = m_gamedef->ndef(); /* Create the whole area of this and the neighboring blocks diff --git a/src/mapblock.cpp b/src/mapblock.cpp index 06ce9282f..76b8a5e79 100644 --- a/src/mapblock.cpp +++ b/src/mapblock.cpp @@ -275,7 +275,6 @@ bool MapBlock::propagateSunlight(core::map & light_sources, else { MapNode n = getNode(v3s16(x, MAP_BLOCKSIZE-1, z)); - //if(n.getContent() == CONTENT_WATER || n.getContent() == CONTENT_WATERSOURCE) if(m_gamedef->ndef()->get(n).sunlight_propagates == false) { no_sunlight = true; @@ -331,26 +330,6 @@ bool MapBlock::propagateSunlight(core::map & light_sources, } else if(nodemgr->get(n).light_propagates == false) { - /*// DEPRECATED TODO: REMOVE - if(grow_grass) - { - bool upper_is_air = false; - try - { - if(getNodeParent(pos+v3s16(0,1,0)).getContent() == CONTENT_AIR) - upper_is_air = true; - } - catch(InvalidPositionException &e) - { - } - // Turn mud into grass - if(upper_is_air && n.getContent() == CONTENT_MUD - && current_light == LIGHT_SUN) - { - n.d = CONTENT_GRASS; - } - }*/ - // A solid object is on the way. stopped_to_solid_object = true; diff --git a/src/mapgen.cpp b/src/mapgen.cpp index 2b8050260..5e7349a3b 100644 --- a/src/mapgen.cpp +++ b/src/mapgen.cpp @@ -19,7 +19,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "mapgen.h" #include "voxel.h" -#include "content_mapnode.h" #include "noise.h" #include "mapblock.h" #include "map.h" @@ -27,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc., //#include "serverobject.h" #include "content_sao.h" #include "nodedef.h" +#include "content_mapnode.h" // For content_mapnode_get_new_name namespace mapgen { @@ -68,8 +68,8 @@ static s16 find_ground_level_clever(VoxelManipulator &vmanip, v2s16 p2d) { MapNode &n = vmanip.m_data[i]; if(content_walkable(n.d) - && n.getContent() != CONTENT_TREE - && n.getContent() != CONTENT_LEAVES) + && n.getContent() != LEGN(ndef, "CONTENT_TREE") + && n.getContent() != LEGN(ndef, "CONTENT_LEAVES")) break; vmanip.m_area.add_y(em, i, -1); @@ -81,11 +81,12 @@ static s16 find_ground_level_clever(VoxelManipulator &vmanip, v2s16 p2d) } #endif -void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, bool is_apple_tree) +void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, + bool is_apple_tree, INodeDefManager *ndef) { - MapNode treenode(CONTENT_TREE); - MapNode leavesnode(CONTENT_LEAVES); - MapNode applenode(CONTENT_APPLE); + MapNode treenode(LEGN(ndef, "CONTENT_TREE")); + MapNode leavesnode(LEGN(ndef, "CONTENT_LEAVES")); + MapNode applenode(LEGN(ndef, "CONTENT_APPLE")); s16 trunk_h = myrand_range(4, 5); v3s16 p1 = p0; @@ -160,10 +161,11 @@ void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, bool is_apple_tree) } } -static void make_jungletree(VoxelManipulator &vmanip, v3s16 p0) +static void make_jungletree(VoxelManipulator &vmanip, v3s16 p0, + INodeDefManager *ndef) { - MapNode treenode(CONTENT_JUNGLETREE); - MapNode leavesnode(CONTENT_LEAVES); + MapNode treenode(LEGN(ndef, "CONTENT_JUNGLETREE")); + MapNode leavesnode(LEGN(ndef, "CONTENT_LEAVES")); for(s16 x=-1; x<=1; x++) for(s16 z=-1; z<=1; z++) @@ -246,9 +248,10 @@ static void make_jungletree(VoxelManipulator &vmanip, v3s16 p0) } } -void make_papyrus(VoxelManipulator &vmanip, v3s16 p0) +void make_papyrus(VoxelManipulator &vmanip, v3s16 p0, + INodeDefManager *ndef) { - MapNode papyrusnode(CONTENT_PAPYRUS); + MapNode papyrusnode(LEGN(ndef, "CONTENT_PAPYRUS")); s16 trunk_h = myrand_range(2, 3); v3s16 p1 = p0; @@ -260,9 +263,10 @@ void make_papyrus(VoxelManipulator &vmanip, v3s16 p0) } } -void make_cactus(VoxelManipulator &vmanip, v3s16 p0) +void make_cactus(VoxelManipulator &vmanip, v3s16 p0, + INodeDefManager *ndef) { - MapNode cactusnode(CONTENT_CACTUS); + MapNode cactusnode(LEGN(ndef, "CONTENT_CACTUS")); s16 trunk_h = 3; v3s16 p1 = p0; @@ -277,7 +281,7 @@ void make_cactus(VoxelManipulator &vmanip, v3s16 p0) #if 0 static void make_randomstone(VoxelManipulator &vmanip, v3s16 p0) { - MapNode stonenode(CONTENT_STONE); + MapNode stonenode(LEGN(ndef, "CONTENT_STONE")); s16 size = myrand_range(3, 6); @@ -358,7 +362,7 @@ static void make_randomstone(VoxelManipulator &vmanip, v3s16 p0) #if 0 static void make_largestone(VoxelManipulator &vmanip, v3s16 p0) { - MapNode stonenode(CONTENT_STONE); + MapNode stonenode(LEGN(ndef, "CONTENT_STONE")); s16 size = myrand_range(8, 16); @@ -448,7 +452,8 @@ static void make_largestone(VoxelManipulator &vmanip, v3s16 p0) #define VMANIP_FLAG_DUNGEON_UNTOUCHABLE (\ VMANIP_FLAG_DUNGEON_INSIDE|VMANIP_FLAG_DUNGEON_PRESERVE) -static void make_room1(VoxelManipulator &vmanip, v3s16 roomsize, v3s16 roomplace) +static void make_room1(VoxelManipulator &vmanip, v3s16 roomsize, v3s16 roomplace, + INodeDefManager *ndef) { // Make +-X walls for(s16 z=0; zgetNodeNoEx(p); if(n.getContent() == CONTENT_IGNORE) continue; - if(data->nodemgr->get(n)->liquid_type != LIQUID_NONE) + if(data->nodedef->get(n)->liquid_type != LIQUID_NONE) continue; - if(data->nodemgr->get(n)->walkable) + if(data->nodedef->get(n)->walkable) { last_node_walkable = true; continue; @@ -1479,7 +1491,9 @@ void make_block(BlockMakeData *data) } assert(data->vmanip); - assert(data->nodemgr); + assert(data->nodedef); + + INodeDefManager *ndef = data->nodedef; v3s16 blockpos = data->blockpos; @@ -1541,7 +1555,7 @@ void make_block(BlockMakeData *data) if(vmanip.m_data[i].getContent() == CONTENT_IGNORE) { if(y <= WATER_LEVEL) - vmanip.m_data[i] = MapNode(CONTENT_WATERSOURCE); + vmanip.m_data[i] = MapNode(LEGN(ndef, "CONTENT_WATERSOURCE")); else vmanip.m_data[i] = MapNode(CONTENT_AIR); } @@ -1653,14 +1667,14 @@ void make_block(BlockMakeData *data) v3s16(x,y,z), data->seed) == false) { if(y <= WATER_LEVEL) - vmanip.m_data[i] = MapNode(CONTENT_WATERSOURCE); + vmanip.m_data[i] = MapNode(LEGN(ndef, "CONTENT_WATERSOURCE")); else vmanip.m_data[i] = MapNode(CONTENT_AIR); } else if(noisebuf_cave.get(x,y,z) > CAVE_NOISE_THRESHOLD) vmanip.m_data[i] = MapNode(CONTENT_AIR); else - vmanip.m_data[i] = MapNode(CONTENT_STONE); + vmanip.m_data[i] = MapNode(LEGN(ndef, "CONTENT_STONE")); } data->vmanip->m_area.add_y(em, i, 1); @@ -1689,9 +1703,9 @@ void make_block(BlockMakeData *data) { v3s16 p = v3s16(x,y,z) + g_27dirs[i]; u32 vi = vmanip.m_area.index(p); - if(vmanip.m_data[vi].getContent() == CONTENT_STONE) + if(vmanip.m_data[vi].getContent() == LEGN(ndef, "CONTENT_STONE")) if(mineralrandom.next()%8 == 0) - vmanip.m_data[vi] = MapNode(CONTENT_MESE); + vmanip.m_data[vi] = MapNode(LEGN(ndef, "CONTENT_MESE")); } } @@ -1709,22 +1723,22 @@ void make_block(BlockMakeData *data) s16 y = mineralrandom.range(node_min.Y+1, node_max.Y-1); s16 z = mineralrandom.range(node_min.Z+1, node_max.Z-1); - u8 base_content = CONTENT_STONE; + u8 base_content = LEGN(ndef, "CONTENT_STONE"); MapNode new_content(CONTENT_IGNORE); u32 sparseness = 6; if(noisebuf_ground_crumbleness.get(x,y+5,z) < -0.1) { - new_content = MapNode(CONTENT_STONE, MINERAL_COAL); + new_content = MapNode(LEGN(ndef, "CONTENT_STONE"), MINERAL_COAL); } else { if(noisebuf_ground_wetness.get(x,y+5,z) > 0.0) - new_content = MapNode(CONTENT_STONE, MINERAL_IRON); + new_content = MapNode(LEGN(ndef, "CONTENT_STONE"), MINERAL_IRON); /*if(noisebuf_ground_wetness.get(x,y,z) > 0.0) - vmanip.m_data[i] = MapNode(CONTENT_MUD); + vmanip.m_data[i] = MapNode(LEGN(ndef, "CONTENT_MUD")); else - vmanip.m_data[i] = MapNode(CONTENT_SAND);*/ + vmanip.m_data[i] = MapNode(LEGN(ndef, "CONTENT_SAND"));*/ } /*else if(noisebuf_ground_crumbleness.get(x,y,z) > 0.1) { @@ -1767,9 +1781,9 @@ void make_block(BlockMakeData *data) { v3s16 p = v3s16(x,y,z) + g_27dirs[i]; u32 vi = vmanip.m_area.index(p); - if(vmanip.m_data[vi].getContent() == CONTENT_STONE) + if(vmanip.m_data[vi].getContent() == LEGN(ndef, "CONTENT_STONE")) if(mineralrandom.next()%8 == 0) - vmanip.m_data[vi] = MapNode(CONTENT_STONE, MINERAL_COAL); + vmanip.m_data[vi] = MapNode(LEGN(ndef, "CONTENT_STONE"), MINERAL_COAL); } } } @@ -1793,9 +1807,9 @@ void make_block(BlockMakeData *data) { v3s16 p = v3s16(x,y,z) + g_27dirs[i]; u32 vi = vmanip.m_area.index(p); - if(vmanip.m_data[vi].getContent() == CONTENT_STONE) + if(vmanip.m_data[vi].getContent() == LEGN(ndef, "CONTENT_STONE")) if(mineralrandom.next()%8 == 0) - vmanip.m_data[vi] = MapNode(CONTENT_STONE, MINERAL_IRON); + vmanip.m_data[vi] = MapNode(LEGN(ndef, "CONTENT_STONE"), MINERAL_IRON); } } } @@ -1816,24 +1830,24 @@ void make_block(BlockMakeData *data) u32 i = vmanip.m_area.index(v3s16(p2d.X, node_max.Y, p2d.Y)); for(s16 y=node_max.Y; y>=node_min.Y; y--) { - if(vmanip.m_data[i].getContent() == CONTENT_STONE) + if(vmanip.m_data[i].getContent() == LEGN(ndef, "CONTENT_STONE")) { if(noisebuf_ground_crumbleness.get(x,y,z) > 1.3) { if(noisebuf_ground_wetness.get(x,y,z) > 0.0) - vmanip.m_data[i] = MapNode(CONTENT_MUD); + vmanip.m_data[i] = MapNode(LEGN(ndef, "CONTENT_MUD")); else - vmanip.m_data[i] = MapNode(CONTENT_SAND); + vmanip.m_data[i] = MapNode(LEGN(ndef, "CONTENT_SAND")); } else if(noisebuf_ground_crumbleness.get(x,y,z) > 0.7) { if(noisebuf_ground_wetness.get(x,y,z) < -0.6) - vmanip.m_data[i] = MapNode(CONTENT_GRAVEL); + vmanip.m_data[i] = MapNode(LEGN(ndef, "CONTENT_GRAVEL")); } else if(noisebuf_ground_crumbleness.get(x,y,z) < -3.0 + MYMIN(0.1 * sqrt((float)MYMAX(0, -y)), 1.5)) { - vmanip.m_data[i] = MapNode(CONTENT_LAVASOURCE); + vmanip.m_data[i] = MapNode(LEGN(ndef, "CONTENT_LAVASOURCE")); for(s16 x1=-1; x1<=1; x1++) for(s16 y1=-1; y1<=1; y1++) for(s16 z1=-1; z1<=1; z1++) @@ -1880,7 +1894,7 @@ void make_block(BlockMakeData *data) { if(vmanip.m_data[i].getContent() == CONTENT_AIR) vmanip.m_flags[i] |= VMANIP_FLAG_DUNGEON_PRESERVE; - else if(vmanip.m_data[i].getContent() == CONTENT_WATERSOURCE) + else if(vmanip.m_data[i].getContent() == LEGN(ndef, "CONTENT_WATERSOURCE")) vmanip.m_flags[i] |= VMANIP_FLAG_DUNGEON_PRESERVE; data->vmanip->m_area.add_y(em, i, -1); } @@ -1890,7 +1904,7 @@ void make_block(BlockMakeData *data) PseudoRandom random(blockseed+2); // Add it - make_dungeon1(vmanip, random); + make_dungeon1(vmanip, random, ndef); // Convert some cobble to mossy cobble for(s16 x=full_node_min.X; x<=full_node_max.X; x++) @@ -1911,17 +1925,17 @@ void make_block(BlockMakeData *data) double d = noise3d_perlin((float)x/2.5, (float)y/2.5,(float)z/2.5, blockseed, 2, 1.4); - if(vmanip.m_data[i].getContent() == CONTENT_COBBLE) + if(vmanip.m_data[i].getContent() == LEGN(ndef, "CONTENT_COBBLE")) { if(d < wetness/3.0) { - vmanip.m_data[i].setContent(CONTENT_MOSSYCOBBLE); + vmanip.m_data[i].setContent(LEGN(ndef, "CONTENT_MOSSYCOBBLE")); } } /*else if(vmanip.m_flags[i] & VMANIP_FLAG_DUNGEON_INSIDE) { if(wetness > 1.2) - vmanip.m_data[i].setContent(CONTENT_MUD); + vmanip.m_data[i].setContent(LEGN(ndef, "CONTENT_MUD")); }*/ data->vmanip->m_area.add_y(em, i, -1); } @@ -1936,7 +1950,7 @@ void make_block(BlockMakeData *data) PseudoRandom ncrandom(blockseed+9324342); if(ncrandom.range(0, 1000) == 0 && blockpos.Y <= -3) { - make_nc(vmanip, ncrandom); + make_nc(vmanip, ncrandom, ndef); } } @@ -1958,7 +1972,7 @@ void make_block(BlockMakeData *data) { if(water_found == false) { - if(vmanip.m_data[i].getContent() == CONTENT_WATERSOURCE) + if(vmanip.m_data[i].getContent() == LEGN(ndef, "CONTENT_WATERSOURCE")) { v3s16 p = v3s16(p2d.X, y, p2d.Y); data->transforming_liquid.push_back(p); @@ -1970,7 +1984,7 @@ void make_block(BlockMakeData *data) // This can be done because water_found can only // turn to true and end up here after going through // a single block. - if(vmanip.m_data[i+1].getContent() != CONTENT_WATERSOURCE) + if(vmanip.m_data[i+1].getContent() != LEGN(ndef, "CONTENT_WATERSOURCE")) { v3s16 p = v3s16(p2d.X, y+1, p2d.Y); data->transforming_liquid.push_back(p); @@ -2013,16 +2027,16 @@ void make_block(BlockMakeData *data) u32 i = vmanip.m_area.index(v3s16(p2d.X, start_y, p2d.Y)); for(s16 y=start_y; y>=node_min.Y-3; y--) { - if(vmanip.m_data[i].getContent() == CONTENT_WATERSOURCE) + if(vmanip.m_data[i].getContent() == LEGN(ndef, "CONTENT_WATERSOURCE")) water_detected = true; if(vmanip.m_data[i].getContent() == CONTENT_AIR) air_detected = true; - if((vmanip.m_data[i].getContent() == CONTENT_STONE - || vmanip.m_data[i].getContent() == CONTENT_GRASS - || vmanip.m_data[i].getContent() == CONTENT_MUD - || vmanip.m_data[i].getContent() == CONTENT_SAND - || vmanip.m_data[i].getContent() == CONTENT_GRAVEL + if((vmanip.m_data[i].getContent() == LEGN(ndef, "CONTENT_STONE") + || vmanip.m_data[i].getContent() == LEGN(ndef, "CONTENT_GRASS") + || vmanip.m_data[i].getContent() == LEGN(ndef, "CONTENT_MUD") + || vmanip.m_data[i].getContent() == LEGN(ndef, "CONTENT_SAND") + || vmanip.m_data[i].getContent() == LEGN(ndef, "CONTENT_GRAVEL") ) && (air_detected || water_detected)) { if(current_depth == 0 && y <= WATER_LEVEL+2 @@ -2043,23 +2057,23 @@ void make_block(BlockMakeData *data) ((claynoise > 0) && (claynoise < 0.12) && (current_depth == 1)) ); if (have_clay) - vmanip.m_data[i] = MapNode(CONTENT_CLAY); + vmanip.m_data[i] = MapNode(LEGN(ndef, "CONTENT_CLAY")); else - vmanip.m_data[i] = MapNode(CONTENT_SAND); + vmanip.m_data[i] = MapNode(LEGN(ndef, "CONTENT_SAND")); } #if 1 else if(current_depth==0 && !water_detected && y >= WATER_LEVEL && air_detected) - vmanip.m_data[i] = MapNode(CONTENT_GRASS); + vmanip.m_data[i] = MapNode(LEGN(ndef, "CONTENT_GRASS")); #endif else - vmanip.m_data[i] = MapNode(CONTENT_MUD); + vmanip.m_data[i] = MapNode(LEGN(ndef, "CONTENT_MUD")); } else { - if(vmanip.m_data[i].getContent() == CONTENT_MUD - || vmanip.m_data[i].getContent() == CONTENT_GRASS) - vmanip.m_data[i] = MapNode(CONTENT_STONE); + if(vmanip.m_data[i].getContent() == LEGN(ndef, "CONTENT_MUD") + || vmanip.m_data[i].getContent() == LEGN(ndef, "CONTENT_GRASS")) + vmanip.m_data[i] = MapNode(LEGN(ndef, "CONTENT_STONE")); } current_depth++; @@ -2113,7 +2127,7 @@ void make_block(BlockMakeData *data) { u32 i = data->vmanip->m_area.index(p); MapNode *n = &data->vmanip->m_data[i]; - if(n->getContent() != CONTENT_AIR && n->getContent() != CONTENT_WATERSOURCE && n->getContent() != CONTENT_IGNORE) + if(n->getContent() != CONTENT_AIR && n->getContent() != LEGN(ndef, "CONTENT_WATERSOURCE") && n->getContent() != CONTENT_IGNORE) { found = true; break; @@ -2127,17 +2141,17 @@ void make_block(BlockMakeData *data) u32 i = data->vmanip->m_area.index(p); MapNode *n = &data->vmanip->m_data[i]; - if(n->getContent() != CONTENT_MUD && n->getContent() != CONTENT_GRASS && n->getContent() != CONTENT_SAND) + if(n->getContent() != LEGN(ndef, "CONTENT_MUD") && n->getContent() != LEGN(ndef, "CONTENT_GRASS") && n->getContent() != LEGN(ndef, "CONTENT_SAND")) continue; // Papyrus grows only on mud and in water - if(n->getContent() == CONTENT_MUD && y <= WATER_LEVEL) + if(n->getContent() == LEGN(ndef, "CONTENT_MUD") && y <= WATER_LEVEL) { p.Y++; - make_papyrus(vmanip, p); + make_papyrus(vmanip, p, ndef); } // Trees grow only on mud and grass, on land - else if((n->getContent() == CONTENT_MUD || n->getContent() == CONTENT_GRASS) && y > WATER_LEVEL + 2) + else if((n->getContent() == LEGN(ndef, "CONTENT_MUD") || n->getContent() == LEGN(ndef, "CONTENT_GRASS")) && y > WATER_LEVEL + 2) { p.Y++; //if(surface_humidity_2d(data->seed, v2s16(x, y)) < 0.5) @@ -2150,16 +2164,16 @@ void make_block(BlockMakeData *data) is_apple_tree = noise2d_perlin( 0.5+(float)p.X/100, 0.5+(float)p.Z/100, data->seed+342902, 3, 0.45) > 0.2; - make_tree(vmanip, p, is_apple_tree); + make_tree(vmanip, p, is_apple_tree, ndef); } else - make_jungletree(vmanip, p); + make_jungletree(vmanip, p, ndef); } // Cactii grow only on sand, on land - else if(n->getContent() == CONTENT_SAND && y > WATER_LEVEL + 2) + else if(n->getContent() == LEGN(ndef, "CONTENT_SAND") && y > WATER_LEVEL + 2) { p.Y++; - make_cactus(vmanip, p); + make_cactus(vmanip, p, ndef); } } } @@ -2188,8 +2202,8 @@ void make_block(BlockMakeData *data) { u32 i = data->vmanip->m_area.index(p); MapNode *n = &data->vmanip->m_data[i]; - if(data->nodemgr->get(*n).is_ground_content - || n->getContent() == CONTENT_JUNGLETREE) + if(data->nodedef->get(*n).is_ground_content + || n->getContent() == LEGN(ndef, "CONTENT_JUNGLETREE")) { found = true; break; @@ -2205,10 +2219,10 @@ void make_block(BlockMakeData *data) continue; /*p.Y--; if(vmanip.m_area.contains(p)) - vmanip.m_data[vmanip.m_area.index(p)] = CONTENT_MUD; + vmanip.m_data[vmanip.m_area.index(p)] = LEGN(ndef, "CONTENT_MUD"); p.Y++;*/ if(vmanip.m_area.contains(p)) - vmanip.m_data[vmanip.m_area.index(p)] = CONTENT_JUNGLEGRASS; + vmanip.m_data[vmanip.m_area.index(p)] = LEGN(ndef, "CONTENT_JUNGLEGNRASS"); } } @@ -2236,7 +2250,7 @@ void make_block(BlockMakeData *data) /*{ u32 i = data->vmanip->m_area.index(v3s16(p)); MapNode *n = &data->vmanip->m_data[i]; - if(n->getContent() != CONTENT_MUD && n->getContent() != CONTENT_GRASS) + if(n->getContent() != LEGN(ndef, "CONTENT_MUD") && n->getContent() != LEGN(ndef, "CONTENT_GRASS")) continue; }*/ // Will be placed one higher @@ -2271,7 +2285,7 @@ void make_block(BlockMakeData *data) /*{ u32 i = data->vmanip->m_area.index(v3s16(p)); MapNode *n = &data->vmanip->m_data[i]; - if(n->getContent() != CONTENT_MUD && n->getContent() != CONTENT_GRASS) + if(n->getContent() != LEGN(ndef, "CONTENT_MUD") && n->getContent() != LEGN(ndef, "CONTENT_GRASS")) continue; }*/ // Will be placed one lower @@ -2288,7 +2302,7 @@ BlockMakeData::BlockMakeData(): no_op(false), vmanip(NULL), seed(0), - nodemgr(NULL) + nodedef(NULL) {} BlockMakeData::~BlockMakeData() diff --git a/src/mapgen.h b/src/mapgen.h index 5caee2efa..55aede099 100644 --- a/src/mapgen.h +++ b/src/mapgen.h @@ -43,7 +43,8 @@ namespace mapgen void add_random_objects(MapBlock *block); // Add a tree - void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, bool is_apple_tree); + void make_tree(ManualMapVoxelManipulator &vmanip, v3s16 p0, + bool is_apple_tree, INodeDefManager *ndef); /* These are used by FarMesh @@ -59,7 +60,7 @@ namespace mapgen u64 seed; v3s16 blockpos; UniqueQueue transforming_liquid; - INodeDefManager *nodemgr; // Destructor deletes + INodeDefManager *nodedef; // Destructor deletes BlockMakeData(); ~BlockMakeData(); diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 64c685932..7074160fd 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -45,7 +45,6 @@ TODO: - Object visual client-side stuff - Blink effect - Spritesheets and animation -- Named node types and dynamic id allocation per MapBlock - LuaNodeMetadata blockdef.has_metadata = true/false - Stores an inventory and stuff in a Settings object diff --git a/src/server.cpp b/src/server.cpp index a488f3045..c01b5050d 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -987,7 +987,7 @@ Server::Server( m_banmanager(mapsavedir+DIR_DELIM+"ipban.txt"), m_lua(NULL), m_toolmgr(createToolDefManager()), - m_nodemgr(createNodeDefManager()), + m_nodedef(createNodeDefManager()), m_thread(this), m_emergethread(this), m_time_counter(0), @@ -1013,10 +1013,10 @@ Server::Server( JMutexAutoLock envlock(m_env_mutex); JMutexAutoLock conlock(m_con_mutex); - infostream<<"m_nodemgr="<getMap().getNode(p_under); // Get mineral - mineral = n.getMineral(m_nodemgr); + mineral = n.getMineral(m_nodedef); // Get material at position material = n.getContent(); // If not yet cancelled if(cannot_remove_node == false) { // If it's not diggable, do nothing - if(m_nodemgr->get(material).diggable == false) + if(m_nodedef->get(material).diggable == false) { infostream<<"Server: Not finishing digging: " <<"Node not diggable" @@ -2633,7 +2633,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) ToolDiggingProperties tp = m_toolmgr->getDiggingProperties(toolname); DiggingProperties prop = - getDiggingProperties(material, &tp, m_nodemgr); + getDiggingProperties(material, &tp, m_nodedef); if(prop.diggable == false) { @@ -2663,7 +2663,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) // If not mineral if(item == NULL) { - const std::string &dug_s = m_nodemgr->get(material).dug_item; + const std::string &dug_s = m_nodedef->get(material).dug_item; if(dug_s != "") { std::istringstream is(dug_s, std::ios::binary); @@ -2689,8 +2689,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) // If not mineral if(item == NULL) { - const std::string &extra_dug_s = m_nodemgr->get(material).extra_dug_item; - s32 extra_rarity = m_nodemgr->get(material).extra_dug_item_rarity; + const std::string &extra_dug_s = m_nodedef->get(material).extra_dug_item; + s32 extra_rarity = m_nodedef->get(material).extra_dug_item_rarity; if(extra_dug_s != "" && extra_rarity != 0 && myrand() % extra_rarity == 0) { @@ -2766,7 +2766,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) <<" because privileges are "<get(n2).buildable_to == false + if(m_nodedef->get(n2).buildable_to == false || no_enough_privs) { // Client probably has wrong data. @@ -2804,11 +2804,11 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) <<" at "<get(n).wall_mounted) + if(m_nodedef->get(n).wall_mounted) n.param2 = packDir(p_under - p_over); // Calculate the direction for furnaces and chests and stuff - if(m_nodemgr->get(n).param_type == CPT_FACEDIR_SIMPLE) + if(m_nodedef->get(n).param_type == CPT_FACEDIR_SIMPLE) { v3f playerpos = player->getPosition(); v3f blockpos = intToFloat(p_over, BS) - playerpos; @@ -2879,7 +2879,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) Calculate special events */ - /*if(n.d == CONTENT_MESE) + /*if(n.d == LEGN(m_nodedef, "CONTENT_MESE")) { u32 count = 0; for(s16 z=-1; z<=1; z++) @@ -3036,7 +3036,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) NodeMetadata *meta = m_env->getMap().getNodeMetadata(p); if(!meta) return; - if(meta->typeId() != CONTENT_SIGN_WALL) + if(meta->typeId() != LEGN(m_nodedef, "CONTENT_SIGN_WALL")) return; SignNodeMetadata *signmeta = (SignNodeMetadata*)meta; signmeta->setText(text); @@ -3162,7 +3162,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) p.Y = stoi(fn.next(",")); p.Z = stoi(fn.next(",")); NodeMetadata *meta = m_env->getMap().getNodeMetadata(p); - if(meta && meta->typeId() == CONTENT_LOCKABLE_CHEST) { + if(meta && meta->typeId() == LEGN(m_nodedef, "CONTENT_LOCKABLE_CHEST")) { LockingChestNodeMetadata *lcm = (LockingChestNodeMetadata*)meta; if (lcm->getOwner() != player->getName()) return; @@ -3180,7 +3180,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) p.Y = stoi(fn.next(",")); p.Z = stoi(fn.next(",")); NodeMetadata *meta = m_env->getMap().getNodeMetadata(p); - if(meta && meta->typeId() == CONTENT_LOCKABLE_CHEST) { + if(meta && meta->typeId() == LEGN(m_nodedef, "CONTENT_LOCKABLE_CHEST")) { LockingChestNodeMetadata *lcm = (LockingChestNodeMetadata*)meta; if (lcm->getOwner() != player->getName()) return; @@ -4422,7 +4422,7 @@ IToolDefManager* Server::getToolDefManager() } INodeDefManager* Server::getNodeDefManager() { - return m_nodemgr; + return m_nodedef; } ITextureSource* Server::getTextureSource() { @@ -4430,7 +4430,7 @@ ITextureSource* Server::getTextureSource() } u16 Server::allocateUnknownNodeId(const std::string &name) { - return m_nodemgr->allocateDummy(name); + return m_nodedef->allocateDummy(name); } IWritableToolDefManager* Server::getWritableToolDefManager() @@ -4439,7 +4439,7 @@ IWritableToolDefManager* Server::getWritableToolDefManager() } IWritableNodeDefManager* Server::getWritableNodeDefManager() { - return m_nodemgr; + return m_nodedef; } v3f findSpawnPos(ServerMap &map) diff --git a/src/server.h b/src/server.h index 164cfe9cd..ff0abccc4 100644 --- a/src/server.h +++ b/src/server.h @@ -633,7 +633,7 @@ private: IWritableToolDefManager *m_toolmgr; // Node definition manager - IWritableNodeDefManager *m_nodemgr; + IWritableNodeDefManager *m_nodedef; /* Threads diff --git a/src/test.cpp b/src/test.cpp index c998a97ab..2a25ed656 100644 --- a/src/test.cpp +++ b/src/test.cpp @@ -229,7 +229,7 @@ struct TestMapNode // Transparency n.setContent(CONTENT_AIR); assert(nodedef->get(n).light_propagates == true); - n.setContent(CONTENT_STONE); + n.setContent(LEGN(nodedef, "CONTENT_STONE")); assert(nodedef->get(n).light_propagates == false); } };