summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-01-13 00:23:36 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-01-13 00:23:36 +0100
commitedefa27a48e2b5e7c82e74ca0e924172181fb098 (patch)
tree5d0a89e0bf234ee80adbdfd83e1d104008339edd
parentFixed wire, rail, and pressure plate unpowering (diff)
downloadcuberite-edefa27a48e2b5e7c82e74ca0e924172181fb098.tar
cuberite-edefa27a48e2b5e7c82e74ca0e924172181fb098.tar.gz
cuberite-edefa27a48e2b5e7c82e74ca0e924172181fb098.tar.bz2
cuberite-edefa27a48e2b5e7c82e74ca0e924172181fb098.tar.lz
cuberite-edefa27a48e2b5e7c82e74ca0e924172181fb098.tar.xz
cuberite-edefa27a48e2b5e7c82e74ca0e924172181fb098.tar.zst
cuberite-edefa27a48e2b5e7c82e74ca0e924172181fb098.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp8
-rw-r--r--src/Entities/Entity.h2
-rw-r--r--src/Entities/Player.cpp26
-rw-r--r--src/Entities/Player.h2
4 files changed, 34 insertions, 4 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index fbf76e008..bc66305b1 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1107,9 +1107,11 @@ void cEntity::AttachTo(cEntity * a_AttachTo)
// Already attached to that entity, nothing to do here
return;
}
-
- // Detach from any previous entity:
- Detach();
+ if (m_AttachedTo != NULL)
+ {
+ // Detach from any previous entity:
+ Detach();
+ }
// Attach to the new entity:
m_AttachedTo = a_AttachTo;
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index 2ba1b303d..878e69668 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -327,7 +327,7 @@ public:
void AttachTo(cEntity * a_AttachTo);
/// Detaches from the currently attached entity, if any
- void Detach(void);
+ virtual void Detach(void);
/// Makes sure head yaw is not over the specified range.
void WrapHeadYaw();
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index bc92790aa..cdedb0c5a 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1884,3 +1884,29 @@ void cPlayer::ApplyFoodExhaustionFromMovement()
+
+void cPlayer::Detach()
+{
+ super::Detach();
+ int PosX = (int)floor(GetPosX());
+ int PosY = (int)floor(GetPosY());
+ int PosZ = (int)floor(GetPosZ());
+
+ // Search for a position within an area to teleport player after detachment
+ // Position must be solid land, and occupied by a nonsolid block
+ // If nothing found, player remains where they are
+ for (int x = PosX - 2; x <= (PosX + 2); ++x)
+ {
+ for (int y = PosY; y <= (PosY + 3); ++y)
+ {
+ for (int z = PosZ - 2; z <= (PosZ + 2); ++z)
+ {
+ if (!g_BlockIsSolid[m_World->GetBlock(x, y, z)] && g_BlockIsSolid[m_World->GetBlock(x, y - 1, z)])
+ {
+ TeleportToCoords(x, y, z);
+ return;
+ }
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index f9ce950ba..bf3ca08e8 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -350,6 +350,8 @@ public:
virtual bool IsCrouched (void) const { return m_IsCrouched; }
virtual bool IsSprinting(void) const { return m_IsSprinting; }
virtual bool IsRclking (void) const { return IsEating(); }
+
+ virtual void Detach(void);
protected:
typedef std::map< std::string, bool > PermissionMap;