From ac628c9b0ab8c69313b3fe401384ecd0fc20eb14 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 9 Sep 2012 12:05:38 +0300 Subject: [PATCH 1/6] Fix ObjectRef:punch() --- doc/lua_api.txt | 1 + src/scriptapi.cpp | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index b71b6d62c..782378c1f 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1087,6 +1087,7 @@ methods: - punch(puncher, time_from_last_punch, tool_capabilities, direction) ^ puncher = an another ObjectRef, ^ time_from_last_punch = time since last punch action of the puncher + ^ direction: can be nil - right_click(clicker); clicker = an another ObjectRef - get_hp(): returns number of hitpoints (2 * number of hearts) - set_hp(hp): set number of hitpoints (2 * number of hearts) diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 81e96aec6..39e2a46e4 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -2542,7 +2542,7 @@ private: return 0; } - // punch(self, puncher, tool_capabilities, direction, time_from_last_punch) + // punch(self, puncher, time_from_last_punch, tool_capabilities, dir) static int l_punch(lua_State *L) { ObjectRef *ref = checkobject(L, 1); @@ -2551,13 +2551,18 @@ private: ServerActiveObject *puncher = getobject(puncher_ref); if(co == NULL) return 0; if(puncher == NULL) return 0; - ToolCapabilities toolcap = read_tool_capabilities(L, 3); - v3f dir = read_v3f(L, 4); + v3f dir; + if(lua_type(L, 5) != LUA_TTABLE) + dir = co->getBasePosition() - puncher->getBasePosition(); + else + dir = read_v3f(L, 5); float time_from_last_punch = 1000000; - if(lua_isnumber(L, 5)) - time_from_last_punch = lua_tonumber(L, 5); + if(lua_isnumber(L, 3)) + time_from_last_punch = lua_tonumber(L, 3); + ToolCapabilities toolcap = read_tool_capabilities(L, 4); + dir.normalize(); // Do it - puncher->punch(dir, &toolcap, puncher, time_from_last_punch); + co->punch(dir, &toolcap, puncher, time_from_last_punch); return 0; } From c4f400acd01d1951c6355e2eec42d10d0a2d871a Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 9 Sep 2012 13:26:52 +0300 Subject: [PATCH 2/6] Fix wielditem entity drawtype brightness control --- src/content_cao.cpp | 30 ++++++++++++++++++++---------- src/environment.cpp | 3 ++- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/content_cao.cpp b/src/content_cao.cpp index aa5c2d674..cb14cf395 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -40,6 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/serialize.h" #include "util/mathconstants.h" #include "map.h" +#include class Settings; struct ToolCapabilities; @@ -797,8 +798,15 @@ public: infostream<<"textures[0]: "<idef(); ItemStack item(m_prop.textures[0], 1, 0, "", idef); - scene::IMesh *mesh = item.getDefinition(idef).wield_mesh; + scene::IMesh *item_mesh = item.getDefinition(idef).wield_mesh; + + // Copy mesh to be able to set unique vertex colors + scene::IMeshManipulator *manip = + irr->getVideoDriver()->getMeshManipulator(); + scene::IMesh *mesh = manip->createMeshUniquePrimitives(item_mesh); + m_meshnode = smgr->addMeshSceneNode(mesh, NULL); + mesh->drop(); m_meshnode->setScale(v3f(m_prop.visual_size.X/2, m_prop.visual_size.Y/2, @@ -838,15 +846,17 @@ public: { bool is_visible = (m_hp != 0); u8 li = decode_light(light_at_pos); - m_last_light = li; - video::SColor color(255,li,li,li); - if(m_meshnode){ - setMeshColor(m_meshnode->getMesh(), color); - m_meshnode->setVisible(is_visible); - } - if(m_spritenode){ - m_spritenode->setColor(color); - m_spritenode->setVisible(is_visible); + if(li != m_last_light){ + m_last_light = li; + video::SColor color(255,li,li,li); + if(m_meshnode){ + setMeshColor(m_meshnode->getMesh(), color); + m_meshnode->setVisible(is_visible); + } + if(m_spritenode){ + m_spritenode->setColor(color); + m_spritenode->setVisible(is_visible); + } } } diff --git a/src/environment.cpp b/src/environment.cpp index a49a5e384..05629b09d 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -2129,6 +2129,7 @@ void ClientEnvironment::step(float dtime) Step active objects and update lighting of them */ + bool update_lighting = m_active_object_light_update_interval.step(dtime, 0.21); for(core::map::Iterator i = m_active_objects.getIterator(); i.atEnd()==false; i++) @@ -2137,7 +2138,7 @@ void ClientEnvironment::step(float dtime) // Step object obj->step(dtime, this); - if(m_active_object_light_update_interval.step(dtime, 0.21)) + if(update_lighting) { // Update lighting u8 light = 0; From 1cc1b93e65d6d88e20786383cb09caf22a8c6494 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 9 Sep 2012 14:18:14 +0300 Subject: [PATCH 3/6] Fix ServerActiveObject stuff --- src/environment.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/environment.cpp b/src/environment.cpp index 05629b09d..10ebd4127 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -743,19 +743,25 @@ neighbor_found: u32 active_object_count = block->m_static_objects.m_active.size(); // Find out how many objects this and all the neighbors contain u32 active_object_count_wider = 0; + u32 wider_unknown_count = 0; for(s16 x=-1; x<=1; x++) for(s16 y=-1; y<=1; y++) for(s16 z=-1; z<=1; z++) { MapBlock *block2 = map->getBlockNoCreateNoEx( block->getPos() + v3s16(x,y,z)); - if(block2==NULL) + if(block2==NULL){ + wider_unknown_count = 0; continue; + } active_object_count_wider += block2->m_static_objects.m_active.size() + block2->m_static_objects.m_stored.size(); } - + // Extrapolate + u32 wider_known_count = 3*3*3 - wider_unknown_count; + active_object_count_wider += wider_unknown_count * active_object_count_wider / wider_known_count; + // Call all the trigger variations i->abm->trigger(m_env, p, n); i->abm->trigger(m_env, p, n, @@ -1465,9 +1471,10 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, "addActiveObjectRaw"); } else{ + v3s16 p = floatToInt(objectpos, BS); errorstream<<"ServerEnvironment::addActiveObjectRaw(): " <<"could not find block for storing id="<getId() - <<" statically"<emergeBlock(blockpos); + MapBlock *block = NULL; + try{ + block = m_map->emergeBlock(blockpos); + } catch(InvalidPositionException &e){ + // Handled via NULL pointer + } if(block) { @@ -1793,9 +1805,10 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete) } else{ if(!force_delete){ + v3s16 p = floatToInt(objectpos, BS); errorstream<<"ServerEnv: Could not find or generate " <<"a block for storing id="<getId() - <<" statically"< Date: Sun, 9 Sep 2012 17:12:29 +0300 Subject: [PATCH 4/6] Add dtime_s to entity activation --- doc/lua_api.txt | 2 +- src/content_sao.cpp | 10 +++++----- src/content_sao.h | 4 ++-- src/environment.cpp | 14 +++++++------- src/environment.h | 4 ++-- src/scriptapi.cpp | 7 ++++--- src/scriptapi.h | 2 +- src/serverobject.h | 2 +- 8 files changed, 23 insertions(+), 22 deletions(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 782378c1f..8c6fedc1e 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1237,7 +1237,7 @@ Entity definition (register_entity) initial_properties = , - on_activate = function(self, staticdata), + on_activate = function(self, staticdata, dtime_s), on_step = function(self, dtime), on_punch = function(self, hitter), on_rightclick = function(self, clicker), diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 843ab29f7..7526e0353 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -376,9 +376,9 @@ LuaEntitySAO::~LuaEntitySAO() } } -void LuaEntitySAO::addedToEnvironment() +void LuaEntitySAO::addedToEnvironment(u32 dtime_s) { - ServerActiveObject::addedToEnvironment(); + ServerActiveObject::addedToEnvironment(dtime_s); // Create entity from name lua_State *L = m_env->getLua(); @@ -390,7 +390,7 @@ void LuaEntitySAO::addedToEnvironment() // Initialize HP from properties m_hp = m_prop.hp_max; // Activate entity, supplying serialized state - scriptapi_luaentity_activate(L, m_id, m_init_state.c_str()); + scriptapi_luaentity_activate(L, m_id, m_init_state.c_str(), dtime_s); } } @@ -805,9 +805,9 @@ std::string PlayerSAO::getDescription() } // Called after id has been set and has been inserted in environment -void PlayerSAO::addedToEnvironment() +void PlayerSAO::addedToEnvironment(u32 dtime_s) { - ServerActiveObject::addedToEnvironment(); + ServerActiveObject::addedToEnvironment(dtime_s); ServerActiveObject::setBasePosition(m_player->getPosition()); m_player->setPlayerSAO(this); m_player->peer_id = m_peer_id; diff --git a/src/content_sao.h b/src/content_sao.h index ff427bac6..05c77e2cb 100644 --- a/src/content_sao.h +++ b/src/content_sao.h @@ -43,7 +43,7 @@ public: { return ACTIVEOBJECT_TYPE_LUAENTITY; } u8 getSendType() const { return ACTIVEOBJECT_TYPE_GENERIC; } - virtual void addedToEnvironment(); + virtual void addedToEnvironment(u32 dtime_s); static ServerActiveObject* create(ServerEnvironment *env, v3f pos, const std::string &data); void step(float dtime, bool send_recommended); @@ -118,7 +118,7 @@ public: Active object <-> environment interface */ - void addedToEnvironment(); + void addedToEnvironment(u32 dtime_s); void removingFromEnvironment(); bool isStaticAllowed() const; bool unlimitedTransferDistance() const; diff --git a/src/environment.cpp b/src/environment.cpp index 10ebd4127..4abba6359 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -790,7 +790,7 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime) < elapsed_timers = @@ -1249,7 +1249,7 @@ u16 getFreeServerActiveObjectId( u16 ServerEnvironment::addActiveObject(ServerActiveObject *object) { assert(object); - u16 id = addActiveObjectRaw(object, true); + u16 id = addActiveObjectRaw(object, true, 0); return id; } @@ -1408,7 +1408,7 @@ ActiveObjectMessage ServerEnvironment::getActiveObjectMessage() */ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, - bool set_changed) + bool set_changed, u32 dtime_s) { assert(object); if(object->getId() == 0){ @@ -1448,7 +1448,7 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object, // Register reference in scripting api (must be done before post-init) scriptapi_add_object_reference(m_lua, object); // Post-initialize object - object->addedToEnvironment(); + object->addedToEnvironment(dtime_s); // Add static data to block if(object->isStaticAllowed()) @@ -1585,7 +1585,7 @@ static void print_hexdump(std::ostream &o, const std::string &data) /* Convert stored objects from blocks near the players to active. */ -void ServerEnvironment::activateObjects(MapBlock *block) +void ServerEnvironment::activateObjects(MapBlock *block, u32 dtime_s) { if(block==NULL) return; @@ -1609,7 +1609,7 @@ void ServerEnvironment::activateObjects(MapBlock *block) "large amount of objects"); return; } - // A list for objects that couldn't be converted to static for some + // A list for objects that couldn't be converted to active for some // reason. They will be stored back. core::list new_stored; // Loop through stored static objects @@ -1639,7 +1639,7 @@ void ServerEnvironment::activateObjects(MapBlock *block) <<"activated static object pos="< Date: Sun, 9 Sep 2012 21:29:44 +0300 Subject: [PATCH 5/6] Statically store always_collect field of __builtin:item --- builtin/item_entity.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/builtin/item_entity.lua b/builtin/item_entity.lua index 2d763d50b..2b12764f1 100644 --- a/builtin/item_entity.lua +++ b/builtin/item_entity.lua @@ -57,11 +57,23 @@ minetest.register_entity("__builtin:item", { end, get_staticdata = function(self) - return self.itemstring + --return self.itemstring + return minetest.serialize({ + itemstring = self.itemstring, + always_collect = self.always_collect, + }) end, on_activate = function(self, staticdata) - self.itemstring = staticdata + if string.sub(staticdata, 1, string.len("return")) == "return" then + local data = minetest.deserialize(staticdata) + if data and type(data) == "table" then + self.itemstring = data.itemstring + self.always_collect = data.always_collect + end + else + self.itemstring = staticdata + end self.object:set_armor_groups({immortal=1}) self.object:setvelocity({x=0, y=2, z=0}) self.object:setacceleration({x=0, y=-10, z=0}) From 25cf3757b29a0397e201a4719788ead3dc76ec94 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 9 Sep 2012 21:54:11 +0300 Subject: [PATCH 6/6] Add nodedef.on_blast() to lua_api.txt in order to support chained explosions of any explosives --- doc/lua_api.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 8c6fedc1e..442937bd1 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1421,6 +1421,11 @@ Node definition (register_node) on_metadata_inventory_take = func(pos, listname, index, stack, player), ^ Called after the actual action has happened, according to what was allowed. ^ No return value + + on_blast = func(pos, intensity), + ^ intensity: 1.0 = mid range of regular TNT + ^ If defined, called when an explosion touches the node, instead of + removing the node } Recipe for register_craft: (shaped)