From bf1825200d63a1a3a93bad7c7b373748555578a3 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Wed, 20 Apr 2016 19:16:19 +0300 Subject: [PATCH] Unification of new API functions --- doc/lua_api.txt | 26 +++++++++++++++++++++++++- src/player.cpp | 6 +++--- src/script/cpp_api/s_player.cpp | 28 +++++++++++----------------- src/script/cpp_api/s_player.h | 3 --- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/doc/lua_api.txt b/doc/lua_api.txt index fdc736906..16bb242bf 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1916,7 +1916,31 @@ Call these functions only at load time! multiple protection mods. * `minetest.register_on_item_eat(func(hp_change, replace_with_item, itemstack, user, pointed_thing))` * Called when an item is eaten, by `minetest.item_eat` - * Return `true` or `itemstack` to cancel the default item eat response (i.e.: hp increase) + * Return `true` or `itemstack` to cancel the default item eat response (i.e.: hp increase)` +* `minetest.register_on_nodemeta_inventory_add_item(func(pos, list_name, slot, stack))` + * Called when any node metadata inventory receive item. + * 'pos' - {'x','y','z'} - absolute position of affected node with metadata. +* `minetest.register_on_nodemeta_inventory_change_item(func(pos, list_name, slot, old_item, new_item))` + * Called when any node metadata inventory change it content in slot number 'slot' from 'old_item' ItemStack to 'new_item' ItemStack. + * 'pos' - {'x','y','z'} - absolute position of affected node with metadata. +* `minetest.register_on_nodemeta_inventory_remove_item(func(pos, list_name, stack))` + * Called when any node metadata inventory loose item. + * 'pos' - {'x','y','z'} - absolute position of affected node with metadata. +* `minetest.register_on_detached_inventory_add_item(func(name, list_name, slot, stack))` + * Called when any detached inventory receive item. + * 'name' - String, name of detached inventory. +* `minetest.register_on_detached_inventory_change_item(func(name, list_name, slot, old_item, new_item))` + * Called when any detached inventory change it content in slot number 'slot' from 'old_item' ItemStack to 'new_item' ItemStack. + * 'name' - String, name of detached inventory. +* `minetest.register_on_detached_inventory_remove_item(func(name, list_name, stack))` + * Called when any detached inventory loose item. + * 'name' - String, name of detached inventory. +* `minetest.register_on_player_inventory_add_item(func(player, list_name, slot, stack))` + * Called when any player receive item. +* `minetest.register_on_player_inventory_change_item(func(player, list_name, slot, old_item, new_item))` + * Called when any players' inventory change it content in slot number 'slot' from 'old_item' ItemStack to 'new_item' ItemStack. +* `minetest.register_on_player_inventory_remove_item(func(player, list_name, stack))` + * Called when any player loose item. ### Other registration functions * `minetest.register_chatcommand(cmd, chatcommand definition)` diff --git a/src/player.cpp b/src/player.cpp index 50c55d744..4abc5b545 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -117,7 +117,7 @@ void Player::on_remove_item(GameScripting *script_interface, const InventoryList { PlayerSAO *player_sao = this->getPlayerSAO(); if(script_interface){ - script_interface->on_player_inventory_remove_item(player_sao, this, inventory_list->getName(), deleted_item); + script_interface->on_player_inventory_remove_item(player_sao, inventory_list->getName(), deleted_item); } } @@ -125,7 +125,7 @@ void Player::on_change_item(GameScripting *script_interface, const InventoryList { PlayerSAO *player_sao = this->getPlayerSAO(); if(script_interface){ - script_interface->on_player_inventory_change_item(player_sao, this, inventory_list->getName(), query_slot, old_item, new_item); + script_interface->on_player_inventory_change_item(player_sao, inventory_list->getName(), query_slot, old_item, new_item); } } @@ -133,7 +133,7 @@ void Player::on_add_item(GameScripting *script_interface, const InventoryList *i { PlayerSAO *player_sao = this->getPlayerSAO(); if(script_interface){ - script_interface->on_player_inventory_add_item(player_sao, this, inventory_list->getName(), query_slot, added_item); + script_interface->on_player_inventory_add_item(player_sao, inventory_list->getName(), query_slot, added_item); } } diff --git a/src/script/cpp_api/s_player.cpp b/src/script/cpp_api/s_player.cpp index c4d93d35b..2a0ef5105 100644 --- a/src/script/cpp_api/s_player.cpp +++ b/src/script/cpp_api/s_player.cpp @@ -194,7 +194,6 @@ void ScriptApiPlayer::on_playerReceiveFields(ServerActiveObject *player, void ScriptApiPlayer::on_player_inventory_remove_item( ServerActiveObject *player_sao, - Player *player, const std::string &inventory_list_name, const ItemStack &deleted_item) { @@ -204,15 +203,13 @@ void ScriptApiPlayer::on_player_inventory_remove_item( lua_getfield(L, -1, "registered_on_player_inventory_remove_item"); // Call callbacks objectrefGetOrCreate(L, player_sao); // player 1 - InvRef::createPlayer(L, player);// InvRef from 2 - lua_pushstring(L, inventory_list_name.c_str());// listname 3 - LuaItemStack::create(L, deleted_item); // stack 4 - runCallbacks(4, RUN_CALLBACKS_MODE_LAST); + lua_pushstring(L, inventory_list_name.c_str());// listname 2 + LuaItemStack::create(L, deleted_item); // stack 3 + runCallbacks(3, RUN_CALLBACKS_MODE_LAST); } void ScriptApiPlayer::on_player_inventory_change_item( ServerActiveObject *player_sao, - Player *player, const std::string &inventory_list_name, u32 query_slot, const ItemStack &old_item, @@ -225,17 +222,15 @@ void ScriptApiPlayer::on_player_inventory_change_item( lua_getfield(L, -1, "registered_on_player_inventory_change_item"); // Call callbacks objectrefGetOrCreate(L, player_sao); // player 1 - InvRef::createPlayer(L, player);// InvRef from 2 - lua_pushstring(L, inventory_list_name.c_str());// listname 3 - lua_pushnumber(L, query_slot);// slot 4 - LuaItemStack::create(L, old_item); // stack 5 - LuaItemStack::create(L, new_item); // stack 6 - runCallbacks(6, RUN_CALLBACKS_MODE_LAST); + lua_pushstring(L, inventory_list_name.c_str());// listname 2 + lua_pushnumber(L, query_slot);// slot 3 + LuaItemStack::create(L, old_item); // stack 4 + LuaItemStack::create(L, new_item); // stack 5 + runCallbacks(5, RUN_CALLBACKS_MODE_LAST); } void ScriptApiPlayer::on_player_inventory_add_item( ServerActiveObject *player_sao, - Player *player, const std::string &inventory_list_name, u32 query_slot, const ItemStack &added_item) @@ -247,11 +242,10 @@ void ScriptApiPlayer::on_player_inventory_add_item( lua_getfield(L, -1, "registered_on_player_inventory_add_item"); // Call callbacks objectrefGetOrCreate(L, player_sao); // player 1 - InvRef::createPlayer(L, player);// InvRef from 2 - lua_pushstring(L, inventory_list_name.c_str());// listname 3 + lua_pushstring(L, inventory_list_name.c_str());// listname 2 lua_pushnumber(L, query_slot); - LuaItemStack::create(L, added_item); // stack 5 - runCallbacks(5, RUN_CALLBACKS_MODE_LAST); + LuaItemStack::create(L, added_item); // stack 4 + runCallbacks(4, RUN_CALLBACKS_MODE_LAST); } diff --git a/src/script/cpp_api/s_player.h b/src/script/cpp_api/s_player.h index 3a20c10e4..e45954272 100644 --- a/src/script/cpp_api/s_player.h +++ b/src/script/cpp_api/s_player.h @@ -51,19 +51,16 @@ public: const std::string &formname, const StringMap &fields); void on_player_inventory_remove_item( ServerActiveObject *player_sao, - Player *player, const std::string &inventory_list_name, const ItemStack &deleted_item); void on_player_inventory_change_item( ServerActiveObject *player_sao, - Player *player, const std::string &inventory_list_name, u32 query_slot, const ItemStack &old_item, const ItemStack &new_item); void on_player_inventory_add_item( ServerActiveObject *player_sao, - Player *player, const std::string &inventory_list_name, u32 query_slot, const ItemStack &added_item);