summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-01-19 19:42:05 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-01-19 19:42:05 +0100
commit3700ad8546dfa7649bb172610dfef4b365eb2a7b (patch)
treeebd1c108b367ecb9615d0db69b92b4c5035b33af
parentMinecart improvements and fixes (diff)
downloadcuberite-3700ad8546dfa7649bb172610dfef4b365eb2a7b.tar
cuberite-3700ad8546dfa7649bb172610dfef4b365eb2a7b.tar.gz
cuberite-3700ad8546dfa7649bb172610dfef4b365eb2a7b.tar.bz2
cuberite-3700ad8546dfa7649bb172610dfef4b365eb2a7b.tar.lz
cuberite-3700ad8546dfa7649bb172610dfef4b365eb2a7b.tar.xz
cuberite-3700ad8546dfa7649bb172610dfef4b365eb2a7b.tar.zst
cuberite-3700ad8546dfa7649bb172610dfef4b365eb2a7b.zip
-rw-r--r--src/Entities/Minecart.cpp77
1 files changed, 51 insertions, 26 deletions
diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp
index 643eefb39..df1e48a60 100644
--- a/src/Entities/Minecart.cpp
+++ b/src/Entities/Minecart.cpp
@@ -720,56 +720,81 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
bool cMinecart::TestEntityCollision(NIBBLETYPE a_RailMeta)
{
+ cMinecartCollisionCallback MinecartCollisionCallback(GetPosition(), GetHeight(), GetWidth(), GetUniqueID(), ((m_Attachee == NULL) ? -1 : m_Attachee->GetUniqueID()));
+ int ChunkX, ChunkZ;
+ cChunkDef::BlockToChunk((int)floor(GetPosX()), (int)floor(GetPosZ()), ChunkX, ChunkZ);
+ m_World->ForEachEntityInChunk(ChunkX, ChunkZ, MinecartCollisionCallback);
+
+ if (!MinecartCollisionCallback.FoundIntersection())
+ {
+ return false;
+ }
+
switch (a_RailMeta)
{
case E_META_RAIL_ZM_ZP:
{
- cMinecartCollisionCallback MinecartCollisionCallback(GetPosition(), GetHeight(), GetWidth(), GetUniqueID(), ((m_Attachee == NULL) ? -1 : m_Attachee->GetUniqueID()));
- m_World->ForEachEntity(MinecartCollisionCallback);
-
- if (MinecartCollisionCallback.FoundIntersection())
+ if (MinecartCollisionCallback.GetCollidedEntityPosition().z >= GetPosZ())
{
- if (MinecartCollisionCallback.GetCollidedEntityPosition().z >= GetPosZ())
+ if ((-GetSpeedZ() * 0.4) < 0.01)
{
- if (((-GetSpeedZ()) * 0.4) < 0.01)
- {
- AddSpeedZ(-4);
- }
- else
- {
- SetSpeedZ((-GetSpeedZ()) * 0.4);
- }
+ AddSpeedZ(-4);
}
else
{
- if ((GetSpeedZ() * 0.4) < 0.01)
- {
- AddSpeedZ(4);
- }
- else
- {
- SetSpeedZ(GetSpeedZ() * 0.4);
- }
+ SetSpeedZ(-GetSpeedZ() * 0.4);
}
- return true;
}
- break;
+ else
+ {
+ if ((GetSpeedZ() * 0.4) < 0.01)
+ {
+ AddSpeedZ(4);
+ }
+ else
+ {
+ SetSpeedZ(GetSpeedZ() * 0.4);
+ }
+ }
+ return true;
}
case E_META_RAIL_XM_XP:
{
-
- break;
+ if (MinecartCollisionCallback.GetCollidedEntityPosition().x >= GetPosX())
+ {
+ if ((-GetSpeedX() * 0.4) < 0.01)
+ {
+ AddSpeedX(-4);
+ }
+ else
+ {
+ SetSpeedX(-GetSpeedX() * 0.4);
+ }
+ }
+ else
+ {
+ if ((GetSpeedX() * 0.4) < 0.01)
+ {
+ AddSpeedX(4);
+ }
+ else
+ {
+ SetSpeedX(GetSpeedX() * 0.4);
+ }
+ }
+ return true;
}
case E_META_RAIL_CURVED_ZM_XM:
case E_META_RAIL_CURVED_ZM_XP:
case E_META_RAIL_CURVED_ZP_XM:
case E_META_RAIL_CURVED_ZP_XP:
{
-
+ // TODO - simply can't be bothered right now
break;
}
default: break;
}
+
return false;
}