Store metadata as metadata name in node definition
authorPerttu Ahola <celeron55@gmail.com>
Fri, 25 Nov 2011 13:38:18 +0000 (15:38 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Tue, 29 Nov 2011 17:13:51 +0000 (19:13 +0200)
src/content_mapnode.cpp
src/map.cpp
src/nodedef.cpp
src/nodedef.h
src/scriptapi.cpp
src/server.cpp

index cddc552d4091544746841343550919b2880dc89e..eda252dc178a25e6f4d06e3f98492682dab50ebf 100644 (file)
@@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "irrlichttypes.h"
 #include "mapnode.h"
-#include "content_nodemeta.h"
 #include "nodedef.h"
 #include "utility.h"
 #include "nameidmapping.h"
@@ -802,8 +801,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f.wall_mounted = true;
        f.air_equivalent = true;
        f.dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
-       if(f.initial_metadata == NULL)
-               f.initial_metadata = new SignNodeMetadata(NULL, "Some sign");
+       f.metadata_name = "sign";
        setConstantMaterialProperties(f.material, 0.5);
        f.selection_box.type = NODEBOX_WALLMOUNTED;
        f.furnace_burntime = 10;
@@ -820,8 +818,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f.setInventoryTexture("chest_top.png");
        //f.setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png");
        f.dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
-       if(f.initial_metadata == NULL)
-               f.initial_metadata = new ChestNodeMetadata(NULL);
+       f.metadata_name = "chest";
        setWoodLikeMaterialProperties(f.material, 1.0);
        f.furnace_burntime = 30;
        nodemgr->set(i, f);
@@ -837,8 +834,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f.setInventoryTexture("chest_lock.png");
        //f.setInventoryTextureCube("chest_top.png", "chest_side.png", "chest_side.png");
        f.dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
-       if(f.initial_metadata == NULL)
-               f.initial_metadata = new LockingChestNodeMetadata(NULL);
+       f.metadata_name = "locked_chest";
        setWoodLikeMaterialProperties(f.material, 1.0);
        f.furnace_burntime = 30;
        nodemgr->set(i, f);
@@ -852,8 +848,7 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
        f.setInventoryTexture("furnace_front.png");
        //f.dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
        f.dug_item = std::string("MaterialItem2 ")+itos(CONTENT_COBBLE)+" 6";
-       if(f.initial_metadata == NULL)
-               f.initial_metadata = new FurnaceNodeMetadata(NULL);
+       f.metadata_name = "furnace";
        setStoneLikeMaterialProperties(f.material, 3.0);
        nodemgr->set(i, f);
 
index 7d5bd700d7855d437cd373597833ffc0d004b4f3..d27c6da120f963862be7107e7c1cce7b0bdebbfa 100644 (file)
@@ -994,11 +994,10 @@ void Map::addNodeAndUpdate(v3s16 p, MapNode n,
        /*
                Add intial metadata
        */
-
-       NodeMetadata *meta_proto = nodemgr->get(n).initial_metadata;
-       if(meta_proto)
-       {
-               NodeMetadata *meta = meta_proto->clone(m_gamedef);
+       
+       std::string metadata_name = nodemgr->get(n).metadata_name;
+       if(metadata_name != ""){
+               NodeMetadata *meta = NodeMetadata::create(metadata_name, m_gamedef);
                meta->setOwner(player_name);
                setNodeMetadata(p, meta);
        }
index a32851974af823a2e81338a51a44b7fdb177717a..956bc1a5fa9b57aa23257ae77f2bfce095aaf937 100644 (file)
@@ -89,7 +89,6 @@ ContentFeatures::ContentFeatures()
 
 ContentFeatures::~ContentFeatures()
 {
-       delete initial_metadata;
 #ifndef SERVER
        for(u16 j=0; j<CF_SPECIAL_COUNT; j++){
                delete special_materials[j];
@@ -143,7 +142,7 @@ void ContentFeatures::reset()
        dug_item = "";
        extra_dug_item = "";
        extra_dug_item_rarity = 2;
-       initial_metadata = NULL;
+       metadata_name = "";
        liquid_type = LIQUID_NONE;
        liquid_alternative_flowing = CONTENT_IGNORE;
        liquid_alternative_source = CONTENT_IGNORE;
@@ -191,12 +190,7 @@ void ContentFeatures::serialize(std::ostream &os)
        os<<serializeString(dug_item);
        os<<serializeString(extra_dug_item);
        writeS32(os, extra_dug_item_rarity);
-       if(initial_metadata){
-               writeU8(os, true);
-               initial_metadata->serialize(os);
-       } else {
-               writeU8(os, false);
-       }
+       os<<serializeString(metadata_name);
        writeU8(os, liquid_type);
        writeU16(os, liquid_alternative_flowing);
        writeU16(os, liquid_alternative_source);
@@ -248,11 +242,7 @@ void ContentFeatures::deSerialize(std::istream &is, IGameDef *gamedef)
        dug_item = deSerializeString(is);
        extra_dug_item = deSerializeString(is);
        extra_dug_item_rarity = readS32(is);
-       if(readU8(is)){
-               initial_metadata = NodeMetadata::deSerialize(is, gamedef);
-       } else {
-               initial_metadata = NULL;
-       }
+       metadata_name = deSerializeString(is);
        liquid_type = (enum LiquidType)readU8(is);
        liquid_alternative_flowing = readU16(is);
        liquid_alternative_source = readU16(is);
index 0804e02797e19790be41a0d15eab6cb1582fcd40..87f5fce83686836ad54c75e6aa1c2f2aebaa2fa3 100644 (file)
@@ -188,8 +188,8 @@ struct ContentFeatures
        std::string extra_dug_item;
        // Usual get interval for extra dug item
        s32 extra_dug_item_rarity;
-       // Initial metadata is cloned from this
-       NodeMetadata *initial_metadata;
+       // Metadata name of node (eg. "furnace")
+       std::string metadata_name;
        // Whether the node is non-liquid, source liquid or flowing liquid
        enum LiquidType liquid_type;
        // If the content is liquid, this is the flowing version of the liquid.
index aed4227c601f910ad8522d038191d5e16d403d73..b4c79cd285090b6baccee5ad21c4f5f5ec1fd17f 100644 (file)
@@ -548,9 +548,8 @@ static int l_register_node(lua_State *L)
        getstringfield(L, table0, "extra_dug_item", f.extra_dug_item);
        // Usual get interval for extra dug item
        getintfield(L, table0, "extra_dug_item_rarity", f.extra_dug_item_rarity);
-       // Initial metadata is cloned from this
-       // TODO: As metadata name
-       // NodeMetadata *initial_metadata;
+       // Metadata name of node (eg. "furnace")
+       getstringfield(L, table0, "metadata_name", f.metadata_name);
        // Whether the node is non-liquid, source liquid or flowing liquid
        // TODO: Enum read
        // enum LiquidType liquid_type;
index cd67bc7494c814ac8ee336a84f40ad9fcde8b7ac..100497b6137a1fb99c3626eab9eed620bd8f6636 100644 (file)
@@ -3536,7 +3536,7 @@ void Server::inventoryModified(InventoryContext *c, std::string id)
                if(meta)
                        meta->inventoryModified();
                
-               MapBlock *block = m_env.getMap().getBlockNoCreateNoEx(blockpos);
+               MapBlock *block = m_env->getMap().getBlockNoCreateNoEx(blockpos);
                if(block)
                        block->raiseModified(MOD_STATE_WRITE_NEEDED);