^ Called when a player wants to put something into the inventory
^ Return value: number of items allowed to put
- allow_metadata_inventory_take = func(pos, listname, index, count, player),
+ allow_metadata_inventory_take = func(pos, listname, index, stack, player),
^ Called when a player wants to take something out of the inventory
^ Return value: number of items allowed to take
on_metadata_inventory_move = func(pos, from_list, from_index,
to_list, to_index, count, player),
on_metadata_inventory_put = func(pos, listname, index, stack, player),
- on_metadata_inventory_take = func(pos, listname, index, count, player),
+ 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
}
^ Called when a player wants to put something into the inventory
^ Return value: number of items allowed to put
- allow_take = func(inv, listname, index, count, player),
+ allow_take = func(inv, listname, index, stack, player),
^ Called when a player wants to take something out of the inventory
^ Return value: number of items allowed to take
on_move = func(inv, from_list, from_index, to_list, to_index, count, player),
on_put = func(inv, listname, index, stack, player),
- on_take = func(inv, listname, index, count, player),
+ on_take = func(inv, listname, index, stack, player),
^ Called after the actual action has happened, according to what was allowed.
^ No return value
}
end
return stack:get_count()
end,
- allow_metadata_inventory_take = function(pos, listname, index, count, player)
+ allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local meta = minetest.env:get_meta(pos)
if not has_locked_chest_privilege(meta, player) then
minetest.log("action", player:get_player_name()..
minetest.pos_to_string(pos))
return 0
end
- return count
+ return stack:get_count()
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", player:get_player_name()..
minetest.log("action", player:get_player_name()..
" moves stuff to locked chest at "..minetest.pos_to_string(pos))
end,
- on_metadata_inventory_take = function(pos, listname, index, count, player)
+ on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()..
" takes stuff from locked chest at "..minetest.pos_to_string(pos))
end,
experimental.print_to_everything("allow put asked")
return 1 -- Allow only 1
end,
- allow_take = function(inv, listname, index, count, player)
+ allow_take = function(inv, listname, index, stack, player)
experimental.print_to_everything("allow take asked")
return 4 -- Allow 4 at max
end,
on_put = function(inv, listname, index, stack, player)
experimental.print_to_everything(player:get_player_name().." put items")
end,
- on_take = function(inv, listname, index, count, player)
+ on_take = function(inv, listname, index, stack, player)
experimental.print_to_everything(player:get_player_name().." took items")
end,
})
if(from_inv.type == InventoryLocation::DETACHED)
{
lua_State *L = player->getEnv()->getLua();
+ ItemStack src_item = list_from->getItem(from_i);
+ src_item.count = try_take_count;
src_can_take_count = scriptapi_detached_inventory_allow_take(
- L, from_inv.name, from_list, from_i, try_take_count, player);
+ L, from_inv.name, from_list, from_i, src_item, player);
}
}
if(from_inv.type == InventoryLocation::NODEMETA)
{
lua_State *L = player->getEnv()->getLua();
+ ItemStack src_item = list_from->getItem(from_i);
+ src_item.count = try_take_count;
src_can_take_count = scriptapi_nodemeta_inventory_allow_take(
- L, from_inv.p, from_list, from_i, try_take_count, player);
+ L, from_inv.p, from_list, from_i, src_item, player);
}
}
}
count = new_count;
+
+ ItemStack src_item = list_from->getItem(from_i);
+ src_item.count = count;
/*
Perform actual move
if(to_inv.type == InventoryLocation::DETACHED)
{
lua_State *L = player->getEnv()->getLua();
- ItemStack src_item = list_from->getItem(from_i);
- src_item.count = count;
scriptapi_detached_inventory_on_put(
L, to_inv.name, to_list, to_i, src_item, player);
}
if(from_inv.type == InventoryLocation::DETACHED)
{
lua_State *L = player->getEnv()->getLua();
- ItemStack src_item = list_from->getItem(from_i);
- src_item.count = count;
scriptapi_detached_inventory_on_take(
- L, from_inv.name, from_list, from_i, src_item.count, player);
+ L, from_inv.name, from_list, from_i, src_item, player);
}
}
if(to_inv.type == InventoryLocation::NODEMETA)
{
lua_State *L = player->getEnv()->getLua();
- ItemStack src_item = list_from->getItem(from_i);
- src_item.count = count;
scriptapi_nodemeta_inventory_on_put(
L, to_inv.p, to_list, to_i, src_item, player);
}
else if(from_inv.type == InventoryLocation::NODEMETA)
{
lua_State *L = player->getEnv()->getLua();
- ItemStack src_item = list_from->getItem(from_i);
- src_item.count = count;
scriptapi_nodemeta_inventory_on_take(
- L, from_inv.p, from_list, from_i, src_item.count, player);
+ L, from_inv.p, from_list, from_i, src_item, player);
}
}
if(from_inv.type == InventoryLocation::DETACHED)
{
lua_State *L = player->getEnv()->getLua();
+ ItemStack src_item = list_from->getItem(from_i);
+ src_item.count = take_count;
src_can_take_count = scriptapi_detached_inventory_allow_take(
- L, from_inv.name, from_list, from_i, take_count, player);
+ L, from_inv.name, from_list, from_i, src_item, player);
}
// Source is nodemeta
if(from_inv.type == InventoryLocation::NODEMETA)
{
lua_State *L = player->getEnv()->getLua();
+ ItemStack src_item = list_from->getItem(from_i);
+ src_item.count = take_count;
src_can_take_count = scriptapi_nodemeta_inventory_allow_take(
- L, from_inv.p, from_list, from_i, take_count, player);
+ L, from_inv.p, from_list, from_i, src_item, player);
}
if(src_can_take_count < take_count)
int actually_dropped_count = 0;
+ ItemStack src_item = list_from->getItem(from_i);
+
// Drop the item
ItemStack item1 = list_from->getItem(from_i);
if(scriptapi_item_on_drop(player->getEnv()->getLua(), item1, player,
<<" list=\""<<from_list<<"\""
<<" i="<<from_i
<<std::endl;
+
+ src_item.count = actually_dropped_count;
/*
Report drop to endpoints
{
lua_State *L = player->getEnv()->getLua();
scriptapi_detached_inventory_on_take(
- L, from_inv.name, from_list, from_i, actually_dropped_count, player);
+ L, from_inv.name, from_list, from_i, src_item, player);
}
// Source is nodemeta
{
lua_State *L = player->getEnv()->getLua();
scriptapi_nodemeta_inventory_on_take(
- L, from_inv.p, from_list, from_i, actually_dropped_count, player);
+ L, from_inv.p, from_list, from_i, src_item, player);
}
}
objectref_get_or_create(L, player);
if(lua_pcall(L, 7, 1, 0))
script_error(L, "error: %s", lua_tostring(L, -1));
+ if(!lua_isnumber(L, -1))
+ throw LuaError(L, "allow_metadata_inventory_move should return a number");
return luaL_checkinteger(L, -1);
}
objectref_get_or_create(L, player);
if(lua_pcall(L, 5, 1, 0))
script_error(L, "error: %s", lua_tostring(L, -1));
+ if(!lua_isnumber(L, -1))
+ throw LuaError(L, "allow_metadata_inventory_put should return a number");
return luaL_checkinteger(L, -1);
}
// Return number of accepted items to be taken
int scriptapi_nodemeta_inventory_allow_take(lua_State *L, v3s16 p,
- const std::string &listname, int index, int count,
+ const std::string &listname, int index, ItemStack &stack,
ServerActiveObject *player)
{
realitycheck(L);
// Push callback function on stack
if(!get_item_callback(L, ndef->get(node).name.c_str(),
"allow_metadata_inventory_take"))
- return count;
+ return stack.count;
// Call function(pos, listname, index, count, player)
// pos
lua_pushstring(L, listname.c_str());
// index
lua_pushinteger(L, index + 1);
- // count
- lua_pushinteger(L, count);
+ // stack
+ LuaItemStack::create(L, stack);
// player
objectref_get_or_create(L, player);
if(lua_pcall(L, 5, 1, 0))
script_error(L, "error: %s", lua_tostring(L, -1));
+ if(!lua_isnumber(L, -1))
+ throw LuaError(L, "allow_metadata_inventory_take should return a number");
return luaL_checkinteger(L, -1);
}
// Report taken items
void scriptapi_nodemeta_inventory_on_take(lua_State *L, v3s16 p,
- const std::string &listname, int index, int count,
+ const std::string &listname, int index, ItemStack &stack,
ServerActiveObject *player)
{
realitycheck(L);
"on_metadata_inventory_take"))
return;
- // Call function(pos, listname, index, count, player)
+ // Call function(pos, listname, index, stack, player)
// pos
push_v3s16(L, p);
// listname
lua_pushstring(L, listname.c_str());
// index
lua_pushinteger(L, index + 1);
- // count
- lua_pushinteger(L, count);
+ // stack
+ LuaItemStack::create(L, stack);
// player
objectref_get_or_create(L, player);
if(lua_pcall(L, 5, 0, 0))
objectref_get_or_create(L, player);
if(lua_pcall(L, 7, 1, 0))
script_error(L, "error: %s", lua_tostring(L, -1));
+ if(!lua_isnumber(L, -1))
+ throw LuaError(L, "allow_move should return a number");
return luaL_checkinteger(L, -1);
}
objectref_get_or_create(L, player);
if(lua_pcall(L, 5, 1, 0))
script_error(L, "error: %s", lua_tostring(L, -1));
+ if(!lua_isnumber(L, -1))
+ throw LuaError(L, "allow_put should return a number");
return luaL_checkinteger(L, -1);
}
// Return number of accepted items to be taken
int scriptapi_detached_inventory_allow_take(lua_State *L,
const std::string &name,
- const std::string &listname, int index, int count,
+ const std::string &listname, int index, ItemStack &stack,
ServerActiveObject *player)
{
realitycheck(L);
// Push callback function on stack
if(!get_detached_inventory_callback(L, name, "allow_take"))
- return count; // All will be accepted
+ return stack.count; // All will be accepted
- // Call function(inv, listname, index, count, player)
+ // Call function(inv, listname, index, stack, player)
// inv
InventoryLocation loc;
loc.setDetached(name);
lua_pushstring(L, listname.c_str());
// index
lua_pushinteger(L, index + 1);
- // count
- lua_pushinteger(L, count);
+ // stack
+ LuaItemStack::create(L, stack);
// player
objectref_get_or_create(L, player);
if(lua_pcall(L, 5, 1, 0))
script_error(L, "error: %s", lua_tostring(L, -1));
+ if(!lua_isnumber(L, -1))
+ throw LuaError(L, "allow_take should return a number");
return luaL_checkinteger(L, -1);
}
// Report taken items
void scriptapi_detached_inventory_on_take(lua_State *L,
const std::string &name,
- const std::string &listname, int index, int count,
+ const std::string &listname, int index, ItemStack &stack,
ServerActiveObject *player)
{
realitycheck(L);
if(!get_detached_inventory_callback(L, name, "on_take"))
return;
- // Call function(inv, listname, index, count, player)
+ // Call function(inv, listname, index, stack, player)
// inv
InventoryLocation loc;
loc.setDetached(name);
lua_pushstring(L, listname.c_str());
// index
lua_pushinteger(L, index + 1);
- // count
- lua_pushinteger(L, count);
+ // stack
+ LuaItemStack::create(L, stack);
// player
objectref_get_or_create(L, player);
if(lua_pcall(L, 5, 0, 0))
ServerActiveObject *player);
// Return number of accepted items to be taken
int scriptapi_nodemeta_inventory_allow_take(lua_State *L, v3s16 p,
- const std::string &listname, int index, int count,
+ const std::string &listname, int index, ItemStack &stack,
ServerActiveObject *player);
// Report moved items
void scriptapi_nodemeta_inventory_on_move(lua_State *L, v3s16 p,
ServerActiveObject *player);
// Report taken items
void scriptapi_nodemeta_inventory_on_take(lua_State *L, v3s16 p,
- const std::string &listname, int index, int count,
+ const std::string &listname, int index, ItemStack &stack,
ServerActiveObject *player);
/* Detached inventory callbacks */
// Return number of accepted items to be taken
int scriptapi_detached_inventory_allow_take(lua_State *L,
const std::string &name,
- const std::string &listname, int index, int count,
+ const std::string &listname, int index, ItemStack &stack,
ServerActiveObject *player);
// Report moved items
void scriptapi_detached_inventory_on_move(lua_State *L,
// Report taken items
void scriptapi_detached_inventory_on_take(lua_State *L,
const std::string &name,
- const std::string &listname, int index, int count,
+ const std::string &listname, int index, ItemStack &stack,
ServerActiveObject *player);
/* luaentity */