summaryrefslogtreecommitdiff
path: root/src/content_cao.cpp
diff options
context:
space:
mode:
authorKahrl <kahrl@gmx.net>2012-01-12 06:10:39 +0100
committerKahrl <kahrl@gmx.net>2012-01-12 06:10:39 +0100
commit6a76c226e10e92c3e3339096f07f8ab065e2098b (patch)
tree396d9083f5f76ebb5ba96df113ba68046c2487df /src/content_cao.cpp
parent569156b01302ea4ba45d11ff5524b62dbc6a9aa0 (diff)
downloadminetest-6a76c226e10e92c3e3339096f07f8ab065e2098b.tar.gz
minetest-6a76c226e10e92c3e3339096f07f8ab065e2098b.tar.bz2
minetest-6a76c226e10e92c3e3339096f07f8ab065e2098b.zip
The huge item definition and item namespace unification patch (itemdef), see http://c55.me/minetest/wiki/doku.php?id=changes:itemdef
Diffstat (limited to 'src/content_cao.cpp')
-rw-r--r--src/content_cao.cpp107
1 files changed, 60 insertions, 47 deletions
diff --git a/src/content_cao.cpp b/src/content_cao.cpp
index d581b35dc..a2708674b 100644
--- a/src/content_cao.cpp
+++ b/src/content_cao.cpp
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "content_cao.h"
#include "tile.h"
#include "environment.h"
+#include "collision.h"
#include "settings.h"
#include <ICameraSceneNode.h>
#include <ITextSceneNode.h>
@@ -172,6 +173,8 @@ public:
void updateLight(u8 light_at_pos);
v3s16 getLightPosition();
void updateNodePos();
+ void updateInfoText();
+ void updateTexture();
void step(float dtime, ClientEnvironment *env);
@@ -191,7 +194,7 @@ private:
core::aabbox3d<f32> m_selection_box;
scene::IMeshSceneNode *m_node;
v3f m_position;
- std::string m_inventorystring;
+ std::string m_itemstring;
std::string m_infotext;
};
@@ -595,39 +598,13 @@ void ItemCAO::addToScene(scene::ISceneManager *smgr, ITextureSource *tsrc,
buf->drop();
m_node = smgr->addMeshSceneNode(mesh, NULL);
mesh->drop();
- // Set it to use the materials of the meshbuffers directly.
- // This is needed for changing the texture in the future
- m_node->setReadOnlyMaterials(true);
updateNodePos();
/*
Update image of node
*/
- // Create an inventory item to see what is its image
- std::istringstream is(m_inventorystring, std::ios_base::binary);
- video::ITexture *texture = NULL;
- try{
- InventoryItem *item = NULL;
- item = InventoryItem::deSerialize(is, m_gamedef);
- infostream<<__FUNCTION_NAME<<": m_inventorystring=\""
- <<m_inventorystring<<"\" -> item="<<item
- <<std::endl;
- if(item)
- {
- texture = item->getImage();
- delete item;
- }
- }
- catch(SerializationError &e)
- {
- infostream<<"WARNING: "<<__FUNCTION_NAME
- <<": error deSerializing inventorystring \""
- <<m_inventorystring<<"\""<<std::endl;
- }
-
- // Set meshbuffer texture
- buf->getMaterial().setTexture(0, texture);
+ updateTexture();
}
void ItemCAO::removeFromScene()
@@ -662,6 +639,51 @@ void ItemCAO::updateNodePos()
m_node->setPosition(m_position);
}
+void ItemCAO::updateInfoText()
+{
+ try{
+ IItemDefManager *idef = m_gamedef->idef();
+ ItemStack item;
+ item.deSerialize(m_itemstring, idef);
+ if(item.isKnown(idef))
+ m_infotext = item.getDefinition(idef).description;
+ else
+ m_infotext = "Unknown item: '" + m_itemstring + "'";
+ if(item.count >= 2)
+ m_infotext += " (" + itos(item.count) + ")";
+ }
+ catch(SerializationError &e)
+ {
+ m_infotext = "Unknown item: '" + m_itemstring + "'";
+ }
+}
+
+void ItemCAO::updateTexture()
+{
+ if(m_node == NULL)
+ return;
+
+ // Create an inventory item to see what is its image
+ std::istringstream is(m_itemstring, std::ios_base::binary);
+ video::ITexture *texture = NULL;
+ try{
+ IItemDefManager *idef = m_gamedef->idef();
+ ItemStack item;
+ item.deSerialize(is, idef);
+ texture = item.getDefinition(idef).inventory_texture;
+ }
+ catch(SerializationError &e)
+ {
+ infostream<<"WARNING: "<<__FUNCTION_NAME
+ <<": error deSerializing itemstring \""
+ <<m_itemstring<<std::endl;
+ }
+
+ // Set meshbuffer texture
+ m_node->getMaterial(0).setTexture(0, texture);
+}
+
+
void ItemCAO::step(float dtime, ClientEnvironment *env)
{
if(m_node)
@@ -689,6 +711,13 @@ void ItemCAO::processMessage(const std::string &data)
m_position = readV3F1000(is);
updateNodePos();
}
+ if(cmd == 1)
+ {
+ // itemstring
+ m_itemstring = deSerializeString(is);
+ updateInfoText();
+ updateTexture();
+ }
}
void ItemCAO::initialize(const std::string &data)
@@ -704,28 +733,12 @@ void ItemCAO::initialize(const std::string &data)
return;
// pos
m_position = readV3F1000(is);
- // inventorystring
- m_inventorystring = deSerializeString(is);
+ // itemstring
+ m_itemstring = deSerializeString(is);
}
updateNodePos();
-
- /*
- Set infotext to item name if item cannot be deserialized
- */
- try{
- InventoryItem *item = NULL;
- item = InventoryItem::deSerialize(m_inventorystring, m_gamedef);
- if(item){
- if(!item->isKnown())
- m_infotext = "Unknown item: '" + m_inventorystring + "'";
- }
- delete item;
- }
- catch(SerializationError &e)
- {
- m_infotext = "Unknown item: '" + m_inventorystring + "'";
- }
+ updateInfoText();
}
/*