Fix dropped nodeitem visuals
authorPerttu Ahola <celeron55@gmail.com>
Wed, 4 Apr 2012 10:16:09 +0000 (13:16 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Wed, 4 Apr 2012 10:16:09 +0000 (13:16 +0300)
builtin/item_entity.lua
src/content_cao.cpp
src/genericobject.cpp
src/object_properties.cpp
src/object_properties.h
src/scriptapi.cpp

index 8468ebedf9193ab5c971a4609e052b83a00c7244..ad0060b48e5f16afef20901eee7e00ee5f166d96 100644 (file)
@@ -12,7 +12,7 @@ minetest.register_entity("__builtin:item", {
        initial_properties = {
                hp_max = 1,
                physical = true,
-               collisionbox = {-0.25,-0.25,-0.25, 0.25,0.25,0.25},
+               collisionbox = {-0.17,-0.17,-0.17, 0.17,0.17,0.17},
                visual = "sprite",
                visual_size = {x=0.5, y=0.5},
                textures = {""},
@@ -33,14 +33,26 @@ minetest.register_entity("__builtin:item", {
                        itemname = stack:to_table().name
                end
                local item_texture = nil
+               local item_type = ""
                if minetest.registered_items[itemname] then
                        item_texture = minetest.registered_items[itemname].inventory_image
+                       item_type = minetest.registered_items[itemname].type
                end
-               item_texture = item_texture or "unknown_item.png"
-               self.object:set_properties({
-                       textures = {item_texture},
+               prop = {
                        is_visible = true,
-               })
+                       visual = "sprite",
+                       textures = {"unknown_item.png"}
+               }
+               if item_texture and item_texture ~= "" then
+                       prop.visual = "sprite"
+                       prop.textures = {item_texture}
+               else
+                       prop.visual = "wielditem"
+                       prop.textures = {itemname}
+                       prop.visual_size = {x=0.20, y=0.20}
+                       prop.automatic_rotate = math.pi * 0.25
+               end
+               self.object:set_properties(prop)
        end,
 
        get_staticdata = function(self)
index 1241e0002416bf61dbb908ee29345e62d72543e4..f211ff8b9ad7d2185511f8918525a9415863449d 100644 (file)
@@ -781,9 +781,27 @@ public:
                        m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
                        mesh->drop();
                        
-                       m_meshnode->setScale(v3f(1));
+                       m_meshnode->setScale(v3f(m_prop.visual_size.X/2,
+                                       m_prop.visual_size.Y/2,
+                                       m_prop.visual_size.X/2));
                        u8 li = m_last_light;
                        setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
+               } else if(m_prop.visual == "wielditem"){
+                       infostream<<"GenericCAO::addToScene(): node"<<std::endl;
+                       infostream<<"textures: "<<m_prop.textures.size()<<std::endl;
+                       if(m_prop.textures.size() >= 1){
+                               infostream<<"textures[0]: "<<m_prop.textures[0]<<std::endl;
+                               IItemDefManager *idef = m_gamedef->idef();
+                               ItemStack item(m_prop.textures[0], 1, 0, "", idef);
+                               scene::IMesh *mesh = item.getDefinition(idef).wield_mesh;
+                               m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
+                               
+                               m_meshnode->setScale(v3f(m_prop.visual_size.X/2,
+                                               m_prop.visual_size.Y/2,
+                                               m_prop.visual_size.X/2));
+                               u8 li = m_last_light;
+                               setMeshColor(m_meshnode->getMesh(), video::SColor(255,li,li,li));
+                       }
                } else {
                        infostream<<"GenericCAO::addToScene(): \""<<m_prop.visual
                                        <<"\" not supported"<<std::endl;
@@ -916,6 +934,10 @@ public:
                                updateTextures("");
                        }
                }
+               if(fabs(m_prop.automatic_rotate > 0.001)){
+                       m_yaw += dtime * m_prop.automatic_rotate * 180 / PI;
+                       updateNodePos();
+               }
        }
 
        void updateTexturePos()
@@ -1064,7 +1086,8 @@ public:
                        m_position = readV3F1000(is);
                        m_velocity = readV3F1000(is);
                        m_acceleration = readV3F1000(is);
-                       m_yaw = readF1000(is);
+                       if(fabs(m_prop.automatic_rotate < 0.001))
+                               m_yaw = readF1000(is);
                        bool do_interpolate = readU8(is);
                        bool is_end_position = readU8(is);
                        float update_interval = readF1000(is);
index 563b7f7f12652b4f04a7d0522e9d68d15070d41c..1f85d9e47ee231a0a2fb73572ce07a5382e55279 100644 (file)
@@ -25,43 +25,14 @@ std::string gob_cmd_set_properties(const ObjectProperties &prop)
 {
        std::ostringstream os(std::ios::binary);
        writeU8(os, GENERIC_CMD_SET_PROPERTIES);
-       writeS16(os, prop.hp_max);
-       writeU8(os, prop.physical);
-       writeF1000(os, prop.weight);
-       writeV3F1000(os, prop.collisionbox.MinEdge);
-       writeV3F1000(os, prop.collisionbox.MaxEdge);
-       os<<serializeString(prop.visual);
-       writeV2F1000(os, prop.visual_size);
-       writeU16(os, prop.textures.size());
-       for(u32 i=0; i<prop.textures.size(); i++){
-               os<<serializeString(prop.textures[i]);
-       }
-       writeV2S16(os, prop.spritediv);
-       writeV2S16(os, prop.initial_sprite_basepos);
-       writeU8(os, prop.is_visible);
-       writeU8(os, prop.makes_footstep_sound);
+       prop.serialize(os);
        return os.str();
 }
 
 ObjectProperties gob_read_set_properties(std::istream &is)
 {
        ObjectProperties prop;
-       prop.hp_max = readS16(is);
-       prop.physical = readU8(is);
-       prop.weight = readF1000(is);
-       prop.collisionbox.MinEdge = readV3F1000(is);
-       prop.collisionbox.MaxEdge = readV3F1000(is);
-       prop.visual = deSerializeString(is);
-       prop.visual_size = readV2F1000(is);
-       prop.textures.clear();
-       u32 texture_count = readU16(is);
-       for(u32 i=0; i<texture_count; i++){
-               prop.textures.push_back(deSerializeString(is));
-       }
-       prop.spritediv = readV2S16(is);
-       prop.initial_sprite_basepos = readV2S16(is);
-       prop.is_visible = readU8(is);
-       prop.makes_footstep_sound = readU8(is);
+       prop.deSerialize(is);
        return prop;
 }
 
index edd50c30a08e4b081b79620f4acbff873eb6d503..08e9f63cf71c47c2636b047890681a0e9a5f5878 100644 (file)
@@ -33,7 +33,8 @@ ObjectProperties::ObjectProperties():
        spritediv(1,1),
        initial_sprite_basepos(0,0),
        is_visible(true),
-       makes_footstep_sound(false)
+       makes_footstep_sound(false),
+       automatic_rotate(0)
 {
        textures.push_back("unknown_object.png");
 }
@@ -54,12 +55,13 @@ std::string ObjectProperties::dump()
        os<<"]";
        os<<", spritediv="<<PP2(spritediv);
        os<<", initial_sprite_basepos="<<PP2(initial_sprite_basepos);
-       os<<", is_visible"<<is_visible;
+       os<<", is_visible="<<is_visible;
        os<<", makes_footstep_sound="<<makes_footstep_sound;
+       os<<", automatic_rotate="<<automatic_rotate;
        return os.str();
 }
 
-void ObjectProperties::serialize(std::ostream &os)
+void ObjectProperties::serialize(std::ostream &os) const
 {
        writeU8(os, 1); // version
        writeS16(os, hp_max);
@@ -77,6 +79,7 @@ void ObjectProperties::serialize(std::ostream &os)
        writeV2S16(os, initial_sprite_basepos);
        writeU8(os, is_visible);
        writeU8(os, makes_footstep_sound);
+       writeF1000(os, automatic_rotate);
 }
 
 void ObjectProperties::deSerialize(std::istream &is)
@@ -100,6 +103,9 @@ void ObjectProperties::deSerialize(std::istream &is)
        initial_sprite_basepos = readV2S16(is);
        is_visible = readU8(is);
        makes_footstep_sound = readU8(is);
+       try{
+               automatic_rotate = readF1000(is);
+       }catch(SerializationError &e){}
 }
 
 
index 99683a917dfed4a67ce36350f1bb48a39f4bccea..75ba1f895bfb18ed1f9a5647d269e31ee793c2ef 100644 (file)
@@ -38,10 +38,11 @@ struct ObjectProperties
        v2s16 initial_sprite_basepos;
        bool is_visible;
        bool makes_footstep_sound;
+       float automatic_rotate;
 
        ObjectProperties();
        std::string dump();
-       void serialize(std::ostream &os);
+       void serialize(std::ostream &os) const;
        void deSerialize(std::istream &is);
 };
 
index a45c27de6a9327af7b42859cc443567a606bfad5..5453d9b2ed509c3cac9b8b0a12e36a312602c3ac 100644 (file)
@@ -915,6 +915,9 @@ static void read_object_properties(lua_State *L, int index,
        
        getboolfield(L, -1, "is_visible", prop->is_visible);
        getboolfield(L, -1, "makes_footstep_sound", prop->makes_footstep_sound);
+       getfloatfield(L, -1, "automatic_rotate", prop->automatic_rotate);
+       dstream<<"scriptapi: prop->automatic_rotate="
+                       <<prop->automatic_rotate<<std::endl;
 }
 
 /*