mirror of
https://github.com/minetest/minetest.git
synced 2025-07-01 07:30:23 +02:00
Unification of new API functions
This commit is contained in:
@ -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)`
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user