diff options
author | TeTpaAka <TeTpaAka@users.noreply.github.com> | 2015-06-25 13:06:49 +0200 |
---|---|---|
committer | paramat <mat.gregory@virginmedia.com> | 2016-11-26 03:49:30 +0000 |
commit | 785a9a6c1af424b0a46f334de7176c9e67341cfb (patch) | |
tree | f0b33e1c47e65800beacae8d6c905c8a02307674 /src/content_sao.cpp | |
parent | e4ee6548afd01040046ee3780d0fbb121d141251 (diff) | |
download | minetest-785a9a6c1af424b0a46f334de7176c9e67341cfb.tar.gz minetest-785a9a6c1af424b0a46f334de7176c9e67341cfb.tar.bz2 minetest-785a9a6c1af424b0a46f334de7176c9e67341cfb.zip |
Wieldhand: Allow overriding the hand
Diffstat (limited to 'src/content_sao.cpp')
-rw-r--r-- | src/content_sao.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 6caea5198..609673ed9 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -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; |