mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
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
This commit is contained in:
parent
003af74213
commit
e462a9a5ef
14 changed files with 154 additions and 249 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue