From 7c4cb9a3852e33d8bcc5f8283485e833c6eab93e Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 1 Sep 2014 20:12:56 +0200 Subject: Added CustomName to cMonster. --- src/Entities/Pawn.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Pawn.cpp b/src/Entities/Pawn.cpp index fe6c24a7a..fc8ca3d47 100644 --- a/src/Entities/Pawn.cpp +++ b/src/Entities/Pawn.cpp @@ -9,9 +9,9 @@ -cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height): - super(a_EntityType, 0, 0, 0, a_Width, a_Height), - m_EntityEffects(tEffectMap()) +cPawn::cPawn(eEntityType a_EntityType, double a_Width, double a_Height) : + super(a_EntityType, 0, 0, 0, a_Width, a_Height) + , m_EntityEffects(tEffectMap()) { } @@ -111,3 +111,6 @@ void cPawn::ClearEntityEffects() RemoveEntityEffect(EffectType); } } + + + -- cgit v1.2.3 From dfed6f94ca78f2e104ed316d83400b0ca74cb79a Mon Sep 17 00:00:00 2001 From: Howaner Date: Mon, 1 Sep 2014 21:05:45 +0200 Subject: Added name tag --- src/Entities/Boat.cpp | 2 ++ src/Entities/Entity.h | 2 +- src/Entities/ItemFrame.cpp | 2 ++ src/Entities/Minecart.cpp | 5 +++-- 4 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index 8ff8866a1..328a70846 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -62,6 +62,8 @@ bool cBoat::DoTakeDamage(TakeDamageInfo & TDI) void cBoat::OnRightClicked(cPlayer & a_Player) { + super::OnRightClicked(a_Player); + if (m_Attachee != NULL) { if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID()) diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index b9c280b6b..774cdb062 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -447,7 +447,7 @@ public: // tolua_end /// Called when the specified player right-clicks this entity - virtual void OnRightClicked(cPlayer &) {} + virtual void OnRightClicked(cPlayer & a_Player) {} /// Returns the list of drops for this pawn when it is killed. May check a_Killer for special handling (sword of looting etc.). Called from KilledBy(). virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp index 0bc10ec60..3ccb95998 100644 --- a/src/Entities/ItemFrame.cpp +++ b/src/Entities/ItemFrame.cpp @@ -22,6 +22,8 @@ cItemFrame::cItemFrame(eBlockFace a_BlockFace, double a_X, double a_Y, double a_ void cItemFrame::OnRightClicked(cPlayer & a_Player) { + super::OnRightClicked(a_Player); + if (!m_Item.IsEmpty()) { // Item not empty, rotate, clipping values to zero to three inclusive diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 1501eea84..5fabbb542 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -1072,6 +1072,8 @@ cRideableMinecart::cRideableMinecart(double a_X, double a_Y, double a_Z, const c void cRideableMinecart::OnRightClicked(cPlayer & a_Player) { + super::OnRightClicked(a_Player); + if (m_Attachee != NULL) { if (m_Attachee->GetUniqueID() == a_Player.GetUniqueID()) @@ -1124,8 +1126,7 @@ void cMinecartWithChest::SetSlot(size_t a_Idx, const cItem & a_Item) void cMinecartWithChest::OnRightClicked(cPlayer & a_Player) { - // Show the chest UI window to the player - // TODO + // TODO: Show the chest UI window to the player } -- cgit v1.2.3 From 1bb4d7941267ee55cdf7f35fa6a0055521115960 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 2 Sep 2014 19:12:35 +0200 Subject: Added SetCustomName() to players. --- src/Entities/Player.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- src/Entities/Player.h | 15 +++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 756410989..a2934d036 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -81,7 +81,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName) : m_Team(NULL), m_TicksUntilNextSave(PLAYER_INVENTORY_SAVE_INTERVAL), m_bIsTeleporting(false), - m_UUID((a_Client != NULL) ? a_Client->GetUUID() : "") + m_UUID((a_Client != NULL) ? a_Client->GetUUID() : ""), + m_CustomName("") { m_InventoryWindow = new cInventoryWindow(*this); m_CurrentWindow = m_InventoryWindow; @@ -813,6 +814,28 @@ void cPlayer::SetCanFly(bool a_CanFly) +void cPlayer::SetCustomName(const AString & a_CustomName) +{ + if (m_CustomName == a_CustomName) + { + return; + } + m_World->BroadcastPlayerListItem(GetTabListName(), false, 0); // Remove old tab-list entry + + m_CustomName = a_CustomName; + if (m_CustomName.length() > 16) + { + m_CustomName = m_CustomName.substr(0, 16); + } + + m_World->BroadcastSpawnEntity(*this, m_ClientHandle); + m_World->BroadcastPlayerListItem(GetTabListName(), true, GetClientHandle()->GetPing()); +} + + + + + void cPlayer::SetFlying(bool a_IsFlying) { if (a_IsFlying == m_IsFlying) @@ -1443,6 +1466,28 @@ AString cPlayer::GetColor(void) const +AString cPlayer::GetTabListName(void) const +{ + const AString & Color = GetColor(); + + if (HasCustomName()) + { + return m_CustomName; + } + else if ((GetName().length() <= 14) && !Color.empty()) + { + return Printf("%s%s", Color.c_str(), GetName().c_str()); + } + else + { + return GetName(); + } +} + + + + + void cPlayer::TossEquippedItem(char a_Amount) { cItems Drops; diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 9821cc6d9..da64bd64f 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -251,6 +251,9 @@ public: The returned value either is empty, or includes the cChatColor::Delimiter. */ AString GetColor(void) const; + /** Returns the name that is used in the tablist. */ + AString GetTabListName(void) const; + /** tosses the item in the selected hotbar slot */ void TossEquippedItem(char a_Amount = 1); @@ -398,6 +401,16 @@ public: /** If true the player can fly even when he's not in creative. */ void SetCanFly(bool a_CanFly); + /** Is a custom name for this player set? */ + bool HasCustomName(void) const { return !m_CustomName.empty(); } + + /** Returns the custom name of this player. If the player hasn't a custom name, it will return an empty string. */ + const AString & GetCustomName(void) const { return m_CustomName; } + + /** Sets the custom name of this player. If you want to disable the custom name, simply set an empty string. + The custom name will be used in the tab-list, in the player nametag and in the tab-completion. */ + void SetCustomName(const AString & a_CustomName); + /** Gets the last position that the player slept in This is initialised to the world spawn point if the player has not slept in a bed as of yet */ @@ -562,6 +575,8 @@ protected: If no ClientHandle is given, the UUID is initialized to empty. */ AString m_UUID; + AString m_CustomName; + /** Sets the speed and sends it to the client, so that they are forced to move so. */ virtual void DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) override; -- cgit v1.2.3 From 079634d18cf63abad05db0fda9a4510aa75c0522 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 2 Sep 2014 19:20:59 +0200 Subject: Added the new functions to APIDump. --- src/Entities/Player.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.h b/src/Entities/Player.h index da64bd64f..49380c776 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -401,7 +401,7 @@ public: /** If true the player can fly even when he's not in creative. */ void SetCanFly(bool a_CanFly); - /** Is a custom name for this player set? */ + /** Returns true if the player has a custom name. */ bool HasCustomName(void) const { return !m_CustomName.empty(); } /** Returns the custom name of this player. If the player hasn't a custom name, it will return an empty string. */ -- cgit v1.2.3 From f94df06b6601f9dcecd383f5d093d225f41d1c65 Mon Sep 17 00:00:00 2001 From: Howaner Date: Tue, 9 Sep 2014 03:02:25 +0200 Subject: Added the player list to the 1.8 protocol. --- src/Entities/Entity.cpp | 2 +- src/Entities/Player.cpp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 9bcdcffeb..fba688847 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -135,7 +135,7 @@ const char * cEntity::GetParentClass(void) const bool cEntity::Initialize(cWorld & a_World) { - if (cPluginManager::Get()->CallHookSpawningEntity(a_World, *this)) + if (cPluginManager::Get()->CallHookSpawningEntity(a_World, *this) && !IsPlayer()) { return false; } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index b0da6965a..a720d8c35 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -266,7 +266,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) cTimer t1; if (m_LastPlayerListTime + PLAYER_LIST_TIME_MS <= t1.GetNowTime()) { - m_World->SendPlayerList(this); + m_World->BroadcastPlayerListItem(*this, 2); m_LastPlayerListTime = t1.GetNowTime(); } @@ -1172,6 +1172,8 @@ void cPlayer::SetGameMode(eGameMode a_GameMode) SetFlying(false); SetCanFly(false); } + + m_World->BroadcastPlayerListItem(*this, 1); } -- cgit v1.2.3 From c45bf7cf55cac42fd168df6d008cb814dd94eae1 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 11 Sep 2014 20:06:28 +0200 Subject: 1.8: Fixed hangings. --- src/Entities/ItemFrame.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/ItemFrame.cpp b/src/Entities/ItemFrame.cpp index 0bc10ec60..7f923ef61 100644 --- a/src/Entities/ItemFrame.cpp +++ b/src/Entities/ItemFrame.cpp @@ -26,7 +26,7 @@ void cItemFrame::OnRightClicked(cPlayer & a_Player) { // Item not empty, rotate, clipping values to zero to three inclusive m_Rotation++; - if (m_Rotation >= 4) + if (m_Rotation >= 8) { m_Rotation = 0; } -- cgit v1.2.3 From 8dedbe4db52ee434595d9bdb32b3850a6c1e175f Mon Sep 17 00:00:00 2001 From: nesco Date: Tue, 16 Sep 2014 20:02:27 +0200 Subject: Preparing 1.8 changes Added Spectator Gamemode --- src/Entities/Player.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 9821cc6d9..d64dd6b99 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -171,6 +171,9 @@ public: /** Returns true if the player is in Adventure mode, either explicitly, or by inheriting from current world */ bool IsGameModeAdventure(void) const; + /** Returns true if the player is in Spectator mode, either explicitly, or by inheriting from current world */ + bool IsGameModeSpectator(void) const; + AString GetIP(void) const { return m_IP; } // tolua_export /** Returns the associated team, NULL if none */ -- cgit v1.2.3 From 120b23d65eefdd6e29b1605b10b852a1069e5444 Mon Sep 17 00:00:00 2001 From: nesco Date: Tue, 16 Sep 2014 20:04:17 +0200 Subject: Pre 1.8 release Added Spectator gamemode --- src/Entities/Player.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index ea795e346..81250bd40 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1043,6 +1043,14 @@ bool cPlayer::IsGameModeAdventure(void) const +bool cPlayer::IsGameModeSpectator(void) const +{ + return (m_GameMode == gmSpectator) || // Either the player is explicitly in Spectator + ((m_GameMode == gmNotSet) && m_World->IsGameModeSpectator()); // or they inherit from the world and the world is Adventure +} + + + void cPlayer::SetTeam(cTeam * a_Team) { -- cgit v1.2.3 From 89c9aec5da5adfcaee06df9979bc701579d19f6d Mon Sep 17 00:00:00 2001 From: nesco Date: Tue, 16 Sep 2014 20:17:35 +0200 Subject: Preparing 1.8 update Partially added Spectator gamemode --- src/Entities/Player.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 81250bd40..0f15ba620 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1166,7 +1166,7 @@ void cPlayer::SetGameMode(eGameMode a_GameMode) m_GameMode = a_GameMode; m_ClientHandle->SendGameMode(a_GameMode); - if (!IsGameModeCreative()) + if (!(IsGameModeCreative() || IsGameModeSpectator())) { SetFlying(false); SetCanFly(false); @@ -1348,6 +1348,7 @@ void cPlayer::MoveTo( const Vector3d & a_NewPos) void cPlayer::SetVisible(bool a_bVisible) { + // Need to Check if this or other players are in gamemode spectator if (a_bVisible && !m_bVisible) // Make visible { m_bVisible = true; -- cgit v1.2.3 From c63e14b6d11a97b56e17d628aebdd5e244999a15 Mon Sep 17 00:00:00 2001 From: nesco Date: Wed, 17 Sep 2014 17:15:47 +0200 Subject: Preparing 1.8 update --- src/Entities/Player.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 0f15ba620..660ad3239 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -451,6 +451,11 @@ void cPlayer::CancelChargingBow(void) void cPlayer::SetTouchGround(bool a_bTouchGround) { + if (IsGameModeSpectator()) // You can fly through the ground in survival + { + return; + } + m_bTouchGround = a_bTouchGround; if (!m_bTouchGround) @@ -585,7 +590,7 @@ bool cPlayer::Feed(int a_Food, double a_Saturation) void cPlayer::AddFoodExhaustion(double a_Exhaustion) { - if (!IsGameModeCreative()) + if (!(IsGameModeCreative() || IsGameModeSpectator())) { m_FoodExhaustionLevel = std::min(m_FoodExhaustionLevel + a_Exhaustion, 40.0); } @@ -823,9 +828,9 @@ bool cPlayer::DoTakeDamage(TakeDamageInfo & a_TDI) { if ((a_TDI.DamageType != dtInVoid) && (a_TDI.DamageType != dtPlugin)) { - if (IsGameModeCreative()) + if (IsGameModeCreative() || IsGameModeSpectator()) { - // No damage / health in creative mode if not void or plugin damage + // No damage / health in creative or spectator mode if not void or plugin damage return false; } } @@ -1348,7 +1353,7 @@ void cPlayer::MoveTo( const Vector3d & a_NewPos) void cPlayer::SetVisible(bool a_bVisible) { - // Need to Check if this or other players are in gamemode spectator + // Need to Check if the player or other players are in gamemode spectator, but will break compatibility if (a_bVisible && !m_bVisible) // Make visible { m_bVisible = true; @@ -1509,6 +1514,11 @@ void cPlayer::TossPickup(const cItem & a_Item) void cPlayer::TossItems(const cItems & a_Items) { + if (IsGameModeSpectator()) // Players can't toss items in spectator + { + return; + } + m_Stats.AddValue(statItemsDropped, (StatValue)a_Items.Size()); double vX = 0, vY = 0, vZ = 0; @@ -1795,7 +1805,7 @@ bool cPlayer::SaveToDisk() void cPlayer::UseEquippedItem(int a_Amount) { - if (IsGameModeCreative()) // No damage in creative + if (IsGameModeCreative() || IsGameModeSpectator()) // No damage in creative or spectator { return; } -- cgit v1.2.3 From bf85c0b0abece030ba822223bd7b2dd6367e08eb Mon Sep 17 00:00:00 2001 From: nesco Date: Wed, 17 Sep 2014 21:17:06 +0200 Subject: Implementing Spectator Mode Adding some proprieties of the spectator game mode in player.cpp : - Players can't toss items - Players can't touch the ground --- src/Entities/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 660ad3239..3920bdb56 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -451,7 +451,7 @@ void cPlayer::CancelChargingBow(void) void cPlayer::SetTouchGround(bool a_bTouchGround) { - if (IsGameModeSpectator()) // You can fly through the ground in survival + if (IsGameModeSpectator()) // You can fly through the ground in Spectator { return; } -- cgit v1.2.3 From 95af3eb526dc8d3289d6b1ced6462283a6ebb6b3 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Wed, 17 Sep 2014 23:32:14 +0200 Subject: Fixed minor style issues. --- src/Entities/Player.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 3920bdb56..38d42be14 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -451,7 +451,7 @@ void cPlayer::CancelChargingBow(void) void cPlayer::SetTouchGround(bool a_bTouchGround) { - if (IsGameModeSpectator()) // You can fly through the ground in Spectator + if (IsGameModeSpectator()) // You can fly through the ground in Spectator { return; } @@ -1514,7 +1514,7 @@ void cPlayer::TossPickup(const cItem & a_Item) void cPlayer::TossItems(const cItems & a_Items) { - if (IsGameModeSpectator()) // Players can't toss items in spectator + if (IsGameModeSpectator()) // Players can't toss items in spectator { return; } -- cgit v1.2.3 From 43ed690520d3c3b47ed7ff6f48f868e8011565e0 Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 18 Sep 2014 18:50:17 +0200 Subject: Exported player list states to extra functions. --- src/Entities/Player.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 826e0786f..36d8307b0 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -266,7 +266,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) cTimer t1; if (m_LastPlayerListTime + PLAYER_LIST_TIME_MS <= t1.GetNowTime()) { - m_World->BroadcastPlayerListItem(*this, 2); + // m_World->BroadcastPlayerListUpdatePing(*this); m_LastPlayerListTime = t1.GetNowTime(); } @@ -1164,7 +1164,7 @@ void cPlayer::SetGameMode(eGameMode a_GameMode) SetCanFly(false); } - m_World->BroadcastPlayerListItem(*this, 1); + m_World->BroadcastPlayerListUpdateGameMode(*this); } -- cgit v1.2.3 From 52c875531ec3622eedd7096e44f6bc67c5e5483b Mon Sep 17 00:00:00 2001 From: Howaner Date: Thu, 18 Sep 2014 18:51:36 +0200 Subject: Derp --- src/Entities/Player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 36d8307b0..55065d550 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -266,7 +266,7 @@ void cPlayer::Tick(float a_Dt, cChunk & a_Chunk) cTimer t1; if (m_LastPlayerListTime + PLAYER_LIST_TIME_MS <= t1.GetNowTime()) { - // m_World->BroadcastPlayerListUpdatePing(*this); + m_World->BroadcastPlayerListUpdatePing(*this); m_LastPlayerListTime = t1.GetNowTime(); } -- cgit v1.2.3 From 195b646aa4189ec9858f4994754eadd2c05ef9df Mon Sep 17 00:00:00 2001 From: Chris Darnell Date: Mon, 22 Sep 2014 03:22:36 -0400 Subject: Made it compile with clang --- src/Entities/Entity.cpp | 4 ++-- src/Entities/Minecart.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 42b207c48..996f2fff3 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -260,7 +260,7 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R void cEntity::SetYawFromSpeed(void) { const double EPS = 0.0000001; - if ((abs(m_Speed.x) < EPS) && (abs(m_Speed.z) < EPS)) + if ((std::abs(m_Speed.x) < EPS) && (std::abs(m_Speed.z) < EPS)) { // atan2() may overflow or is undefined, pick any number SetYaw(0); @@ -277,7 +277,7 @@ void cEntity::SetPitchFromSpeed(void) { const double EPS = 0.0000001; double xz = sqrt(m_Speed.x * m_Speed.x + m_Speed.z * m_Speed.z); // Speed XZ-plane component - if ((abs(xz) < EPS) && (abs(m_Speed.y) < EPS)) + if ((std::abs(xz) < EPS) && (std::abs(m_Speed.y) < EPS)) { // atan2() may overflow or is undefined, pick any number SetPitch(0); diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 1501eea84..bc9e21d8e 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -876,7 +876,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ()); // Prevent division by small numbers - if (abs(Distance.z) < 0.001) + if (std::abs(Distance.z) < 0.001) { Distance.z = 0.001; } @@ -925,7 +925,7 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta) Vector3d Distance = MinecartCollisionCallback.GetCollidedEntityPosition() - Vector3d(GetPosX(), 0, GetPosZ()); // Prevent division by small numbers - if (abs(Distance.z) < 0.001) + if (std::abs(Distance.z) < 0.001) { Distance.z = 0.001; } -- cgit v1.2.3 From 806871b86f2f04545f20caa6a8c30db2ccb7bc12 Mon Sep 17 00:00:00 2001 From: Chris Darnell Date: Mon, 22 Sep 2014 18:23:56 -0400 Subject: A few compiler warning fixes --- src/Entities/Entity.cpp | 5 +-- src/Entities/EntityEffect.cpp | 1 + src/Entities/Minecart.cpp | 81 ++++++++++++++++++++++--------------------- 3 files changed, 45 insertions(+), 42 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index c8ebc4314..8ef24828e 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -342,6 +342,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) a_TDI.FinalDamage += (int)ceil(2.5 * SmiteLevel); break; } + default: break; } } } @@ -1015,7 +1016,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) if (Tracer.HitNormal.y != 0.f) NextSpeed.y = 0.f; if (Tracer.HitNormal.z != 0.f) NextSpeed.z = 0.f; - if (Tracer.HitNormal.y == 1) // Hit BLOCK_FACE_YP, we are on the ground + if (Tracer.HitNormal.y == 1.f) // Hit BLOCK_FACE_YP, we are on the ground { m_bOnGround = true; } @@ -1960,7 +1961,7 @@ void cEntity::SteerVehicle(float a_Forward, float a_Sideways) { return; } - if ((a_Forward != 0) || (a_Sideways != 0)) + if ((a_Forward != 0.f) || (a_Sideways != 0.f)) { m_AttachedTo->HandleSpeedFromAttachee(a_Forward, a_Sideways); } diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index 1a923930f..98c5d23b4 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -96,6 +96,7 @@ int cEntityEffect::GetPotionEffectDuration(short a_ItemDamage) base = 1800; break; } + default: break; } // If potion is level II, half the duration. If not, stays the same diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index bc9e21d8e..5833cb4ae 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -13,6 +13,7 @@ #include "Player.h" #include "../BoundingBox.h" +#define NO_SPEED 0.0 #define MAX_SPEED 8 #define MAX_SPEED_NEGATIVE -MAX_SPEED @@ -220,7 +221,7 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; - if (GetSpeedZ() != 0) // Don't do anything if cart is stationary + if (GetSpeedZ() != NO_SPEED) // Don't do anything if cart is stationary { if (GetSpeedZ() > 0) { @@ -239,13 +240,13 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) { SetYaw(180); SetPosY(floor(GetPosY()) + 0.55); - SetSpeedY(0); - SetSpeedZ(0); + SetSpeedY(NO_SPEED); + SetSpeedZ(NO_SPEED); bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; - if (GetSpeedX() != 0) + if (GetSpeedX() != NO_SPEED) { if (GetSpeedX() > 0) { @@ -305,9 +306,9 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) case E_META_RAIL_ASCEND_XM: // ASCEND EAST { SetYaw(180); - SetSpeedZ(0); + SetSpeedZ(NO_SPEED); - if (GetSpeedX() >= 0) + if (GetSpeedX() >= NO_SPEED) { if (GetSpeedX() <= MAX_SPEED) { @@ -424,9 +425,9 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; - if (GetSpeedZ() != 0) + if (GetSpeedZ() != NO_SPEED) { - if (GetSpeedZ() > 0) + if (GetSpeedZ() > NO_SPEED) { AddSpeedZ(AccelDecelSpeed); } @@ -441,15 +442,15 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) { SetYaw(180); SetPosY(floor(GetPosY()) + 0.55); - SetSpeedY(0); - SetSpeedZ(0); + SetSpeedY(NO_SPEED); + SetSpeedZ(NO_SPEED); bool BlckCol = TestBlockCollision(a_RailMeta), EntCol = TestEntityCollision(a_RailMeta); if (EntCol || BlckCol) return; - if (GetSpeedX() != 0) + if (GetSpeedX() != NO_SPEED) { - if (GetSpeedX() > 0) + if (GetSpeedX() > NO_SPEED) { AddSpeedX(AccelDecelSpeed); } @@ -463,9 +464,9 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) case E_META_RAIL_ASCEND_XM: // ASCEND EAST { SetYaw(180); - SetSpeedZ(0); + SetSpeedZ(NO_SPEED); - if (GetSpeedX() >= 0) + if (GetSpeedX() >= NO_SPEED) { if (GetSpeedX() <= MAX_SPEED) { @@ -483,9 +484,9 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) case E_META_RAIL_ASCEND_XP: // ASCEND WEST { SetYaw(180); - SetSpeedZ(0); + SetSpeedZ(NO_SPEED); - if (GetSpeedX() > 0) + if (GetSpeedX() > NO_SPEED) { AddSpeedX(AccelDecelSpeed); SetSpeedY(GetSpeedX()); @@ -503,9 +504,9 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) case E_META_RAIL_ASCEND_ZM: // ASCEND NORTH { SetYaw(270); - SetSpeedX(0); + SetSpeedX(NO_SPEED); - if (GetSpeedZ() >= 0) + if (GetSpeedZ() >= NO_SPEED) { if (GetSpeedZ() <= MAX_SPEED) { @@ -523,9 +524,9 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) case E_META_RAIL_ASCEND_ZP: // ASCEND SOUTH { SetYaw(270); - SetSpeedX(0); + SetSpeedX(NO_SPEED); - if (GetSpeedZ() > 0) + if (GetSpeedZ() > NO_SPEED) { AddSpeedZ(AccelDecelSpeed); SetSpeedY(GetSpeedZ()); @@ -576,7 +577,7 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) case E_META_RAIL_ASCEND_XP: case E_META_RAIL_XM_XP: { - SetSpeedZ(0); + SetSpeedZ(NO_SPEED); SetPosZ(floor(GetPosZ()) + 0.5); break; } @@ -584,7 +585,7 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) case E_META_RAIL_ASCEND_ZP: case E_META_RAIL_ZM_ZP: { - SetSpeedX(0); + SetSpeedX(NO_SPEED); SetPosX(floor(GetPosX()) + 0.5); break; } @@ -593,12 +594,12 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) { if (GetPosZ() > floor(GetPosZ()) + 0.5) { - if (GetSpeedZ() > 0) + if (GetSpeedZ() > NO_SPEED) { SetSpeedX(-GetSpeedZ() * 0.7); } - SetSpeedZ(0); + SetSpeedZ(NO_SPEED); SetPosZ(floor(GetPosZ()) + 0.5); } else if (GetPosX() > floor(GetPosX()) + 0.5) @@ -608,82 +609,82 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) SetSpeedZ(-GetSpeedX() * 0.7); } - SetSpeedX(0); + SetSpeedX(NO_SPEED); SetPosX(floor(GetPosX()) + 0.5); } - SetSpeedY(0); + SetSpeedY(NO_SPEED); break; } case E_META_RAIL_CURVED_ZM_XP: { if (GetPosZ() > floor(GetPosZ()) + 0.5) { - if (GetSpeedZ() > 0) + if (GetSpeedZ() > NO_SPEED) { SetSpeedX(GetSpeedZ() * 0.7); } - SetSpeedZ(0); + SetSpeedZ(NO_SPEED); SetPosZ(floor(GetPosZ()) + 0.5); } else if (GetPosX() < floor(GetPosX()) + 0.5) { - if (GetSpeedX() < 0) + if (GetSpeedX() < NO_SPEED) { SetSpeedZ(GetSpeedX() * 0.7); } - SetSpeedX(0); + SetSpeedX(NO_SPEED); SetPosX(floor(GetPosX()) + 0.5); } - SetSpeedY(0); + SetSpeedY(NO_SPEED); break; } case E_META_RAIL_CURVED_ZP_XM: { if (GetPosZ() < floor(GetPosZ()) + 0.5) { - if (GetSpeedZ() < 0) + if (GetSpeedZ() < NO_SPEED) { SetSpeedX(GetSpeedZ() * 0.7); } - SetSpeedZ(0); + SetSpeedZ(NO_SPEED); SetPosZ(floor(GetPosZ()) + 0.5); } else if (GetPosX() > floor(GetPosX()) + 0.5) { - if (GetSpeedX() > 0) + if (GetSpeedX() > NO_SPEED) { SetSpeedZ(GetSpeedX() * 0.7); } - SetSpeedX(0); + SetSpeedX(NO_SPEED); SetPosX(floor(GetPosX()) + 0.5); } - SetSpeedY(0); + SetSpeedY(NO_SPEED); break; } case E_META_RAIL_CURVED_ZP_XP: { if (GetPosZ() < floor(GetPosZ()) + 0.5) { - if (GetSpeedZ() < 0) + if (GetSpeedZ() < NO_SPEED) { SetSpeedX(-GetSpeedZ() * 0.7); } - SetSpeedZ(0); + SetSpeedZ(NO_SPEED); SetPosZ(floor(GetPosZ()) + 0.5); } else if (GetPosX() < floor(GetPosX()) + 0.5) { - if (GetSpeedX() < 0) + if (GetSpeedX() < NO_SPEED) { SetSpeedZ(-GetSpeedX() * 0.7); } - SetSpeedX(0); + SetSpeedX(NO_SPEED); SetPosX(floor(GetPosX()) + 0.5); } SetSpeedY(0); -- cgit v1.2.3 From 5f6bac20915fda0d0a92c805f6dfbf562bb4beee Mon Sep 17 00:00:00 2001 From: archshift Date: Tue, 23 Sep 2014 00:12:28 -0700 Subject: Made ExpBottleEntity break on entities. Fixes #1369 --- src/Entities/ExpBottleEntity.cpp | 19 ++++++++++++++++++- src/Entities/ExpBottleEntity.h | 5 +++++ 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'src/Entities') diff --git a/src/Entities/ExpBottleEntity.cpp b/src/Entities/ExpBottleEntity.cpp index 202dde942..ee142a5a2 100644 --- a/src/Entities/ExpBottleEntity.cpp +++ b/src/Entities/ExpBottleEntity.cpp @@ -18,10 +18,27 @@ cExpBottleEntity::cExpBottleEntity(cEntity * a_Creator, double a_X, double a_Y, void cExpBottleEntity::OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) +{ + Break(a_HitPos); +} + + + + + +void cExpBottleEntity::OnHitEntity(cEntity & a_EntityHit, const Vector3d & a_HitPos) +{ + Break(a_HitPos); +} + + + + + +void cExpBottleEntity::Break(const Vector3d &a_HitPos) { // Spawn an experience orb with a reward between 3 and 11. m_World->BroadcastSoundParticleEffect(2002, POSX_TOINT, POSY_TOINT, POSZ_TOINT, 0); m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), 3 + m_World->GetTickRandomNumber(8)); - Destroy(); } diff --git a/src/Entities/ExpBottleEntity.h b/src/Entities/ExpBottleEntity.h index d62a84469..d36110f97 100644 --- a/src/Entities/ExpBottleEntity.h +++ b/src/Entities/ExpBottleEntity.h @@ -29,5 +29,10 @@ protected: // cProjectileEntity overrides: virtual void OnHitSolidBlock(const Vector3d & a_HitPos, eBlockFace a_HitFace) override; + virtual void OnHitEntity (cEntity & a_EntityHit, const Vector3d & a_HitPos) override; + + /** Breaks the bottle, fires its particle effects and sounds + @param a_HitPos The position where the bottle will break */ + void Break(const Vector3d &a_HitPos); }; // tolua_export -- cgit v1.2.3