diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2019-08-07 19:16:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-07 19:16:31 +0200 |
commit | e462a9a5ef46776d974203bb44e0b89e8c980b29 (patch) | |
tree | 4562ef5587bd896890d843877031d5818de19bbc /src/player.cpp | |
parent | 003af7421352ec1b8ba0d230b807862e1e4cc7e9 (diff) | |
download | minetest-e462a9a5ef46776d974203bb44e0b89e8c980b29.tar.gz minetest-e462a9a5ef46776d974203bb44e0b89e8c980b29.tar.bz2 minetest-e462a9a5ef46776d974203bb44e0b89e8c980b29.zip |
Unify wield item handling (#8677)
This moves the wield item functions to Player and the tool utils for range calculation
Also 'local_inventory' was removed due to redundancy in Client
Diffstat (limited to 'src/player.cpp')
-rw-r--r-- | src/player.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/player.cpp b/src/player.cpp index 9beeab74e..d3ba5c2c2 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -90,6 +90,29 @@ Player::~Player() clearHud(); } +void Player::setWieldIndex(u16 index) +{ + const InventoryList *mlist = inventory.getList("main"); + m_wield_index = MYMIN(index, mlist ? mlist->getSize() : 0); +} + +ItemStack &Player::getWieldedItem(ItemStack *selected, ItemStack *hand) const +{ + assert(selected); + + const InventoryList *mlist = inventory.getList("main"); // TODO: Make this generic + const InventoryList *hlist = inventory.getList("hand"); + + if (mlist && m_wield_index < mlist->getSize()) + *selected = mlist->getItem(m_wield_index); + + if (hand && hlist) + *hand = hlist->getItem(0); + + // Return effective tool item + return (hand && selected->name.empty()) ? *hand : *selected; +} + u32 Player::addHud(HudElement *toadd) { MutexAutoLock lock(m_mutex); |