summaryrefslogtreecommitdiffstats
path: root/source/cPickup.cpp
diff options
context:
space:
mode:
authorlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-12-24 02:36:15 +0100
committerlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-12-24 02:36:15 +0100
commite45b01ba4a9cf25d5733b4ed839c713a7b22ff2d (patch)
tree98c77fd44742cfe5a82a5a7b5e3b8ae7c779a77e /source/cPickup.cpp
parentMax. players and MOTD are now changeable in the settings.ini (diff)
downloadcuberite-e45b01ba4a9cf25d5733b4ed839c713a7b22ff2d.tar
cuberite-e45b01ba4a9cf25d5733b4ed839c713a7b22ff2d.tar.gz
cuberite-e45b01ba4a9cf25d5733b4ed839c713a7b22ff2d.tar.bz2
cuberite-e45b01ba4a9cf25d5733b4ed839c713a7b22ff2d.tar.lz
cuberite-e45b01ba4a9cf25d5733b4ed839c713a7b22ff2d.tar.xz
cuberite-e45b01ba4a9cf25d5733b4ed839c713a7b22ff2d.tar.zst
cuberite-e45b01ba4a9cf25d5733b4ed839c713a7b22ff2d.zip
Diffstat (limited to '')
-rw-r--r--source/cPickup.cpp60
1 files changed, 55 insertions, 5 deletions
diff --git a/source/cPickup.cpp b/source/cPickup.cpp
index db409c637..7b6e9e1d1 100644
--- a/source/cPickup.cpp
+++ b/source/cPickup.cpp
@@ -6,6 +6,7 @@
#include "cClientHandle.h"
#include "cInventory.h"
#include "cWorld.h"
+#include "cWaterSimulator.h"
#include "cServer.h"
#include "cPlayer.h"
#include "cPluginManager.h"
@@ -28,11 +29,15 @@ cPickup::~cPickup()
{
delete m_Item;
delete m_Speed;
+ delete m_ResultingSpeed;
+ delete m_WaterSpeed;
}
cPickup::cPickup(int a_X, int a_Y, int a_Z, const cItem & a_Item, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */)
: cEntity( ((double)(a_X))/32, ((double)(a_Y))/32, ((double)(a_Z))/32 )
, m_Speed( new Vector3f( a_SpeedX, a_SpeedY, a_SpeedZ ) )
+ , m_ResultingSpeed(new Vector3f())
+ , m_WaterSpeed(new Vector3f())
, m_bOnGround( false )
, m_bReplicated( false )
, m_Timer( 0.f )
@@ -63,6 +68,8 @@ cPickup::cPickup(int a_X, int a_Y, int a_Z, const cItem & a_Item, float a_SpeedX
cPickup::cPickup(cPacket_PickupSpawn* a_PickupSpawnPacket)
: cEntity( ((double)a_PickupSpawnPacket->m_PosX)/32, ((double)a_PickupSpawnPacket->m_PosY)/32, ((double)a_PickupSpawnPacket->m_PosZ)/32 )
, m_Speed( new Vector3f() )
+ , m_ResultingSpeed(new Vector3f())
+ , m_WaterSpeed(new Vector3f())
, m_bOnGround( false )
, m_bReplicated( false )
, m_Timer( 0.f )
@@ -149,9 +156,11 @@ void cPickup::Tick(float a_Dt)
void cPickup::HandlePhysics(float a_Dt)
{
+ m_ResultingSpeed->Set(0.f, 0.f, 0.f);
+ cWorld* World = GetWorld();
+
if( m_bOnGround ) // check if it's still on the ground
{
- cWorld* World = GetWorld();
int BlockX = (m_Pos->x)<0 ? (int)m_Pos->x-1 : (int)m_Pos->x;
int BlockZ = (m_Pos->z)<0 ? (int)m_Pos->z-1 : (int)m_Pos->z;
char BlockBelow = World->GetBlock( BlockX, (int)m_Pos->y -1, BlockZ );
@@ -179,18 +188,55 @@ void cPickup::HandlePhysics(float a_Dt)
if( fabs(m_Speed->z) < 0.05 ) m_Speed->z = 0;
}
+
+ //get flowing direction
+ Direction WaterDir = World->GetWaterSimulator()->GetFlowingDirection((int) m_Pos->x - 1, (int) m_Pos->y, (int) m_Pos->z - 1);
+
+
+ *m_WaterSpeed *= 0.9; //Keep old speed but lower it
+
+ switch(WaterDir)
+ {
+ case X_PLUS:
+ m_WaterSpeed->x = 1.f;
+ m_bOnGround = false;
+ break;
+ case X_MINUS:
+ m_WaterSpeed->x = -1.f;
+ m_bOnGround = false;
+ break;
+ case Z_PLUS:
+ m_WaterSpeed->z = 1.f;
+ m_bOnGround = false;
+ break;
+ case Z_MINUS:
+ m_WaterSpeed->z = -1.f;
+ m_bOnGround = false;
+ break;
+
+ default:
+ break;
+ }
+
+ *m_ResultingSpeed += *m_WaterSpeed;
+
+
if( !m_bOnGround )
{
float Gravity = -9.81f*a_Dt;
m_Speed->y += Gravity;
+ // Set to hit position
+ *m_ResultingSpeed += *m_Speed;
+
cTracer Tracer( GetWorld() );
int Ret = Tracer.Trace( *m_Pos, *m_Speed, 2 );
if( Ret ) // Oh noez! we hit something
{
- // Set to hit position
- if( (*Tracer.RealHit - Vector3f(*m_Pos)).SqrLength() <= ( *m_Speed * a_Dt ).SqrLength() )
+
+
+ if( (*Tracer.RealHit - Vector3f(*m_Pos)).SqrLength() <= ( *m_ResultingSpeed * a_Dt ).SqrLength() )
{
m_bReplicated = false; // It's only interesting to replicate when we actually hit something...
if( Ret == 1 )
@@ -210,15 +256,19 @@ void cPickup::HandlePhysics(float a_Dt)
}
else
- *m_Pos += *m_Speed*a_Dt;
+ *m_Pos += *m_ResultingSpeed*a_Dt;
}
else
{ // We didn't hit anything, so move =]
- *m_Pos += *m_Speed*a_Dt;
+ *m_Pos += *m_ResultingSpeed * a_Dt;
}
}
+ //Usable for debugging
+ //SetPosition(m_Pos->x, m_Pos->y, m_Pos->z);
+
+
}
bool cPickup::CollectedBy( cPlayer* a_Dest )