1
0
mirror of https://github.com/minetest/minetest.git synced 2025-07-06 09:50:23 +02:00

Wieldhand: Allow overriding the hand

This commit is contained in:
TeTpaAka
2015-06-25 13:06:49 +02:00
committed by paramat
parent e4ee6548af
commit 785a9a6c1a
6 changed files with 64 additions and 4 deletions

View File

@ -1341,6 +1341,42 @@ std::string PlayerSAO::getWieldList() const
return "main";
}
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());
if (ret.name.empty()) {
const InventoryList *hlist = inv->getList("hand");
if (hlist)
ret = hlist->getItem(0);
}
return ret;
}
bool PlayerSAO::setWieldedItem(const ItemStack &item)
{
Inventory *inv = getInventory();
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;
}
}
return false;
}
int PlayerSAO::getWieldIndex() const
{
return m_wield_index;