aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-02-14 12:08:03 +0200
committerPerttu Ahola <celeron55@gmail.com>2011-02-14 12:08:03 +0200
commit00810408a8cf1e5212cc8efa1287fd3745232f13 (patch)
tree5e43a94d2781686dffb1396c60ac28608bd54c51 /src
parent5573142a2bd4fe65adf4219b21e6708296610563 (diff)
downloadminetest-00810408a8cf1e5212cc8efa1287fd3745232f13.tar.gz
minetest-00810408a8cf1e5212cc8efa1287fd3745232f13.tar.bz2
minetest-00810408a8cf1e5212cc8efa1287fd3745232f13.zip
New way of determining the outcome of digging
Diffstat (limited to 'src')
-rw-r--r--src/mapnode.cpp13
-rw-r--r--src/mapnode.h9
-rw-r--r--src/server.cpp29
3 files changed, 41 insertions, 10 deletions
diff --git a/src/mapnode.cpp b/src/mapnode.cpp
index 747c5aefb..1e0381d03 100644
--- a/src/mapnode.cpp
+++ b/src/mapnode.cpp
@@ -140,6 +140,7 @@ void init_mapnode()
f->setInventoryTextureCube("stone.png", "stone.png", "stone.png");
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
+ f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
i = CONTENT_GRASS;
f = &g_content_features[i];
@@ -148,6 +149,7 @@ void init_mapnode()
f->setTexture(1, "mud.png");
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
+ f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
i = CONTENT_GRASS_FOOTSTEPS;
f = &g_content_features[i];
@@ -156,18 +158,21 @@ void init_mapnode()
f->setTexture(1, "mud.png");
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
+ f->dug_item = std::string("MaterialItem ")+itos(CONTENT_MUD)+" 1";
i = CONTENT_MUD;
f = &g_content_features[i];
f->setAllTextures("mud.png");
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
+ f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
i = CONTENT_SAND;
f = &g_content_features[i];
f->setAllTextures("sand.png");
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
+ f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
i = CONTENT_TREE;
f = &g_content_features[i];
@@ -176,6 +181,7 @@ void init_mapnode()
f->setTexture(1, "tree_top.png");
f->param_type = CPT_MINERAL;
f->is_ground_content = true;
+ f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
i = CONTENT_LEAVES;
f = &g_content_features[i];
@@ -186,11 +192,13 @@ void init_mapnode()
if(new_style_leaves)
{
f->solidness = 0; // drawn separately, makes no faces
+ f->setInventoryTextureCube("leaves.png", "leaves.png", "leaves.png");
}
else
{
f->setAllTextures("[noalpha:leaves.png");
}
+ f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
i = CONTENT_COALSTONE;
f = &g_content_features[i];
@@ -202,16 +210,19 @@ void init_mapnode()
f = &g_content_features[i];
f->setAllTextures("wood.png");
f->is_ground_content = true;
+ f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
i = CONTENT_MESE;
f = &g_content_features[i];
f->setAllTextures("mese.png");
f->is_ground_content = true;
+ f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
i = CONTENT_CLOUD;
f = &g_content_features[i];
f->setAllTextures("cloud.png");
f->is_ground_content = true;
+ f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
i = CONTENT_AIR;
f = &g_content_features[i];
@@ -263,6 +274,7 @@ void init_mapnode()
f->diggable = false;
f->buildable_to = true;
f->liquid_type = LIQUID_SOURCE;
+ f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
i = CONTENT_TORCH;
f = &g_content_features[i];
@@ -272,6 +284,7 @@ void init_mapnode()
f->solidness = 0; // drawn separately, makes no faces
f->walkable = false;
f->wall_mounted = true;
+ f->dug_item = std::string("MaterialItem ")+itos(i)+" 1";
}
diff --git a/src/mapnode.h b/src/mapnode.h
index 37a0b3aa6..d67b9629e 100644
--- a/src/mapnode.h
+++ b/src/mapnode.h
@@ -154,7 +154,13 @@ struct ContentFeatures
bool diggable;
bool buildable_to;
enum LiquidType liquid_type;
- bool wall_mounted; // If true, param2 is set to direction when placed
+ // If true, param2 is set to direction when placed
+ // NOTE: the direction format is quite inefficient and should be changed
+ bool wall_mounted;
+
+ // Inventory item string as which the node appears in inventory when dug.
+ // Mineral overrides this.
+ std::string dug_item;
//TODO: Move more properties here
@@ -173,6 +179,7 @@ struct ContentFeatures
buildable_to = false;
liquid_type = LIQUID_NONE;
wall_mounted = false;
+ dug_item = "";
}
~ContentFeatures();
diff --git a/src/server.cpp b/src/server.cpp
index 739698f16..02a832ca2 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -1854,6 +1854,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
0: start digging
1: place block
2: stop digging (all parameters ignored)
+ 3: digging completed
*/
u8 action = readU8(&data[2]);
v3s16 p_under;
@@ -1996,23 +1997,33 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
}
/*
- Add digged item to inventory
+ Add dug item to inventory
*/
InventoryItem *item = NULL;
if(mineral != MINERAL_NONE)
item = getDiggedMineralItem(mineral);
-
+
+ // If not mineral
if(item == NULL)
- item = new MaterialItem(material, 1);
-
- player->inventory.addItem("main", item);
+ {
+ std::string &dug_s = content_features(material).dug_item;
+ if(dug_s != "")
+ {
+ std::istringstream is(dug_s, std::ios::binary);
+ item = InventoryItem::deSerialize(is);
+ }
+ }
+
+ if(item != NULL)
+ {
+ // Add a item to inventory
+ player->inventory.addItem("main", item);
- /*
- Send inventory
- */
- SendInventory(player->peer_id);
+ // Send inventory
+ SendInventory(player->peer_id);
+ }
}
/*