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/content_sao.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/content_sao.cpp')
-rw-r--r-- | src/content_sao.cpp | 65 |
1 files changed, 10 insertions, 55 deletions
diff --git a/src/content_sao.cpp b/src/content_sao.cpp index c0bc25a4d..0f1e2f435 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -896,18 +896,11 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t p m_armor_groups["immortal"] = 1; } -PlayerSAO::~PlayerSAO() -{ - if(m_inventory != &m_player->inventory) - delete m_inventory; -} - void PlayerSAO::finalize(RemotePlayer *player, const std::set<std::string> &privs) { assert(player); m_player = player; m_privs = privs; - m_inventory = &m_player->inventory; } v3f PlayerSAO::getEyeOffset() const @@ -1365,13 +1358,9 @@ void PlayerSAO::setBreath(const u16 breath, bool send) m_env->getGameDef()->SendPlayerBreath(this); } -Inventory* PlayerSAO::getInventory() -{ - return m_inventory; -} -const Inventory* PlayerSAO::getInventory() const +Inventory *PlayerSAO::getInventory() const { - return m_inventory; + return m_player ? &m_player->inventory : nullptr; } InventoryLocation PlayerSAO::getInventoryLocation() const @@ -1381,61 +1370,27 @@ InventoryLocation PlayerSAO::getInventoryLocation() const return loc; } -std::string PlayerSAO::getWieldList() const +u16 PlayerSAO::getWieldIndex() const { - return "main"; + return m_player->getWieldIndex(); } 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; - 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; + ItemStack selected_item, hand_item; + return m_player->getWieldedItem(&selected_item, &hand_item); } bool PlayerSAO::setWieldedItem(const ItemStack &item) { - Inventory *inv = getInventory(); - if (inv) { - InventoryList *mlist = inv->getList(getWieldList()); - if (mlist) { - mlist->changeItem(getWieldIndex(), item); - return true; - } + InventoryList *mlist = m_player->inventory.getList(getWieldList()); + if (mlist) { + mlist->changeItem(m_player->getWieldIndex(), item); + return true; } return false; } -int PlayerSAO::getWieldIndex() const -{ - return m_wield_index; -} - -void PlayerSAO::setWieldIndex(int i) -{ - if(i != m_wield_index) { - m_wield_index = i; - } -} - void PlayerSAO::disconnected() { m_peer_id = 0; |