1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-12 16:58:39 +00:00

Fix problems when overriding the hand:

- If the hand can dig a node the item wielded can't, allow to dig it anyway.
- Fix the API callbacks from setting the hand instead of the wielded item.
This commit is contained in:
Ekdohibs 2017-03-22 03:25:16 +01:00 committed by Auke Kok
parent bce0d458d8
commit 08b680d588
4 changed files with 38 additions and 20 deletions

View file

@ -1271,6 +1271,16 @@ std::string PlayerSAO::getWieldList() const
}
ItemStack PlayerSAO::getWieldedItem() const
{
const Inventory *inv = getInventory();
ItemStack ret;
const InventoryList *mlist = inv->getList(getWieldList());
if (mlist && getWieldIndex() < (s32)mlist->getSize())
ret = mlist->getItem(getWieldIndex());
return ret;
}
ItemStack PlayerSAO::getWieldedItemOrHand() const
{
const Inventory *inv = getInventory();
ItemStack ret;
@ -1291,14 +1301,6 @@ bool PlayerSAO::setWieldedItem(const ItemStack &item)
if (inv) {
InventoryList *mlist = inv->getList(getWieldList());
if (mlist) {
ItemStack olditem = mlist->getItem(getWieldIndex());
if (olditem.name.empty()) {
InventoryList *hlist = inv->getList("hand");
if (hlist) {
hlist->changeItem(0, item);
return true;
}
}
mlist->changeItem(getWieldIndex(), item);
return true;
}