summaryrefslogtreecommitdiffstats
path: root/src/Entities/Player.cpp
diff options
context:
space:
mode:
authorbibo38 <bibo38@users.noreply.github.com>2016-10-12 14:38:45 +0200
committerMattes D <github@xoft.cz>2016-10-12 14:38:45 +0200
commitcb640ffea4a51a10db2e379ada8dc0487378ba09 (patch)
tree780ff243f439c9663b2f88e5df2805cc503f4f1d /src/Entities/Player.cpp
parentFixed cProjectileEntity double destroy bug (#3397) (diff)
downloadcuberite-cb640ffea4a51a10db2e379ada8dc0487378ba09.tar
cuberite-cb640ffea4a51a10db2e379ada8dc0487378ba09.tar.gz
cuberite-cb640ffea4a51a10db2e379ada8dc0487378ba09.tar.bz2
cuberite-cb640ffea4a51a10db2e379ada8dc0487378ba09.tar.lz
cuberite-cb640ffea4a51a10db2e379ada8dc0487378ba09.tar.xz
cuberite-cb640ffea4a51a10db2e379ada8dc0487378ba09.tar.zst
cuberite-cb640ffea4a51a10db2e379ada8dc0487378ba09.zip
Diffstat (limited to 'src/Entities/Player.cpp')
-rw-r--r--src/Entities/Player.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 5ab5e4567..db4b07553 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -250,6 +250,20 @@ void cPlayer::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
m_Stats.AddValue(statMinutesPlayed, 1);
+ // Handle the player detach, when the player is in spectator mode
+ if (
+ (IsGameModeSpectator()) &&
+ (m_AttachedTo != nullptr) &&
+ (
+ (m_AttachedTo->IsDestroyed()) || // Watching entity destruction
+ (m_AttachedTo->GetHealth() <= 0) || // Watching entity dead
+ (IsCrouched()) // Or the player wants to be detached
+ )
+ )
+ {
+ Detach();
+ }
+
// Handle a frozen player
TickFreezeCode();
if (m_IsFrozen)
@@ -1233,6 +1247,16 @@ bool cPlayer::IsGameModeSpectator(void) const
+
+bool cPlayer::CanMobsTarget(void) const
+{
+ return IsGameModeSurvival() || IsGameModeAdventure();
+}
+
+
+
+
+
void cPlayer::SetTeam(cTeam * a_Team)
{
if (m_Team == a_Team)
@@ -1344,6 +1368,12 @@ void cPlayer::SetGameMode(eGameMode a_GameMode)
return;
}
+ // Detach, if the player is switching from or to the spectator mode
+ if ((m_GameMode == gmSpectator) || (a_GameMode == gmSpectator))
+ {
+ Detach();
+ }
+
m_GameMode = a_GameMode;
m_ClientHandle->SendGameMode(a_GameMode);
@@ -1379,6 +1409,13 @@ void cPlayer::SetCapabilities()
{
SetVisible(false);
SetCanFly(true);
+
+ // Clear the current dragging item of the player
+ if (GetWindow() != nullptr)
+ {
+ m_DraggingItem.Empty();
+ GetClientHandle()->SendInventorySlot(-1, -1, m_DraggingItem);
+ }
}
else
{
@@ -2476,8 +2513,40 @@ bool cPlayer::PlaceBlocks(const sSetBlockVector & a_Blocks)
+void cPlayer::AttachTo(cEntity * a_AttachTo)
+{
+ // Different attach, if this is a spectator
+ if (IsGameModeSpectator())
+ {
+ m_AttachedTo = a_AttachTo;
+ GetClientHandle()->SendCameraSetTo(*m_AttachedTo);
+ return;
+ }
+
+ super::AttachTo(a_AttachTo);
+}
+
+
+
+
+
void cPlayer::Detach()
{
+ if (m_AttachedTo == nullptr)
+ {
+ // The player is not attached to anything. Bail out.
+ return;
+ }
+
+ // Different detach, if this is a spectator
+ if (IsGameModeSpectator())
+ {
+ GetClientHandle()->SendCameraSetTo(*this);
+ TeleportToEntity(*m_AttachedTo);
+ m_AttachedTo = nullptr;
+ return;
+ }
+
super::Detach();
int PosX = POSX_TOINT;
int PosY = POSY_TOINT;