1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add player inventory callbacks

This commit is contained in:
SmallJoker 2018-03-31 12:30:43 +02:00 committed by Loïc Blot
parent 12edb200eb
commit f6eff57f7c
5 changed files with 259 additions and 1 deletions

View file

@ -314,6 +314,33 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
}
}
// Query player inventories
// Move occurs in the same player inventory
if (from_inv.type == InventoryLocation::PLAYER &&
to_inv.type == InventoryLocation::PLAYER &&
from_inv.name == to_inv.name) {
src_can_take_count = PLAYER_TO_SA(player)->player_inventory_AllowMove(
from_inv, from_list, from_i,
to_list, to_i, try_take_count, player);
dst_can_put_count = src_can_take_count;
} else {
// Destination is a player
if (to_inv.type == InventoryLocation::PLAYER) {
ItemStack src_item = list_from->getItem(from_i);
src_item.count = try_take_count;
dst_can_put_count = PLAYER_TO_SA(player)->player_inventory_AllowPut(
to_inv, to_list, to_i, src_item, player);
}
// Source is a player
if (from_inv.type == InventoryLocation::PLAYER) {
ItemStack src_item = list_from->getItem(from_i);
src_item.count = try_take_count;
src_can_take_count = PLAYER_TO_SA(player)->player_inventory_AllowTake(
from_inv, from_list, from_i, src_item, player);
}
}
int old_count = count;
/* Modify count according to collected data */
@ -482,12 +509,34 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
to_inv.p, to_list, to_i, src_item, player);
}
// Source is nodemeta
else if (from_inv.type == InventoryLocation::NODEMETA) {
if (from_inv.type == InventoryLocation::NODEMETA) {
PLAYER_TO_SA(player)->nodemeta_inventory_OnTake(
from_inv.p, from_list, from_i, src_item, player);
}
}
// Player inventories
// Both endpoints are same player inventory
if (from_inv.type == InventoryLocation::PLAYER &&
to_inv.type == InventoryLocation::PLAYER &&
from_inv.name == to_inv.name) {
PLAYER_TO_SA(player)->player_inventory_OnMove(
from_inv, from_list, from_i,
to_list, to_i, count, player);
} else {
// Destination is player inventory
if (to_inv.type == InventoryLocation::PLAYER) {
PLAYER_TO_SA(player)->player_inventory_OnPut(
to_inv, to_list, to_i, src_item, player);
}
// Source is player inventory
if (from_inv.type == InventoryLocation::PLAYER) {
PLAYER_TO_SA(player)->player_inventory_OnTake(
from_inv, from_list, from_i, src_item, player);
}
}
mgr->setInventoryModified(from_inv, false);
if (inv_from != inv_to)
mgr->setInventoryModified(to_inv, false);