diff options
Diffstat (limited to 'src/Entities/Player.cpp')
-rw-r--r-- | src/Entities/Player.cpp | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 04a7f9be0..43632f551 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -17,6 +17,7 @@ #include "../Items/ItemHandler.h" #include "../FastRandom.h" #include "../ClientHandle.h" +#include "Entities/Pickup.h" #include "../WorldStorage/StatisticsSerializer.h" #include "../CompositeChat.h" @@ -475,24 +476,6 @@ bool cPlayer::IsStanding() const -void cPlayer::TossItems(const cItems & a_Items) -{ - if (IsGameModeSpectator()) // Players can't toss items in spectator - { - return; - } - - m_Stats.Custom[CustomStatistic::Drop] += static_cast<StatisticsManager::StatValue>(a_Items.Size()); - - const auto Speed = (GetLookVector() + Vector3d(0, 0.2, 0)) * 6; // A dash of height and a dollop of speed - const auto Position = GetEyePosition() - Vector3d(0, 0.2, 0); // Correct for eye-height weirdness - m_World->SpawnItemPickups(a_Items, Position, Speed, true); // 'true' because created by player -} - - - - - void cPlayer::SetIsInBed(const bool a_GoToBed) { if (a_GoToBed && IsStanding()) @@ -1719,7 +1702,6 @@ void cPlayer::SetDraggingItem(const cItem & a_Item) void cPlayer::TossEquippedItem(char a_Amount) { - cItems Drops; cItem DroppedItem(GetInventory().GetEquippedItem()); if (!DroppedItem.IsEmpty()) { @@ -1732,10 +1714,8 @@ void cPlayer::TossEquippedItem(char a_Amount) GetInventory().GetHotbarGrid().ChangeSlotCount(GetInventory().GetEquippedSlotNum() /* Returns hotbar subslot, which HotbarGrid takes */, -a_Amount); DroppedItem.m_ItemCount = NewAmount; - Drops.push_back(DroppedItem); + TossPickup(DroppedItem); } - - TossItems(Drops); } @@ -1763,13 +1743,12 @@ void cPlayer::ReplaceOneEquippedItemTossRest(const cItem & a_Item) void cPlayer::TossHeldItem(char a_Amount) { - cItems Drops; cItem & Item = GetDraggingItem(); if (!Item.IsEmpty()) { char OriginalItemAmount = Item.m_ItemCount; Item.m_ItemCount = std::min(OriginalItemAmount, a_Amount); - Drops.push_back(Item); + TossPickup(Item); if (OriginalItemAmount > a_Amount) { @@ -1780,8 +1759,6 @@ void cPlayer::TossHeldItem(char a_Amount) Item.Empty(); } } - - TossItems(Drops); } @@ -1790,10 +1767,16 @@ void cPlayer::TossHeldItem(char a_Amount) void cPlayer::TossPickup(const cItem & a_Item) { - cItems Drops; - Drops.push_back(a_Item); + if (IsGameModeSpectator()) // Players can't toss items in spectator + { + return; + } + + m_Stats.Custom[CustomStatistic::Drop] += 1U; - TossItems(Drops); + const auto Speed = (GetLookVector() + Vector3d(0, 0.2, 0)) * 6; // A dash of height and a dollop of speed. + const auto Position = GetEyePosition() - Vector3d(0, 0.2, 0); // Eye position, corrected for eye-height weirdness. + m_World->SpawnItemPickup(Position, cItem(a_Item), Speed, 40_tick); // 2s delay before vomited pickups can be collected. } |