From 3c31f2d8d8caa9660ab5a2ca67a658ff3cf47ee0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 15 Jan 2014 22:36:19 +0000 Subject: Implemented Ctrl-Q drop stack Also fixed an issue with TossItems not respecting count. --- src/Entities/Player.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index fa6422389..22cbf656b 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1382,11 +1382,16 @@ void cPlayer::TossItem( cItem DroppedItem(GetInventory().GetEquippedItem()); if (!DroppedItem.IsEmpty()) { - if (GetInventory().RemoveOneEquippedItem()) + char NewAmount = a_Amount; + if (NewAmount > GetInventory().GetEquippedItem().m_ItemCount) { - DroppedItem.m_ItemCount = 1; // RemoveItem decreases the count, so set it to 1 again - Drops.push_back(DroppedItem); + NewAmount = GetInventory().GetEquippedItem().m_ItemCount; // Drop only what's there } + + GetInventory().GetHotbarGrid().ChangeSlotCount(GetInventory().GetEquippedSlotNum() /* Returns hotbar subslot, which HotbarGrid takes */, -a_Amount); + + DroppedItem.m_ItemCount = NewAmount; + Drops.push_back(DroppedItem); } } } -- cgit v1.2.3 From f3baf31563940f1cc6790a9a5b50cd1e12c2abd8 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 15 Jan 2014 22:38:15 +0000 Subject: OBSOLETE'd obsolete functions --- src/Entities/Entity.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 878e69668..cddc3fd49 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -155,7 +155,7 @@ public: double GetPosY (void) const { return m_Pos.y; } double GetPosZ (void) const { return m_Pos.z; } const Vector3d & GetRot (void) const { return m_Rot; } - double GetRotation (void) const { return m_Rot.x; } // OBSOLETE, use GetYaw() instead + OBSOLETE double GetRotation (void) const { return m_Rot.x; } // OBSOLETE, use GetYaw() instead double GetYaw (void) const { return m_Rot.x; } double GetPitch (void) const { return m_Rot.y; } double GetRoll (void) const { return m_Rot.z; } @@ -178,7 +178,7 @@ public: void SetPosition(double a_PosX, double a_PosY, double a_PosZ); void SetPosition(const Vector3d & a_Pos) { SetPosition(a_Pos.x, a_Pos.y, a_Pos.z); } void SetRot (const Vector3f & a_Rot); - void SetRotation(double a_Rotation) { SetYaw(a_Rotation); } // OBSOLETE, use SetYaw() instead + OBSOLETE void SetRotation(double a_Rotation) { SetYaw(a_Rotation); } // OBSOLETE, use SetYaw() instead void SetYaw (double a_Yaw); void SetPitch (double a_Pitch); void SetRoll (double a_Roll); -- cgit v1.2.3 From 74645fdfaa892e460c1b5444fd35eca11343e570 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 16 Jan 2014 19:00:49 +0000 Subject: Removed obsoleted functions --- src/Entities/Entity.cpp | 6 +++--- src/Entities/Entity.h | 4 +--- src/Entities/Minecart.cpp | 24 ++++++++++++------------ src/Entities/Player.cpp | 6 +++--- src/Entities/ProjectileEntity.cpp | 12 ++++++------ 5 files changed, 25 insertions(+), 27 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index cd97c6766..e1efe3ccd 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -256,16 +256,16 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R -void cEntity::SetRotationFromSpeed(void) +void cEntity::SetYawFromSpeed(void) { const double EPS = 0.0000001; if ((abs(m_Speed.x) < EPS) && (abs(m_Speed.z) < EPS)) { // atan2() may overflow or is undefined, pick any number - SetRotation(0); + SetYaw(0); return; } - SetRotation(atan2(m_Speed.x, m_Speed.z) * 180 / PI); + SetYaw(atan2(m_Speed.x, m_Speed.z) * 180 / PI); } diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index cddc3fd49..34d8b0fed 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -155,7 +155,6 @@ public: double GetPosY (void) const { return m_Pos.y; } double GetPosZ (void) const { return m_Pos.z; } const Vector3d & GetRot (void) const { return m_Rot; } - OBSOLETE double GetRotation (void) const { return m_Rot.x; } // OBSOLETE, use GetYaw() instead double GetYaw (void) const { return m_Rot.x; } double GetPitch (void) const { return m_Rot.y; } double GetRoll (void) const { return m_Rot.z; } @@ -178,7 +177,6 @@ public: void SetPosition(double a_PosX, double a_PosY, double a_PosZ); void SetPosition(const Vector3d & a_Pos) { SetPosition(a_Pos.x, a_Pos.y, a_Pos.z); } void SetRot (const Vector3f & a_Rot); - OBSOLETE void SetRotation(double a_Rotation) { SetYaw(a_Rotation); } // OBSOLETE, use SetYaw() instead void SetYaw (double a_Yaw); void SetPitch (double a_Pitch); void SetRoll (double a_Roll); @@ -223,7 +221,7 @@ public: void SetGravity(float a_Gravity) { m_Gravity = a_Gravity; } /// Sets the rotation to match the speed vector (entity goes "face-forward") - void SetRotationFromSpeed(void); + void SetYawFromSpeed(void); /// Sets the pitch to match the speed vector (entity gies "face-forward") void SetPitchFromSpeed(void); diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 7f3fea5ec..2c1287d40 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -148,7 +148,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) { case E_META_RAIL_ZM_ZP: // NORTHSOUTH { - SetRotation(270); + SetYaw(270); SetPosY(floor(GetPosY()) + 0.55); SetSpeedY(0); // Don't move vertically as on ground SetSpeedX(0); // Correct diagonal movement from curved rails @@ -172,7 +172,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) } case E_META_RAIL_XM_XP: // EASTWEST { - SetRotation(180); + SetYaw(180); SetPosY(floor(GetPosY()) + 0.55); SetSpeedY(0); SetSpeedZ(0); @@ -194,7 +194,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) } case E_META_RAIL_ASCEND_ZM: // ASCEND NORTH { - SetRotation(270); + SetYaw(270); SetSpeedX(0); if (GetSpeedZ() >= 0) @@ -216,7 +216,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) } case E_META_RAIL_ASCEND_ZP: // ASCEND SOUTH { - SetRotation(270); + SetYaw(270); SetSpeedX(0); if (GetSpeedZ() > 0) @@ -238,7 +238,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) } case E_META_RAIL_ASCEND_XM: // ASCEND EAST { - SetRotation(180); + SetYaw(180); SetSpeedZ(0); if (GetSpeedX() >= 0) @@ -258,7 +258,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) } case E_META_RAIL_ASCEND_XP: // ASCEND WEST { - SetRotation(180); + SetYaw(180); SetSpeedZ(0); if (GetSpeedX() > 0) @@ -278,7 +278,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) } case E_META_RAIL_CURVED_ZM_XM: // Ends pointing NORTH and WEST { - SetRotation(315); // Set correct rotation server side + SetYaw(315); // Set correct rotation server side SetPosY(floor(GetPosY()) + 0.55); // Levitate dat cart if (TestBlockCollision(a_RailMeta)) return; @@ -303,7 +303,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) } case E_META_RAIL_CURVED_ZM_XP: // Curved NORTH EAST { - SetRotation(225); + SetYaw(225); SetPosY(floor(GetPosY()) + 0.55); if (TestBlockCollision(a_RailMeta)) return; @@ -326,7 +326,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) } case E_META_RAIL_CURVED_ZP_XM: // Curved SOUTH WEST { - SetRotation(135); + SetYaw(135); SetPosY(floor(GetPosY()) + 0.55); if (TestBlockCollision(a_RailMeta)) return; @@ -349,7 +349,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) } case E_META_RAIL_CURVED_ZP_XP: // Curved SOUTH EAST { - SetRotation(45); + SetYaw(45); SetPosY(floor(GetPosY()) + 0.55); if (TestBlockCollision(a_RailMeta)) return; @@ -398,7 +398,7 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) { case E_META_RAIL_ZM_ZP: // NORTHSOUTH { - SetRotation(270); + SetYaw(270); SetPosY(floor(GetPosY()) + 0.55); SetSpeedY(0); SetSpeedX(0); @@ -420,7 +420,7 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) } case E_META_RAIL_XM_XP: // EASTWEST { - SetRotation(180); + SetYaw(180); SetPosY(floor(GetPosY()) + 0.55); SetSpeedY(0); SetSpeedZ(0); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 22cbf656b..386dc3a42 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1396,7 +1396,7 @@ void cPlayer::TossItem( } } double vX = 0, vY = 0, vZ = 0; - EulerToVector(-GetRotation(), GetPitch(), vZ, vX, vY); + EulerToVector(-GetRot().x, GetPitch(), vZ, vX, vY); vY = -vY * 2 + 1.f; m_World->SpawnItemPickups(Drops, GetPosX(), GetEyeHeight(), GetPosZ(), vX * 3, vY * 3, vZ * 3, true); // 'true' because created by player } @@ -1528,7 +1528,7 @@ bool cPlayer::LoadFromDisk() Json::Value & JSON_PlayerRotation = root["rotation"]; if (JSON_PlayerRotation.size() == 3) { - SetRotation ((float)JSON_PlayerRotation[(unsigned int)0].asDouble()); + SetYaw ((float)JSON_PlayerRotation[(unsigned int)0].asDouble()); SetPitch ((float)JSON_PlayerRotation[(unsigned int)1].asDouble()); SetRoll ((float)JSON_PlayerRotation[(unsigned int)2].asDouble()); } @@ -1591,7 +1591,7 @@ bool cPlayer::SaveToDisk() JSON_PlayerPosition.append(Json::Value(GetPosZ())); Json::Value JSON_PlayerRotation; - JSON_PlayerRotation.append(Json::Value(GetRotation())); + JSON_PlayerRotation.append(Json::Value(GetRot().x)); JSON_PlayerRotation.append(Json::Value(GetPitch())); JSON_PlayerRotation.append(Json::Value(GetRoll())); diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 9e5069ba6..76365076f 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -206,7 +206,7 @@ cProjectileEntity::cProjectileEntity(eKind a_Kind, cEntity * a_Creator, const Ve m_IsInGround(false) { SetSpeed(a_Speed); - SetRotationFromSpeed(); + SetYawFromSpeed(); SetPitchFromSpeed(); } @@ -350,7 +350,7 @@ void cProjectileEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) NewSpeed.y += m_Gravity / 20; NewSpeed *= TracerCallback.GetSlowdownCoeff(); SetSpeed(NewSpeed); - SetRotationFromSpeed(); + SetYawFromSpeed(); SetPitchFromSpeed(); // DEBUG: @@ -358,7 +358,7 @@ void cProjectileEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) m_UniqueID, GetPosX(), GetPosY(), GetPosZ(), GetSpeedX(), GetSpeedY(), GetSpeedZ(), - GetRotation(), GetPitch() + GetRot().x, GetPitch() ); } @@ -369,7 +369,7 @@ void cProjectileEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) void cProjectileEntity::SpawnOn(cClientHandle & a_Client) { // Default spawning - use the projectile kind to spawn an object: - a_Client.SendSpawnObject(*this, m_ProjectileKind, 12, ANGLE_TO_PROTO(GetRotation()), ANGLE_TO_PROTO(GetPitch())); + a_Client.SendSpawnObject(*this, m_ProjectileKind, 12, ANGLE_TO_PROTO(GetRot().x), ANGLE_TO_PROTO(GetPitch())); a_Client.SendEntityMetadata(*this); } @@ -402,11 +402,11 @@ cArrowEntity::cArrowEntity(cEntity * a_Creator, double a_X, double a_Y, double a { SetSpeed(a_Speed); SetMass(0.1); - SetRotationFromSpeed(); + SetYawFromSpeed(); SetPitchFromSpeed(); LOGD("Created arrow %d with speed {%.02f, %.02f, %.02f} and rot {%.02f, %.02f}", m_UniqueID, GetSpeedX(), GetSpeedY(), GetSpeedZ(), - GetRotation(), GetPitch() + GetRot().x, GetPitch() ); } -- cgit v1.2.3