aboutsummaryrefslogtreecommitdiff
path: root/src/content_cao.cpp
diff options
context:
space:
mode:
authorKahrl <kahrl@gmx.net>2012-03-19 03:04:16 +0100
committerPerttu Ahola <celeron55@gmail.com>2012-03-29 14:05:45 +0300
commitf8c3743991a6897c7133bf35dc2699b8b5f9df7c (patch)
treee856506d9c96d572d1a3b0a58edf00f0d70cba43 /src/content_cao.cpp
parent072c265c301d3336203b77b8b1651fdacf3a7682 (diff)
downloadminetest-f8c3743991a6897c7133bf35dc2699b8b5f9df7c.tar.gz
minetest-f8c3743991a6897c7133bf35dc2699b8b5f9df7c.tar.bz2
minetest-f8c3743991a6897c7133bf35dc2699b8b5f9df7c.zip
added PlayerSAO and RemotePlayer, removed ServerRemotePlayer
Diffstat (limited to 'src/content_cao.cpp')
-rw-r--r--src/content_cao.cpp58
1 files changed, 57 insertions, 1 deletions
diff --git a/src/content_cao.cpp b/src/content_cao.cpp
index fc1df377a..11c9ad9c6 100644
--- a/src/content_cao.cpp
+++ b/src/content_cao.cpp
@@ -1011,6 +1011,7 @@ private:
float m_damage_visual_timer;
bool m_dead;
float m_step_distance_counter;
+ std::string m_wielded_item;
public:
PlayerCAO(IGameDef *gamedef, ClientEnvironment *env):
@@ -1024,7 +1025,8 @@ public:
m_local_player(NULL),
m_damage_visual_timer(0),
m_dead(false),
- m_step_distance_counter(0)
+ m_step_distance_counter(0),
+ m_wielded_item("")
{
if(gamedef == NULL)
ClientActiveObject::registerType(getType(), create);
@@ -1048,6 +1050,11 @@ public:
m_yaw = readF1000(is);
// dead
m_dead = readU8(is);
+ // wielded item
+ try{
+ m_wielded_item = deSerializeString(is);
+ }
+ catch(SerializationError &e){}
pos_translator.init(m_position);
@@ -1263,6 +1270,11 @@ public:
m_dead = readU8(is);
updateVisibility();
}
+ else if(cmd == 3) // wielded item
+ {
+ m_wielded_item = deSerializeString(is);
+ updateWieldedItem();
+ }
}
void updateTextures(const std::string &mod)
@@ -1288,6 +1300,50 @@ public:
}
}
}
+
+ void updateWieldedItem()
+ {
+ if(m_is_local_player)
+ {
+ // ignoring player item for local player
+ return;
+ }
+
+ ItemStack item;
+ try
+ {
+ item.deSerialize(m_wielded_item, m_gamedef->idef());
+ }
+ catch(SerializationError &e)
+ {
+ errorstream<<"PlayerCAO: SerializationError "
+ "while reading wielded item: "
+ <<m_wielded_item<<std::endl;
+ return;
+ }
+
+ // do something with the item, for example:
+ Player *player = m_env->getPlayer(m_name.c_str());
+ if(player)
+ {
+ InventoryList *inv = player->inventory.getList("main");
+ assert(inv);
+ inv->changeItem(0, item);
+ }
+
+ if(item.empty())
+ {
+ infostream<<"PlayerCAO: empty player item for player "
+ <<m_name<<std::endl;
+ }
+ else
+ {
+ infostream<<"PlayerCAO: player item for player "
+ <<m_name<<": "
+ <<item.getItemString()<<std::endl;
+ }
+ }
+
};
// Prototype