diff options
author | sfan5 <sfan5@live.de> | 2020-03-04 19:13:26 +0100 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2020-03-05 22:04:23 +0100 |
commit | e774d8ca2fa5ead9f6d739a2031e6655a22a5b4d (patch) | |
tree | 6aba5db64df6c5773bdca50cc22a66e4832909a4 | |
parent | 8d6a0b917ce1e7f4f1017835af0ca76e79c98c38 (diff) | |
download | minetest-e774d8ca2fa5ead9f6d739a2031e6655a22a5b4d.tar.gz minetest-e774d8ca2fa5ead9f6d739a2031e6655a22a5b4d.tar.bz2 minetest-e774d8ca2fa5ead9f6d739a2031e6655a22a5b4d.zip |
Fixes around ServerActiveObject on_punch handling
-rw-r--r-- | doc/lua_api.txt | 1 | ||||
-rw-r--r-- | src/content_sao.cpp | 5 | ||||
-rw-r--r-- | src/network/serverpackethandler.cpp | 2 |
3 files changed, 6 insertions, 2 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt index acf2f77c1..a603a5a37 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -3900,6 +3900,7 @@ Callbacks: * `dir`: unit vector of direction of punch. Always defined. Points from the puncher to the punched. * `damage`: damage that will be done to entity. + * Can return `true` to prevent the default damage mechanism. * `on_death(self, killer)` * Called when the object dies. * `killer`: an `ObjectRef` (can be `nil`) diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 5119223a7..75c3eaf37 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -653,7 +653,7 @@ u16 LuaEntitySAO::punch(v3f dir, if (!damage_handled) { if (result.did_punch) { setHP((s32)getHP() - result.damage, - PlayerHPChangeReason(PlayerHPChangeReason::SET_HP)); + PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher)); std::string str = gob_cmd_punched(getHP()); // create message and add to list @@ -663,10 +663,10 @@ u16 LuaEntitySAO::punch(v3f dir, } if (getHP() == 0 && !isGone()) { - m_pending_removal = true; clearParentAttachment(); clearChildAttachments(); m_env->getScriptIface()->luaentity_on_death(m_id, puncher); + m_pending_removal = true; } actionstream << puncher->getDescription() << " (id=" << puncher->getId() << @@ -675,6 +675,7 @@ u16 LuaEntitySAO::punch(v3f dir, "), damage=" << (old_hp - (s32)getHP()) << (damage_handled ? " (handled by Lua)" : "") << std::endl; + // TODO: give Lua control over wear return result.wear; } diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 7a42ce5ef..23bcc867f 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -1166,6 +1166,8 @@ void Server::handleCommand_Interact(NetworkPacket *pkt) u16 wear = pointed_object->punch(dir, &toolcap, playersao, time_from_last_punch); + // Callback may have changed item, so get it again + playersao->getWieldedItem(&selected_item); bool changed = selected_item.addWear(wear, m_itemdef); if (changed) playersao->setWieldedItem(selected_item); |