summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
authorTycho Bickerstaff <work.tycho@gmail.com>2013-12-19 17:16:35 +0100
committerTycho Bickerstaff <work.tycho@gmail.com>2013-12-19 17:16:35 +0100
commit0e6107bfddeb6265f7a20076cdb86d5fa1aaa905 (patch)
treeabbc672f049128c6821b2f0c12cd49692bcaaf8f /src/Entities
parentfixed visual studio compile flags (diff)
parentMerge pull request #450 from mc-server/redstonefixes (diff)
downloadcuberite-0e6107bfddeb6265f7a20076cdb86d5fa1aaa905.tar
cuberite-0e6107bfddeb6265f7a20076cdb86d5fa1aaa905.tar.gz
cuberite-0e6107bfddeb6265f7a20076cdb86d5fa1aaa905.tar.bz2
cuberite-0e6107bfddeb6265f7a20076cdb86d5fa1aaa905.tar.lz
cuberite-0e6107bfddeb6265f7a20076cdb86d5fa1aaa905.tar.xz
cuberite-0e6107bfddeb6265f7a20076cdb86d5fa1aaa905.tar.zst
cuberite-0e6107bfddeb6265f7a20076cdb86d5fa1aaa905.zip
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/Entity.h3
-rw-r--r--src/Entities/Floater.cpp58
-rw-r--r--src/Entities/Floater.h29
-rw-r--r--src/Entities/Player.cpp20
-rw-r--r--src/Entities/Player.h10
5 files changed, 120 insertions, 0 deletions
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index 8d1692c98..7107a4a13 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -75,6 +75,7 @@ public:
etTNT,
etProjectile,
etExpOrb,
+ etFloater,
// Common variations
etMob = etMonster, // DEPRECATED, use etMonster instead!
@@ -129,6 +130,8 @@ public:
bool IsBoat (void) const { return (m_EntityType == etBoat); }
bool IsTNT (void) const { return (m_EntityType == etTNT); }
bool IsProjectile (void) const { return (m_EntityType == etProjectile); }
+ bool IsExpOrb (void) const { return (m_EntityType == etExpOrb); }
+ bool IsFloater (void) const { return (m_EntityType == etFloater); }
/// Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns true)
virtual bool IsA(const char * a_ClassName) const;
diff --git a/src/Entities/Floater.cpp b/src/Entities/Floater.cpp
new file mode 100644
index 000000000..1aa0413d9
--- /dev/null
+++ b/src/Entities/Floater.cpp
@@ -0,0 +1,58 @@
+#include "Globals.h"
+
+#include "Floater.h"
+#include "Player.h"
+#include "../ClientHandle.h"
+
+cFloater::cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID) :
+ cEntity(etFloater, a_X, a_Y, a_Z, 0.98, 0.98),
+ m_PlayerID(a_PlayerID),
+ m_CanPickupItem(false),
+ m_PickupCountDown(0)
+{
+ SetSpeed(a_Speed);
+}
+
+
+
+
+
+void cFloater::SpawnOn(cClientHandle & a_Client)
+{
+ a_Client.SendSpawnObject(*this, 90, m_PlayerID, 0, 0);
+}
+
+
+
+
+
+void cFloater::Tick(float a_Dt, cChunk & a_Chunk)
+{
+ HandlePhysics(a_Dt, a_Chunk);
+ if (IsBlockWater(m_World->GetBlock((int) GetPosX(), (int) GetPosY(), (int) GetPosZ())))
+ {
+ if (m_World->GetTickRandomNumber(100) == 0)
+ {
+ SetPosY(GetPosY() - 1);
+ m_CanPickupItem = true;
+ m_PickupCountDown = 20;
+ LOGD("Floater %i can be picked up", GetUniqueID());
+ }
+ else
+ {
+ SetSpeedY(1);
+ }
+ }
+ SetSpeedX(GetSpeedX() * 0.95);
+ SetSpeedZ(GetSpeedZ() * 0.95);
+ if (CanPickup())
+ {
+ m_PickupCountDown--;
+ if (m_PickupCountDown == 0)
+ {
+ m_CanPickupItem = false;
+ LOGD("The fish is gone. Floater %i can not pick an item up.", GetUniqueID());
+ }
+ }
+ BroadcastMovementUpdate();
+} \ No newline at end of file
diff --git a/src/Entities/Floater.h b/src/Entities/Floater.h
new file mode 100644
index 000000000..9bc5039f8
--- /dev/null
+++ b/src/Entities/Floater.h
@@ -0,0 +1,29 @@
+
+#pragma once
+
+#include "Entity.h"
+
+
+
+
+
+class cFloater :
+ public cEntity
+{
+ typedef cFloater super;
+
+public:
+
+ cFloater(double a_X, double a_Y, double a_Z, Vector3d a_Speed, int a_PlayerID);
+
+ virtual void SpawnOn(cClientHandle & a_Client) override;
+ virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
+
+ bool CanPickup(void) const { return m_CanPickupItem; }
+
+protected:
+ Vector3d m_Speed;
+ int m_PickupCountDown;
+ int m_PlayerID;
+ bool m_CanPickupItem;
+} ; \ No newline at end of file
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 7e7d77433..ca0d625e2 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -65,6 +65,8 @@ cPlayer::cPlayer(cClientHandle* a_Client, const AString & a_PlayerName)
, m_IsSubmerged(false)
, m_IsFlying(false)
, m_CanFly(false)
+ , m_IsFishing(false)
+ , m_FloaterID(-1)
, m_EatingFinishTick(-1)
, m_IsChargingBow(false)
, m_BowCharge(0)
@@ -1500,6 +1502,24 @@ bool cPlayer::LoadFromDisk()
//SetExperience(root.get("experience", 0).asInt());
m_GameMode = (eGameMode) root.get("gamemode", eGameMode_NotSet).asInt();
+
+ if (m_GameMode == eGameMode_Creative)
+ {
+ m_CanFly = true;
+ }
+ else if (m_GameMode == eGameMode_NotSet)
+ {
+ cWorld * World = cRoot::Get()->GetWorld(GetLoadedWorldName());
+ if (World == NULL)
+ {
+ World = cRoot::Get()->GetDefaultWorld();
+ }
+
+ if (World->GetGameMode() == eGameMode_Creative)
+ {
+ m_CanFly = true;
+ }
+ }
m_Inventory.LoadFromJson(root["inventory"]);
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index 59e941040..74da857e8 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -253,6 +253,14 @@ public:
/// Returns true if the player is currently flying.
bool IsFlying(void) const { return m_IsFlying; }
+
+ /// returns true if the player has thrown out a floater.
+ bool IsFishing(void) const { return m_IsFishing; }
+
+ void SetIsFishing(bool a_IsFishing, int a_FloaterID = -1) { m_IsFishing = a_IsFishing; m_FloaterID = a_FloaterID; }
+
+ int GetFloaterID(void) const { return m_FloaterID; }
+
// tolua_end
/// Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet
@@ -429,6 +437,7 @@ protected:
bool m_IsFlying;
bool m_IsSwimming;
bool m_IsSubmerged;
+ bool m_IsFishing;
bool m_CanFly; // If this is true the player can fly. Even if he is not in creative.
@@ -445,6 +454,7 @@ protected:
bool m_IsChargingBow;
int m_BowCharge;
+ int m_FloaterID;
virtual void Destroyed(void);