1
0

Fix minecart entity collision

* Minecarts no longer handle a collision if the entity is behind them.
* Minecarts will leave the pushing after a collision on a straight rail to the entity.
This commit is contained in:
Marvin Kopf 2016-02-16 17:02:05 +01:00
parent 7d09fcbd2f
commit f96903c661
2 changed files with 11 additions and 27 deletions

View File

@ -845,24 +845,16 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
{ {
if (MinecartCollisionCallback.GetCollidedEntityPosition().z >= GetPosZ()) if (MinecartCollisionCallback.GetCollidedEntityPosition().z >= GetPosZ())
{ {
if ((-GetSpeedZ() * 0.4) < 0.01) if (GetSpeedZ() > 0) // True if minecart is moving into the direction of the entity
{ {
AddSpeedZ(-4); SetSpeedZ(0); // Entity handles the pushing
}
else
{
SetSpeedZ(-GetSpeedZ() * 0.4);
} }
} }
else else // if (MinecartCollisionCallback.GetCollidedEntityPosition().z < GetPosZ())
{ {
if ((GetSpeedZ() * 0.4) < 0.01) if (GetSpeedZ() < 0) // True if minecart is moving into the direction of the entity
{ {
AddSpeedZ(4); SetSpeedZ(0); // Entity handles the pushing
}
else
{
SetSpeedZ(GetSpeedZ() * 0.4);
} }
} }
return true; return true;
@ -871,24 +863,16 @@ bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
{ {
if (MinecartCollisionCallback.GetCollidedEntityPosition().x >= GetPosX()) if (MinecartCollisionCallback.GetCollidedEntityPosition().x >= GetPosX())
{ {
if ((-GetSpeedX() * 0.4) < 0.01) if (GetSpeedX() > 0) // True if minecart is moving into the direction of the entity
{ {
AddSpeedX(-4); SetSpeedX(0); // Entity handles the pushing
}
else
{
SetSpeedX(-GetSpeedX() * 0.4);
} }
} }
else else // if (MinecartCollisionCallback.GetCollidedEntityPosition().x < GetPosX())
{ {
if ((GetSpeedX() * 0.4) < 0.01) if (GetSpeedX() < 0) // True if minecart is moving into the direction of the entity
{ {
AddSpeedX(4); SetSpeedX(0); // Entity handles the pushing
}
else
{
SetSpeedX(GetSpeedX() * 0.4);
} }
} }
return true; return true;

View File

@ -75,7 +75,7 @@ protected:
void SnapToRail(NIBBLETYPE a_RailMeta); void SnapToRail(NIBBLETYPE a_RailMeta);
/** Tests if a solid block is in front of a cart, and stops the cart (and returns true) if so; returns false if no obstruction */ /** Tests if a solid block is in front of a cart, and stops the cart (and returns true) if so; returns false if no obstruction */
bool TestBlockCollision(NIBBLETYPE a_RailMeta); bool TestBlockCollision(NIBBLETYPE a_RailMeta);
/** Tests if this mincecart's bounding box is intersecting another entity's bounding box (collision) and pushes mincecart away */ /** Tests if this mincecart's bounding box is intersecting another entity's bounding box (collision) and pushes mincecart away if necessary */
bool TestEntityCollision(NIBBLETYPE a_RailMeta); bool TestEntityCollision(NIBBLETYPE a_RailMeta);
} ; } ;