summaryrefslogtreecommitdiffstats
path: root/source/cPlayer.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-10 21:01:36 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-10 21:01:36 +0200
commit6711fcd6360a4a0a5efba95d51b1fd1cb456471c (patch)
treeb2be4dcafd474b5259e8db12daeb6339f1101975 /source/cPlayer.cpp
parentTorch placement handling (contributed by l0udPL) (diff)
downloadcuberite-6711fcd6360a4a0a5efba95d51b1fd1cb456471c.tar
cuberite-6711fcd6360a4a0a5efba95d51b1fd1cb456471c.tar.gz
cuberite-6711fcd6360a4a0a5efba95d51b1fd1cb456471c.tar.bz2
cuberite-6711fcd6360a4a0a5efba95d51b1fd1cb456471c.tar.lz
cuberite-6711fcd6360a4a0a5efba95d51b1fd1cb456471c.tar.xz
cuberite-6711fcd6360a4a0a5efba95d51b1fd1cb456471c.tar.zst
cuberite-6711fcd6360a4a0a5efba95d51b1fd1cb456471c.zip
Diffstat (limited to 'source/cPlayer.cpp')
-rw-r--r--source/cPlayer.cpp54
1 files changed, 34 insertions, 20 deletions
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp
index c260330f6..7c0f0c703 100644
--- a/source/cPlayer.cpp
+++ b/source/cPlayer.cpp
@@ -792,38 +792,52 @@ AString cPlayer::GetColor(void) const
-void cPlayer::TossItem( bool a_bDraggingItem, int a_Amount /* = 1 */ )
+void cPlayer::TossItem(
+ bool a_bDraggingItem,
+ int a_Amount /* = 1 */,
+ int a_CreateType /* = 0 */,
+ int a_CreateHealth /* = 0 */
+)
{
cItems Drops;
- if (a_bDraggingItem)
+ if (a_CreateType)
{
- cItem * Item = GetInventory().GetWindow()->GetDraggingItem();
- if (!Item->IsEmpty())
- {
- Drops.push_back(*Item);
- if( Item->m_ItemCount > a_Amount )
- Item->m_ItemCount -= (char)a_Amount;
- else
- Item->Empty();
- }
+ // Just create item without touching the inventory (used in creative mode)
+ Drops.push_back(cItem((ENUM_ITEM_ID)a_CreateType, (char)a_Amount, a_CreateHealth));
}
else
{
- // Else drop equipped item
- cItem DroppedItem = GetInventory().GetEquippedItem();
- if (!DroppedItem.IsEmpty())
+ // Drop an item from the inventory:
+ if (a_bDraggingItem)
+ {
+ cItem * Item = GetInventory().GetWindow()->GetDraggingItem();
+ if (!Item->IsEmpty())
+ {
+ Drops.push_back(*Item);
+ if( Item->m_ItemCount > a_Amount )
+ Item->m_ItemCount -= (char)a_Amount;
+ else
+ Item->Empty();
+ }
+ }
+ else
{
- DroppedItem.m_ItemCount = 1;
- if (GetInventory().RemoveItem(DroppedItem))
+ // Else drop equipped item
+ cItem DroppedItem = GetInventory().GetEquippedItem();
+ if (!DroppedItem.IsEmpty())
{
- DroppedItem.m_ItemCount = 1; // RemoveItem decreases the count, so set it to 1 again
- Drops.push_back(DroppedItem);
+ DroppedItem.m_ItemCount = 1;
+ if (GetInventory().RemoveItem(DroppedItem))
+ {
+ DroppedItem.m_ItemCount = 1; // RemoveItem decreases the count, so set it to 1 again
+ Drops.push_back(DroppedItem);
+ }
}
}
}
float vX = 0, vY = 0, vZ = 0;
- EulerToVector( -GetRotation(), GetPitch(), vZ, vX, vY );
- vY = -vY*2 + 1.f;
+ EulerToVector(-GetRotation(), GetPitch(), vZ, vX, vY);
+ vY = -vY * 2 + 1.f;
m_World->SpawnItemPickups(Drops, GetPosX(), GetPosY() + 1.6f, GetPosZ(), vX * 2, vY * 2, vZ * 2);
}