summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Entities/Boat.cpp33
-rw-r--r--src/Entities/Boat.h3
-rw-r--r--src/Entities/Entity.cpp18
-rw-r--r--src/Entities/Entity.h1
-rw-r--r--src/Items/ItemBoat.h39
5 files changed, 80 insertions, 14 deletions
diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp
index 56e766dd4..184aeeeeb 100644
--- a/src/Entities/Boat.cpp
+++ b/src/Entities/Boat.cpp
@@ -39,6 +39,15 @@ void cBoat::DoTakeDamage(TakeDamageInfo & TDI)
if (GetHealth() == 0)
{
+ if (TDI.Attacker != NULL)
+ {
+ if (TDI.Attacker->IsPlayer())
+ {
+ cItems Pickups;
+ Pickups.Add(cItem(E_ITEM_BOAT));
+ m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 0, 0, 0, true);
+ }
+ }
Destroy(true);
}
}
@@ -76,12 +85,32 @@ void cBoat::OnRightClicked(cPlayer & a_Player)
-void cBoat::HandlePhysics(float a_Dt, cChunk & a_Chunk)
+void cBoat::Tick(float a_Dt, cChunk & a_Chunk)
{
- super::HandlePhysics(a_Dt, a_Chunk);
+ super::Tick(a_Dt, a_Chunk);
BroadcastMovementUpdate();
+ SetSpeed(GetSpeed() * 0.97); // Slowly decrease the speed.
+ if (IsBlockWater(m_World->GetBlock((int) GetPosX(), (int) GetPosY(), (int) GetPosZ())))
+ {
+ SetSpeedY(1);
+ }
}
+
+void cBoat::HandleSpeedFromAttachee(float a_Forward, float a_Sideways)
+{
+ if (GetSpeed().Length() > 7)
+ {
+ return;
+ }
+
+ Vector3d ToAddSpeed(m_Attachee->GetLookVector() * (a_Sideways * 1.5));
+ ToAddSpeed.y = 0;
+
+ AddSpeed(ToAddSpeed);
+}
+
+ \ No newline at end of file
diff --git a/src/Entities/Boat.h b/src/Entities/Boat.h
index 8c51ab86c..c4c9afe7a 100644
--- a/src/Entities/Boat.h
+++ b/src/Entities/Boat.h
@@ -27,7 +27,8 @@ public:
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
virtual void DoTakeDamage(TakeDamageInfo & TDI) override;
- virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override;
+ virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
+ virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways) override;
cBoat(double a_X, double a_Y, double a_Z);
} ;
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 0a2145e81..7721d58b3 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1341,6 +1341,19 @@ void cEntity::AddSpeedZ(double a_AddSpeedZ)
+void cEntity::HandleSpeedFromAttachee(float a_Forward, float a_Sideways)
+{
+ Vector3d LookVector = m_Attachee->GetLookVector();
+ double AddSpeedX = LookVector.x * a_Forward + LookVector.z * a_Sideways;
+ double AddSpeedZ = LookVector.z * a_Forward - LookVector.x * a_Sideways;
+ SetSpeed(AddSpeedX, 0, AddSpeedZ);
+ BroadcastMovementUpdate();
+}
+
+
+
+
+
void cEntity::SteerVehicle(float a_Forward, float a_Sideways)
{
if (m_AttachedTo == NULL)
@@ -1349,10 +1362,7 @@ void cEntity::SteerVehicle(float a_Forward, float a_Sideways)
}
if ((a_Forward != 0) || (a_Sideways != 0))
{
- Vector3d LookVector = GetLookVector();
- double AddSpeedX = LookVector.x * a_Forward + LookVector.z * a_Sideways;
- double AddSpeedZ = LookVector.z * a_Forward - LookVector.x * a_Sideways;
- m_AttachedTo->AddSpeed(AddSpeedX, 0, AddSpeedZ);
+ m_AttachedTo->HandleSpeedFromAttachee(a_Forward, a_Sideways);
}
}
diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h
index de5f176ae..8d1692c98 100644
--- a/src/Entities/Entity.h
+++ b/src/Entities/Entity.h
@@ -197,6 +197,7 @@ public:
void AddSpeedY (double a_AddSpeedY);
void AddSpeedZ (double a_AddSpeedZ);
+ virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways);
void SteerVehicle(float a_Forward, float a_Sideways);
inline int GetUniqueID(void) const { return m_UniqueID; }
diff --git a/src/Items/ItemBoat.h b/src/Items/ItemBoat.h
index 6e3395f1d..79c8e9589 100644
--- a/src/Items/ItemBoat.h
+++ b/src/Items/ItemBoat.h
@@ -10,6 +10,7 @@
#pragma once
#include "../Entities/Boat.h"
+#include "../LineBlockTracer.h"
@@ -30,23 +31,47 @@ public:
virtual bool OnItemUse(cWorld * a_World, cPlayer * a_Player, const cItem & a_Item, int a_BlockX, int a_BlockY, int a_BlockZ, char a_Dir) override
{
- if (a_Dir < 0)
+ if (a_Dir > 0)
{
return false;
}
+
+ class cCallbacks :
+ public cBlockTracer::cCallbacks
+ {
+ public:
+ Vector3d Pos;
+ virtual bool OnNextBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, char a_EntryFace) override
+ {
+ if (a_BlockType != E_BLOCK_AIR)
+ {
+ Pos = Vector3d(a_BlockX, a_BlockY, a_BlockZ);
+ return true;
+ }
+ return false;
+ }
+ } Callbacks;
- double x = (double)a_BlockX + 0.5;
- double y = (double)a_BlockY + 0.5;
- double z = (double)a_BlockZ + 0.5;
+ cLineBlockTracer Tracer(*a_World, Callbacks);
+ Vector3d Start(a_Player->GetEyePosition() + a_Player->GetLookVector());
+ Vector3d End(a_Player->GetEyePosition() + a_Player->GetLookVector() * 5);
- cBoat * Boat = NULL;
+ Tracer.Trace(Start.x, Start.y, Start.z, End.x, End.y, End.z);
+
+ double x = Callbacks.Pos.x;
+ double y = Callbacks.Pos.y;
+ double z = Callbacks.Pos.z;
+
+ if ((x == 0) && (y == 0) && (z == 0))
+ {
+ return false;
+ }
- Boat = new cBoat (x, y, z);
+ cBoat * Boat = new cBoat(x + 0.5, y + 1, z + 0.5);
Boat->Initialize(a_World);
return true;
}
-
} ;