diff options
author | x12xx12x <44411062+12xx12@users.noreply.github.com> | 2021-12-02 00:31:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-02 00:31:10 +0100 |
commit | 3ff57559e36d3254c64e334fbe3bdd47398fe16f (patch) | |
tree | 30a73d405640285863bfa9932afbee482f36b50c /src/ClientHandle.cpp | |
parent | Added ExperienceAmount variable to HOOK_PLAYER_FISHING and HOOK_PLAYER_FISHED (#5345) (diff) | |
download | cuberite-3ff57559e36d3254c64e334fbe3bdd47398fe16f.tar cuberite-3ff57559e36d3254c64e334fbe3bdd47398fe16f.tar.gz cuberite-3ff57559e36d3254c64e334fbe3bdd47398fe16f.tar.bz2 cuberite-3ff57559e36d3254c64e334fbe3bdd47398fe16f.tar.lz cuberite-3ff57559e36d3254c64e334fbe3bdd47398fe16f.tar.xz cuberite-3ff57559e36d3254c64e334fbe3bdd47398fe16f.tar.zst cuberite-3ff57559e36d3254c64e334fbe3bdd47398fe16f.zip |
Diffstat (limited to 'src/ClientHandle.cpp')
-rw-r--r-- | src/ClientHandle.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index a42212002..1d9b8e2a6 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -1164,8 +1164,8 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB case DIG_STATUS_SHOOT_EAT: { - cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem()); - if (ItemHandler->IsFood() || ItemHandler->IsDrinkable(m_Player->GetEquippedItem().m_ItemDamage)) + auto & ItemHandler = m_Player->GetEquippedItem().GetHandler(); + if (ItemHandler.IsFood() || ItemHandler.IsDrinkable(m_Player->GetEquippedItem().m_ItemDamage)) { m_Player->AbortEating(); return; @@ -1180,9 +1180,12 @@ void cClientHandle::HandleLeftClick(int a_BlockX, int a_BlockY, int a_BlockZ, eB // When bow is in off-hand / shield slot if (m_Player->GetInventory().GetShieldSlot().m_ItemType == E_ITEM_BOW) { - ItemHandler = cItemHandler::GetItemHandler(m_Player->GetInventory().GetShieldSlot()); + m_Player->GetInventory().GetShieldSlot().GetHandler().OnItemShoot(m_Player, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace); + } + else + { + ItemHandler.OnItemShoot(m_Player, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace); } - ItemHandler->OnItemShoot(m_Player, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace); } return; } @@ -1319,8 +1322,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc cChunkInterface ChunkInterface(World->GetChunkMap()); cBlockHandler::For(DiggingBlock).OnDigging(ChunkInterface, *World, *m_Player, {a_BlockX, a_BlockY, a_BlockZ}); - cItemHandler * ItemHandler = cItemHandler::GetItemHandler(m_Player->GetEquippedItem()); - ItemHandler->OnDiggingBlock(World, m_Player, m_Player->GetEquippedItem(), {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace); + m_Player->GetEquippedItem().GetHandler().OnDiggingBlock(World, m_Player, m_Player->GetEquippedItem(), {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace); } @@ -1452,7 +1454,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e // TODO: We are still consuming the items in main hand. Remove this override when the off-hand consumption is handled correctly. a_UsedMainHand = true; const cItem & HeldItem = a_UsedMainHand ? m_Player->GetEquippedItem() : m_Player->GetInventory().GetShieldSlot(); - cItemHandler * ItemHandler = cItemHandler::GetItemHandler(HeldItem.m_ItemType); + auto & ItemHandler = HeldItem.GetHandler(); // TODO: This distance should be calculated from the point that the cursor pointing at, instead of the center of the block // Distance from the block's center to the player's eye height @@ -1480,7 +1482,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e World->GetBlockTypeMeta(ClickedBlockPos, BlockType, BlockMeta); const auto & BlockHandler = cBlockHandler::For(BlockType); - bool Placeable = ItemHandler->IsPlaceable() && !m_Player->IsGameModeAdventure() && !m_Player->IsGameModeSpectator(); + bool Placeable = ItemHandler.IsPlaceable() && !m_Player->IsGameModeAdventure() && !m_Player->IsGameModeSpectator(); bool BlockUsable = BlockHandler.IsUseable() && (!m_Player->IsGameModeSpectator() || cBlockInfo::IsUseableBySpectator(BlockType)); if (BlockUsable && !(m_Player->IsCrouched() && !HeldItem.IsEmpty())) @@ -1499,7 +1501,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e if (Placeable) { // Place a block: - ItemHandler->OnPlayerPlace(*m_Player, HeldItem, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace, {a_CursorX, a_CursorY, a_CursorZ}); + ItemHandler.OnPlayerPlace(*m_Player, HeldItem, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace, {a_CursorX, a_CursorY, a_CursorZ}); } return; @@ -1516,7 +1518,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e } // Place a block: - ItemHandler->OnPlayerPlace(*m_Player, HeldItem, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace, {a_CursorX, a_CursorY, a_CursorZ}); + ItemHandler.OnPlayerPlace(*m_Player, HeldItem, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace, {a_CursorX, a_CursorY, a_CursorZ}); return; } else if (!PlgMgr->CallHookPlayerUsingItem(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ)) @@ -1525,7 +1527,7 @@ void cClientHandle::HandleRightClick(int a_BlockX, int a_BlockY, int a_BlockZ, e // Use an item in hand with a target block. cBlockInServerPluginInterface PluginInterface(*World); - ItemHandler->OnItemUse(World, m_Player, PluginInterface, HeldItem, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace); + ItemHandler.OnItemUse(World, m_Player, PluginInterface, HeldItem, {a_BlockX, a_BlockY, a_BlockZ}, a_BlockFace); PlgMgr->CallHookPlayerUsedItem(*m_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ); return; } @@ -1854,7 +1856,7 @@ void cClientHandle::HandleUseItem(bool a_UsedMainHand) // TODO: We are still consuming the items in main hand. Remove this override when the off-hand consumption is handled correctly. a_UsedMainHand = true; const cItem & HeldItem = a_UsedMainHand ? m_Player->GetEquippedItem() : m_Player->GetInventory().GetShieldSlot(); - cItemHandler * ItemHandler = cItemHandler::GetItemHandler(HeldItem.m_ItemType); + auto & ItemHandler = HeldItem.GetHandler(); cWorld * World = m_Player->GetWorld(); cPluginManager * PlgMgr = cRoot::Get()->GetPluginManager(); @@ -1872,10 +1874,10 @@ void cClientHandle::HandleUseItem(bool a_UsedMainHand) return; } - if (ItemHandler->IsFood() || ItemHandler->IsDrinkable(HeldItem.m_ItemDamage)) + if (ItemHandler.IsFood() || ItemHandler.IsDrinkable(HeldItem.m_ItemDamage)) { if ( - ItemHandler->IsFood() && + ItemHandler.IsFood() && (m_Player->IsSatiated() || m_Player->IsGameModeCreative()) && // Only non-creative or hungry players can eat (HeldItem.m_ItemType != E_ITEM_GOLDEN_APPLE) && // Golden apple is a special case, it is used instead of eaten (HeldItem.m_ItemType != E_ITEM_CHORUS_FRUIT) // Chorus fruit is a special case, it is used instead of eaten @@ -1896,7 +1898,7 @@ void cClientHandle::HandleUseItem(bool a_UsedMainHand) { // All plugins agree with using the item cBlockInServerPluginInterface PluginInterface(*World); - ItemHandler->OnItemUse(World, m_Player, PluginInterface, HeldItem, {-1, 255, -1}, BLOCK_FACE_NONE); + ItemHandler.OnItemUse(World, m_Player, PluginInterface, HeldItem, {-1, 255, -1}, BLOCK_FACE_NONE); PlgMgr->CallHookPlayerUsedItem(*m_Player, -1, 255, -1, BLOCK_FACE_NONE, 0, 0, 0); } } |