summaryrefslogtreecommitdiffstats
path: root/src/Entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/Entities')
-rw-r--r--src/Entities/Minecart.cpp76
1 files changed, 43 insertions, 33 deletions
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index c8f43a3e6..643eefb39 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -160,10 +160,17 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk)
if (IsBlockRail(InsideType)) AddPosY(1); // Push cart upwards
}
+ bool WasDetectorRail = false;
if (IsBlockRail(InsideType))
{
- bool WasDetectorRail = false;
- SnapToRail(InsideMeta);
+ if (InsideType == E_BLOCK_RAIL)
+ {
+ SnapToRail(InsideMeta);
+ }
+ else
+ {
+ SnapToRail(InsideMeta & 0x07);
+ }
switch (InsideType)
{
@@ -180,12 +187,6 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk)
}
AddPosition(GetSpeed() * (a_Dt / 1000)); // Commit changes; as we use our own engine when on rails, this needs to be done, whereas it is normally in Entity.cpp
-
- if (m_bIsOnDetectorRail && !WasDetectorRail)
- {
- m_World->SetBlock(m_DetectorRailPosition.x, m_DetectorRailPosition.y, m_DetectorRailPosition.z, E_BLOCK_DETECTOR_RAIL, m_World->GetBlockMeta(m_DetectorRailPosition) & 0x07);
- m_bIsOnDetectorRail = false;
- }
}
else
{
@@ -193,6 +194,17 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk)
SetPosY(floor(GetPosY()) + 0.35); // HandlePhysics overrides this if minecart can fall, else, it is to stop ground clipping minecart bottom when off-rail
super::HandlePhysics(a_Dt, *Chunk);
}
+
+ if (m_bIsOnDetectorRail && !Vector3i((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())).Equals(m_DetectorRailPosition))
+ {
+ m_World->SetBlock(m_DetectorRailPosition.x, m_DetectorRailPosition.y, m_DetectorRailPosition.z, E_BLOCK_DETECTOR_RAIL, m_World->GetBlockMeta(m_DetectorRailPosition) & 0x07);
+ m_bIsOnDetectorRail = false;
+ }
+ else if (WasDetectorRail)
+ {
+ m_bIsOnDetectorRail = true;
+ m_DetectorRailPosition = Vector3i((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()));
+ }
// Broadcast positioning changes to client
BroadcastMovementUpdate();
@@ -425,11 +437,11 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
{
if (GetSpeedZ() > 0)
{
- AddSpeedZ(AccelDecelNegSpeed);
+ AddSpeedZ(AccelDecelSpeed);
}
else
{
- AddSpeedZ(AccelDecelSpeed);
+ AddSpeedZ(AccelDecelNegSpeed);
}
}
break;
@@ -465,9 +477,6 @@ void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta)
void cMinecart::HandleDetectorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt)
{
- m_bIsOnDetectorRail = true;
- m_DetectorRailPosition = Vector3i((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()));
-
m_World->SetBlockMeta(m_DetectorRailPosition, a_RailMeta | 0x08);
HandleRailPhysics(a_RailMeta & 0x07, a_Dt);
@@ -497,9 +506,20 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta)
SetPosX(floor(GetPosX()) + 0.5);
break;
}
+ // Curved rail physics: once minecart has reached more than half of the block in the direction that it is travelling in, jerk it in the direction of curvature
case E_META_RAIL_CURVED_ZM_XM:
{
- if (GetPosZ() < floor(GetPosZ()) + 0.5)
+ if (GetPosZ() > floor(GetPosZ()) + 0.5)
+ {
+ if (GetSpeedZ() > 0)
+ {
+ SetSpeedX(-GetSpeedZ() * 0.7);
+ }
+
+ SetSpeedZ(0);
+ SetPosZ(floor(GetPosZ()) + 0.5);
+ }
+ else if (GetPosX() > floor(GetPosX()) + 0.5)
{
if (GetSpeedX() > 0)
{
@@ -509,21 +529,21 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta)
SetSpeedX(0);
SetPosX(floor(GetPosX()) + 0.5);
}
- else
+ break;
+ }
+ case E_META_RAIL_CURVED_ZM_XP:
+ {
+ if (GetPosZ() > floor(GetPosZ()) + 0.5)
{
if (GetSpeedZ() > 0)
{
- SetSpeedX(-GetSpeedZ() * 0.7);
+ SetSpeedX(GetSpeedZ() * 0.7);
}
SetSpeedZ(0);
SetPosZ(floor(GetPosZ()) + 0.5);
}
- break;
- }
- case E_META_RAIL_CURVED_ZM_XP:
- {
- if (GetPosZ() < floor(GetPosZ()) + 0.5)
+ else if (GetPosX() < floor(GetPosX()) + 0.5)
{
if (GetSpeedX() < 0)
{
@@ -533,16 +553,6 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta)
SetSpeedX(0);
SetPosX(floor(GetPosX()) + 0.5);
}
- else
- {
- if (GetSpeedZ() > 0)
- {
- SetSpeedX(GetSpeedZ() * 0.7);
- }
-
- SetSpeedZ(0);
- SetPosZ(floor(GetPosZ()) + 0.5);
- }
break;
}
case E_META_RAIL_CURVED_ZP_XM:
@@ -557,7 +567,7 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta)
SetSpeedZ(0);
SetPosZ(floor(GetPosZ()) + 0.5);
}
- else
+ else if (GetPosX() > floor(GetPosX()) + 0.5)
{
if (GetSpeedX() > 0)
{
@@ -581,7 +591,7 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta)
SetSpeedZ(0);
SetPosZ(floor(GetPosZ()) + 0.5);
}
- else
+ else if (GetPosX() < floor(GetPosX()) + 0.5)
{
if (GetSpeedX() < 0)
{