From f1f86c46d37051b16a70bbc3c0c663873ccdf2eb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 27 Aug 2013 20:38:11 +0100 Subject: Preliminary Minecart physics handling [SEE DESC] This commit includes physics handling for the following scenarios: Flat rails in orientations [N, S, W, E] Ascending/descending rails in orientations [N, S, W, E] Powered rails are NOT handled (they don't respond to redstone). Curved rails are NOT handled (I haven't figured out how to do them :P) Please note that I have not tried to emulate vanilla behaviour because of a lack of knowledge on velocity unites/C++. We can say it's a feature or something. :P --- source/BlockID.cpp | 2 +- source/Entities/Entity.h | 6 +- source/Entities/Minecart.cpp | 197 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 200 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/BlockID.cpp b/source/BlockID.cpp index 40664647a..b53507f17 100644 --- a/source/BlockID.cpp +++ b/source/BlockID.cpp @@ -782,7 +782,7 @@ public: g_BlockIsSolid[E_BLOCK_NETHER_PORTAL] = false; g_BlockIsSolid[E_BLOCK_PISTON] = false; g_BlockIsSolid[E_BLOCK_PISTON_EXTENSION] = false; - g_BlockIsSolid[E_BLOCK_RAIL] = false; + g_BlockIsSolid[E_BLOCK_RAIL] = true; g_BlockIsSolid[E_BLOCK_REDSTONE_REPEATER_OFF] = false; g_BlockIsSolid[E_BLOCK_REDSTONE_REPEATER_ON] = false; g_BlockIsSolid[E_BLOCK_REDSTONE_TORCH_OFF] = false; diff --git a/source/Entities/Entity.h b/source/Entities/Entity.h index 820405cb9..7ae70b8cf 100644 --- a/source/Entities/Entity.h +++ b/source/Entities/Entity.h @@ -351,6 +351,9 @@ protected: bool m_bOnGround; float m_Gravity; + + // Measured in Kilograms (Kg) + double m_Mass; // Last Position. double m_LastPosX, m_LastPosY, m_LastPosZ; @@ -399,9 +402,6 @@ private: // Measured in meter / second Vector3d m_WaterSpeed; - // Measured in Kilograms (Kg) - double m_Mass; - /// Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. double m_Width; diff --git a/source/Entities/Minecart.cpp b/source/Entities/Minecart.cpp index 3e6069237..20811580a 100644 --- a/source/Entities/Minecart.cpp +++ b/source/Entities/Minecart.cpp @@ -2,6 +2,7 @@ // Minecart.cpp // Implements the cMinecart class representing a minecart in the world +// Indiana Jones! #include "Globals.h" #include "Minecart.h" @@ -17,6 +18,7 @@ cMinecart::cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z) : super(etMinecart, a_X, a_Y, a_Z, 0.98, 0.7), m_Payload(a_Payload) { + m_Mass = 20.f; } @@ -59,9 +61,202 @@ void cMinecart::SpawnOn(cClientHandle & a_ClientHandle) +enum ENUM_RAIL_DIRECTIONS +{ + E_RAIL_NORTH_SOUTH = 0, + E_RAIL_EAST_WEST = 1, + E_RAIL_ASCEND_EAST = 2, + E_RAIL_ASCEND_WEST = 3, + E_RAIL_ASCEND_NORTH = 4, + E_RAIL_ASCEND_SOUTH = 5, + E_RAIL_CURVED_SOUTH_EAST = 6, + E_RAIL_CURVED_SOUTH_WEST = 7, + E_RAIL_CURVED_NORTH_WEST = 8, + E_RAIL_CURVED_NORTH_EAST = 9, +} ; + + + + + void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) { - // TODO: the physics + /* + NOTE: Please bear in mind that taking away from negatives make them even more negative, + adding to negatives make them positive, etc. Also remember that - North is -Z, South +Z, West -X, and East +Z + */ + + super::Tick(a_Dt, a_Chunk); + + BLOCKTYPE BelowType; + NIBBLETYPE BelowMeta; + double SpeedX = GetSpeedX(), SpeedY = GetSpeedY(), SpeedZ = GetSpeedZ(); // Get current speed + + // Get block type & meta below the cart + GetWorld()->GetBlockTypeMeta(floor(GetPosX()), floor(GetPosY() -1 ), floor(GetPosZ()), BelowType, BelowMeta); + + if ((BelowType == E_BLOCK_RAIL) || (BelowType == E_BLOCK_DETECTOR_RAIL) || (BelowType == E_BLOCK_ACTIVATOR_RAIL)) + { + switch (BelowMeta) + { + + case E_RAIL_NORTH_SOUTH: + { + SpeedY = 0; // Don't move vertically as on ground + + // Set Y as current Y rounded up to bypass friction + // TODO: this causes positioning mismatches on the client, but Entity physics insists on friction! + SetPosY(ceil(GetPosY()) + 0.05); + + if (SpeedZ != 0) // Don't do anything if cart is stationary + { + if (SpeedZ > 0) + { + // Going SOUTH, slow down + SpeedZ = SpeedZ - 0.05; + } + else + { + // Going NORTH, slow down + SpeedZ = SpeedZ + 0.05; + } + } + break; + } + + case E_RAIL_EAST_WEST: + { + SpeedY = 0; + SetPosY(ceil(GetPosY()) + 0.05); + + if (SpeedX != 0) + { + if (SpeedX > 0) + { + SpeedX = SpeedX - 0.05; + } + else + { + SpeedX = SpeedX + 0.05; + } + } + break; + } + + case E_RAIL_ASCEND_NORTH: + { + if (SpeedZ >= 0) + { + // SpeedZ POSITIVE, going SOUTH + if (SpeedZ <= 6) // Speed limit of 6 SOUTH (m/s??) + { + SpeedZ = SpeedZ + 1; // Speed up + SpeedY = (0 - SpeedZ); // Downward movement is negative (0 minus positive numbers is negative) + } + else + { + SpeedZ = 6; // Enforce speed limit + SpeedY = (0 - SpeedZ); + } + } + else + { + // SpeedZ NEGATIVE, going NORTH + SpeedZ = SpeedZ + 0.1; // Slow down + SpeedY = (0 - SpeedZ); // Upward movement is positive (0 minus negative number is positive number) + } + break; + } + + case E_RAIL_ASCEND_SOUTH: + { + if (SpeedX > 0) + { + // SpeedZ POSITIVE, going SOUTH + SpeedZ = SpeedZ - 0.1; // Slow down + SpeedY = SpeedZ; // Upward movement positive + } + else + { + if (SpeedZ >= -6) // Speed limit of 6 WEST (m/s??) + { + // SpeedZ NEGATIVE, going NORTH + SpeedZ = SpeedZ - 1; // Speed up + SpeedY = SpeedZ; // Downward movement negative + } + else + { + SpeedZ = 6; // Enforce speed limit + SpeedY = SpeedZ; + } + } + break; + } + + case E_RAIL_ASCEND_WEST: + { + if (SpeedX >= 0) + { + if (SpeedX <= 6) + { + SpeedX = SpeedX + 1; + SpeedY = (0 - SpeedX); + } + else + { + SpeedX = 6; + SpeedY = (0 - SpeedX); + } + } + else + { + SpeedX = SpeedX + 0.1; + SpeedY = (0 - SpeedX); + } + break; + } + + case E_RAIL_ASCEND_EAST: + { + if (SpeedX > 0) + { + SpeedX = SpeedX - 0.1; + SpeedY = SpeedX; + } + else + { + if (SpeedX >= -6) + { + SpeedX = SpeedX - 1; + SpeedY = SpeedX; + } + else + { + SpeedX = -6; + SpeedY = SpeedX; + } + } + break; + } + + default: + { + ASSERT(!"Unhandled rail meta!"); + break; + } + + } + } + + // Set speed to speed variables + SetSpeedX(SpeedX); + SetSpeedY(SpeedY); + SetSpeedZ(SpeedZ); + + // Pass to physics handlers in Entity.cpp and broadcast position to client + HandlePhysics(a_Dt, a_Chunk); + BroadcastMovementUpdate(); + } -- cgit v1.2.3 From fa7def847b4565667b75f34502b2675c375057ad Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 27 Aug 2013 21:11:00 +0100 Subject: Zomb-ee and Skellingtons burning improvements They don't burn unless they are in direct view of the sun god or are protected by the sands of the souls of the underworld. --- source/Mobs/Skeleton.cpp | 11 ++++++----- source/Mobs/Zombie.cpp | 13 ++++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) (limited to 'source') diff --git a/source/Mobs/Skeleton.cpp b/source/Mobs/Skeleton.cpp index bec912afa..ad4037db9 100644 --- a/source/Mobs/Skeleton.cpp +++ b/source/Mobs/Skeleton.cpp @@ -21,12 +21,13 @@ void cSkeleton::Tick(float a_Dt, cChunk & a_Chunk) { cMonster::Tick(a_Dt, a_Chunk); - // TODO Outsource - // TODO should do SkyLight check, mobs in the dark donīt burn - if ((GetWorld()->GetTimeOfDay() < (12000 + 1000)) && !IsOnFire()) + if ((GetWorld()->GetBlockSkyLight(GetPosX(), GetPosY(), GetPosZ()) == 15) && (GetWorld()->GetBlock(GetPosX(), GetPosY(), GetPosZ()) != E_BLOCK_SOULSAND)) { - // Burn for 10 ticks, then decide again - StartBurning(10); + if ((GetWorld()->GetTimeOfDay() < (12000 + 1000)) && !IsOnFire()) + { + // Burn for 100 ticks, then decide again + StartBurning(100); + } } } diff --git a/source/Mobs/Zombie.cpp b/source/Mobs/Zombie.cpp index a6e39d6df..f3adf1283 100644 --- a/source/Mobs/Zombie.cpp +++ b/source/Mobs/Zombie.cpp @@ -3,10 +3,12 @@ #include "Zombie.h" #include "../World.h" +#include "../LineBlockTracer.h" +// They're eating your brains! cZombie::cZombie(void) : super("Zombie", 54, "mob.zombie.hurt", "mob.zombie.death", 0.6, 1.8) @@ -20,12 +22,13 @@ cZombie::cZombie(void) : void cZombie::Tick(float a_Dt, cChunk & a_Chunk) { super::Tick(a_Dt, a_Chunk); - - // TODO Same as in cSkeleton :D - if ((GetWorld()->GetTimeOfDay() < (12000 + 1000)) && !IsOnFire()) + if ((GetWorld()->GetBlockSkyLight(GetPosX(), GetPosY(), GetPosZ()) == 15) && (GetWorld()->GetBlock(GetPosX(), GetPosY(), GetPosZ()) != E_BLOCK_SOULSAND)) { - // Burn for 10 ticks, then decide again - StartBurning(10); + if ((GetWorld()->GetTimeOfDay() < (12000 + 1000)) && !IsOnFire()) + { + // Burn for 100 ticks, then decide again + StartBurning(100); + } } } -- cgit v1.2.3 From 1e910022291df03d5bc92b88d6a526e1bc0f095e Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 28 Aug 2013 22:13:27 +0100 Subject: Fixed Minecart spawning issues Now you can have everything! --- source/ClientHandle.cpp | 4 ++-- source/ClientHandle.h | 2 +- source/Entities/Minecart.cpp | 19 ++++++++++--------- source/Protocol/Protocol.h | 2 +- source/Protocol/Protocol125.cpp | 13 ++++++++----- source/Protocol/Protocol125.h | 2 +- source/Protocol/Protocol14x.cpp | 25 ++++++++++++++----------- source/Protocol/Protocol14x.h | 2 +- source/Protocol/ProtocolRecognizer.cpp | 4 ++-- source/Protocol/ProtocolRecognizer.h | 2 +- 10 files changed, 41 insertions(+), 34 deletions(-) (limited to 'source') diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index 199f43014..ea6266240 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -1901,9 +1901,9 @@ void cClientHandle::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, -void cClientHandle::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType) +void cClientHandle::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) // VehicleTypeType is specific to Minecarts { - m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType); + m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType, a_VehicleTypeType); } diff --git a/source/ClientHandle.h b/source/ClientHandle.h index f1a2dbc3d..0e871657c 100644 --- a/source/ClientHandle.h +++ b/source/ClientHandle.h @@ -125,7 +125,7 @@ public: void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock); void SendSpawnMob (const cMonster & a_Mob); void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch); - void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType); + void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType); void SendTabCompletionResults(const AStringVector & a_Results); void SendTeleportEntity (const cEntity & a_Entity); void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ); diff --git a/source/Entities/Minecart.cpp b/source/Entities/Minecart.cpp index 20811580a..c484d8763 100644 --- a/source/Entities/Minecart.cpp +++ b/source/Entities/Minecart.cpp @@ -18,7 +18,8 @@ cMinecart::cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z) : super(etMinecart, a_X, a_Y, a_Z, 0.98, 0.7), m_Payload(a_Payload) { - m_Mass = 20.f; + SetMass(20.f); + SetMaxHealth(6); } @@ -40,21 +41,21 @@ bool cMinecart::Initialize(cWorld * a_World) void cMinecart::SpawnOn(cClientHandle & a_ClientHandle) { - char Type = 0; - switch (m_Payload) //Wiki.vg is outdated on this!! + char TypeType = 0; + switch (m_Payload) { - case mpNone: Type = 9; break; //? - case mpChest: Type = 10; break; - case mpFurnace: Type = 11; break; //? - case mpTNT: Type = 12; break; //? - case mpHopper: Type = 13; break; //? + case mpNone: TypeType = 0; break; + case mpChest: TypeType = 1; break; + case mpFurnace: TypeType = 2; break; + case mpTNT: TypeType = 3; break; + case mpHopper: TypeType = 5; break; default: { ASSERT(!"Unknown payload, cannot spawn on client"); return; } } - a_ClientHandle.SendSpawnVehicle(*this, Type); + a_ClientHandle.SendSpawnVehicle(*this, 10, TypeType); // 10 = Minecarts, TypeType = What type of Minecart } diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h index 0953071b1..833b4d727 100644 --- a/source/Protocol/Protocol.h +++ b/source/Protocol/Protocol.h @@ -89,7 +89,7 @@ public: virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) = 0; virtual void SendSpawnMob (const cMonster & a_Mob) = 0; virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) = 0; - virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType) = 0; + virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) = 0; virtual void SendTabCompletionResults(const AStringVector & a_Results) = 0; virtual void SendTeleportEntity (const cEntity & a_Entity) = 0; virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) = 0; diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index c4c15819d..514ef02c6 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -747,7 +747,7 @@ void cProtocol125::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, -void cProtocol125::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType) +void cProtocol125::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_SPAWN_OBJECT); @@ -758,10 +758,13 @@ void cProtocol125::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp WriteInt ((int)(a_Vehicle.GetPosZ() * 32)); WriteByte ((Byte)((a_Vehicle.GetPitch() / 360.f) * 256)); WriteByte ((Byte)((a_Vehicle.GetRotation() / 360.f) * 256)); - WriteInt (1); - WriteShort((short)(a_Vehicle.GetSpeedX() * 400)); - WriteShort((short)(a_Vehicle.GetSpeedY() * 400)); - WriteShort((short)(a_Vehicle.GetSpeedZ() * 400)); + WriteInt (a_VehicleTypeType); + if (a_VehicleTypeType != 0) + { + WriteShort((short)(a_Vehicle.GetSpeedX() * 400)); + WriteShort((short)(a_Vehicle.GetSpeedY() * 400)); + WriteShort((short)(a_Vehicle.GetSpeedZ() * 400)); + } Flush(); } diff --git a/source/Protocol/Protocol125.h b/source/Protocol/Protocol125.h index ec6e12a0d..66085f661 100644 --- a/source/Protocol/Protocol125.h +++ b/source/Protocol/Protocol125.h @@ -66,7 +66,7 @@ public: virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; virtual void SendSpawnMob (const cMonster & a_Mob) override; virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override; - virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType) override; + virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) override; virtual void SendTabCompletionResults(const AStringVector & a_Results) override; virtual void SendTeleportEntity (const cEntity & a_Entity) override; virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override; diff --git a/source/Protocol/Protocol14x.cpp b/source/Protocol/Protocol14x.cpp index 881a55717..c31a21c42 100644 --- a/source/Protocol/Protocol14x.cpp +++ b/source/Protocol/Protocol14x.cpp @@ -229,21 +229,24 @@ void cProtocol146::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, -void cProtocol146::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType) +void cProtocol146::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) { cCSLock Lock(m_CSPacket); - WriteByte(PACKET_SPAWN_OBJECT); - WriteInt (a_Vehicle.GetUniqueID()); - WriteByte(a_VehicleType); - WriteInt ((int)(a_Vehicle.GetPosX() * 32)); - WriteInt ((int)(a_Vehicle.GetPosY() * 32)); - WriteInt ((int)(a_Vehicle.GetPosZ() * 32)); + WriteByte (PACKET_SPAWN_OBJECT); + WriteInt (a_Vehicle.GetUniqueID()); + WriteByte (a_VehicleType); + WriteInt ((int)(a_Vehicle.GetPosX() * 32)); + WriteInt ((int)(a_Vehicle.GetPosY() * 32)); + WriteInt ((int)(a_Vehicle.GetPosZ() * 32)); WriteByte ((Byte)((a_Vehicle.GetPitch() / 360.f) * 256)); WriteByte ((Byte)((a_Vehicle.GetRotation() / 360.f) * 256)); - WriteInt (1); - WriteShort((short)(a_Vehicle.GetSpeedX() * 400)); - WriteShort((short)(a_Vehicle.GetSpeedY() * 400)); - WriteShort((short)(a_Vehicle.GetSpeedZ() * 400)); + WriteInt (a_VehicleTypeType); + if (a_VehicleTypeType != 0) + { + WriteShort((short)(a_Vehicle.GetSpeedX() * 400)); + WriteShort((short)(a_Vehicle.GetSpeedY() * 400)); + WriteShort((short)(a_Vehicle.GetSpeedZ() * 400)); + } Flush(); } diff --git a/source/Protocol/Protocol14x.h b/source/Protocol/Protocol14x.h index c3193a3e7..ec2dc84ad 100644 --- a/source/Protocol/Protocol14x.h +++ b/source/Protocol/Protocol14x.h @@ -55,7 +55,7 @@ public: virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock) override; virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override; - virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType) override; + virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) override; } ; diff --git a/source/Protocol/ProtocolRecognizer.cpp b/source/Protocol/ProtocolRecognizer.cpp index ef2ed91f6..f406c1097 100644 --- a/source/Protocol/ProtocolRecognizer.cpp +++ b/source/Protocol/ProtocolRecognizer.cpp @@ -502,10 +502,10 @@ void cProtocolRecognizer::SendSpawnObject(const cEntity & a_Entity, char a_Objec -void cProtocolRecognizer::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType) +void cProtocolRecognizer::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) { ASSERT(m_Protocol != NULL); - m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType); + m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType, a_VehicleTypeType); } diff --git a/source/Protocol/ProtocolRecognizer.h b/source/Protocol/ProtocolRecognizer.h index 94bbb184f..530cfec83 100644 --- a/source/Protocol/ProtocolRecognizer.h +++ b/source/Protocol/ProtocolRecognizer.h @@ -96,7 +96,7 @@ public: virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; virtual void SendSpawnMob (const cMonster & a_Mob) override; virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override; - virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType) override; + virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) override; virtual void SendTabCompletionResults(const AStringVector & a_Results) override; virtual void SendTeleportEntity (const cEntity & a_Entity) override; virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override; -- cgit v1.2.3 From 7056992d0d99fde627e00c5d7f524cad0a70073d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 29 Aug 2013 13:47:22 +0100 Subject: Implemented xoft's suggestions [SEE DESC] Rail metas are now in BlockID and exported to LUA Minecart now does a SetMass, instead of m_Mass Minecarts use SubType instead of TypeType --- source/Bindings.cpp | 10 +++ source/BlockID.h | 12 +++ source/Blocks/BlockRail.h | 133 +++++++++++++-------------------- source/ClientHandle.cpp | 4 +- source/ClientHandle.h | 2 +- source/Entities/Entity.h | 6 +- source/Entities/Minecart.cpp | 46 ++++-------- source/Protocol/Protocol.h | 2 +- source/Protocol/Protocol125.cpp | 6 +- source/Protocol/Protocol125.h | 2 +- source/Protocol/Protocol14x.cpp | 6 +- source/Protocol/Protocol14x.h | 2 +- source/Protocol/ProtocolRecognizer.cpp | 4 +- source/Protocol/ProtocolRecognizer.h | 2 +- 14 files changed, 105 insertions(+), 132 deletions(-) (limited to 'source') diff --git a/source/Bindings.cpp b/source/Bindings.cpp index 7d51f7a4e..effb9c6ed 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -27567,6 +27567,16 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_constant(tolua_S,"E_META_SNOW_LAYER_SIX",E_META_SNOW_LAYER_SIX); tolua_constant(tolua_S,"E_META_SNOW_LAYER_SEVEN",E_META_SNOW_LAYER_SEVEN); tolua_constant(tolua_S,"E_META_SNOW_LAYER_EIGHT",E_META_SNOW_LAYER_EIGHT); + tolua_constant(tolua_S,"E_RAIL_ZM_ZP",E_RAIL_ZM_ZP); + tolua_constant(tolua_S,"E_RAIL_XM_XP",E_RAIL_XM_XP); + tolua_constant(tolua_S,"E_RAIL_ASCEND_XP",E_RAIL_ASCEND_XP); + tolua_constant(tolua_S,"E_RAIL_ASCEND_XM",E_RAIL_ASCEND_XM); + tolua_constant(tolua_S,"E_RAIL_ASCEND_ZM",E_RAIL_ASCEND_ZM); + tolua_constant(tolua_S,"E_RAIL_ASCEND_ZP",E_RAIL_ASCEND_ZP); + tolua_constant(tolua_S,"E_RAIL_CURVED_ZP_XP",E_RAIL_CURVED_ZP_XP); + tolua_constant(tolua_S,"E_RAIL_CURVED_ZP_XM",E_RAIL_CURVED_ZP_XM); + tolua_constant(tolua_S,"E_RAIL_CURVED_ZM_XM",E_RAIL_CURVED_ZM_XM); + tolua_constant(tolua_S,"E_RAIL_CURVED_ZM_XP",E_RAIL_CURVED_ZM_XP); tolua_constant(tolua_S,"E_META_COAL_NORMAL",E_META_COAL_NORMAL); tolua_constant(tolua_S,"E_META_COAL_CHARCOAL",E_META_COAL_CHARCOAL); tolua_constant(tolua_S,"E_META_DYE_BLACK",E_META_DYE_BLACK); diff --git a/source/BlockID.h b/source/BlockID.h index 0eb3df96d..b08795fdd 100644 --- a/source/BlockID.h +++ b/source/BlockID.h @@ -558,6 +558,18 @@ enum E_META_SNOW_LAYER_SEVEN = 6, E_META_SNOW_LAYER_EIGHT = 7, + // E_BLOCK_RAIL metas + E_RAIL_ZM_ZP = 0, + E_RAIL_XM_XP = 1, + E_RAIL_ASCEND_XP = 2, + E_RAIL_ASCEND_XM = 3, + E_RAIL_ASCEND_ZM = 4, + E_RAIL_ASCEND_ZP = 5, + E_RAIL_CURVED_ZP_XP = 6, + E_RAIL_CURVED_ZP_XM = 7, + E_RAIL_CURVED_ZM_XM = 8, + E_RAIL_CURVED_ZM_XP = 9, + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Item metas: diff --git a/source/Blocks/BlockRail.h b/source/Blocks/BlockRail.h index 65d120923..d30063f9e 100644 --- a/source/Blocks/BlockRail.h +++ b/source/Blocks/BlockRail.h @@ -8,37 +8,6 @@ -/// Meta values for the rail -enum ENUM_RAIL_DIRECTIONS -{ - E_RAIL_NORTH_SOUTH = 0, - E_RAIL_EAST_WEST = 1, - E_RAIL_ASCEND_EAST = 2, - E_RAIL_ASCEND_WEST = 3, - E_RAIL_ASCEND_NORTH = 4, - E_RAIL_ASCEND_SOUTH = 5, - E_RAIL_CURVED_SOUTH_EAST = 6, - E_RAIL_CURVED_SOUTH_WEST = 7, - E_RAIL_CURVED_NORTH_WEST = 8, - E_RAIL_CURVED_NORTH_EAST = 9, - - // Some useful synonyms: - E_RAIL_DIR_X = E_RAIL_EAST_WEST, - E_RAIL_DIR_Z = E_RAIL_NORTH_SOUTH, - E_RAIL_ASCEND_XP = E_RAIL_ASCEND_EAST, - E_RAIL_ASCEND_XM = E_RAIL_ASCEND_WEST, - E_RAIL_ASCEND_ZM = E_RAIL_ASCEND_NORTH, - E_RAIL_ASCEND_ZP = E_RAIL_ASCEND_SOUTH, - E_RAIL_CURVED_XPZP = E_RAIL_CURVED_SOUTH_EAST, - E_RAIL_CURVED_XMZP = E_RAIL_CURVED_SOUTH_WEST, - E_RAIL_CURVED_XMZM = E_RAIL_CURVED_NORTH_WEST, - E_RAIL_CURVED_XPZM = E_RAIL_CURVED_NORTH_EAST, -} ; - - - - - enum ENUM_PURE { E_PURE_UPDOWN = 0, @@ -96,13 +65,13 @@ public: NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ); switch (Meta) { - case E_RAIL_ASCEND_EAST: - case E_RAIL_ASCEND_WEST: - case E_RAIL_ASCEND_NORTH: - case E_RAIL_ASCEND_SOUTH: + case E_RAIL_ASCEND_XP: + case E_RAIL_ASCEND_XM: + case E_RAIL_ASCEND_ZM: + case E_RAIL_ASCEND_ZP: { // Mapping between the meta and the neighbors that need checking - Meta -= E_RAIL_ASCEND_EAST; // Base index at zero + Meta -= E_RAIL_ASCEND_XP; // Base index at zero static const struct { int x, z; @@ -157,12 +126,12 @@ public: } if (RailsCnt == 1) { - if (Neighbors[7]) return E_RAIL_ASCEND_SOUTH; - else if (Neighbors[6]) return E_RAIL_ASCEND_NORTH; - else if (Neighbors[5]) return E_RAIL_ASCEND_WEST; - else if (Neighbors[4]) return E_RAIL_ASCEND_EAST; - else if (Neighbors[0] || Neighbors[1]) return E_RAIL_EAST_WEST; - else if (Neighbors[2] || Neighbors[3]) return E_RAIL_NORTH_SOUTH; + if (Neighbors[7]) return E_RAIL_ASCEND_ZP; + else if (Neighbors[6]) return E_RAIL_ASCEND_ZM; + else if (Neighbors[5]) return E_RAIL_ASCEND_XM; + else if (Neighbors[4]) return E_RAIL_ASCEND_XP; + else if (Neighbors[0] || Neighbors[1]) return E_RAIL_XM_XP; + else if (Neighbors[2] || Neighbors[3]) return E_RAIL_ZM_ZP; ASSERT(!"Weird neighbor count"); return Meta; } @@ -175,16 +144,16 @@ public: } if (RailsCnt > 1) { - if (Neighbors[3] && Neighbors[0]) return E_RAIL_CURVED_SOUTH_EAST; - else if (Neighbors[3] && Neighbors[1]) return E_RAIL_CURVED_SOUTH_WEST; - else if (Neighbors[2] && Neighbors[0]) return E_RAIL_CURVED_NORTH_EAST; - else if (Neighbors[2] && Neighbors[1]) return E_RAIL_CURVED_NORTH_WEST; - else if (Neighbors[7] && Neighbors[2]) return E_RAIL_ASCEND_SOUTH; - else if (Neighbors[3] && Neighbors[6]) return E_RAIL_ASCEND_NORTH; - else if (Neighbors[5] && Neighbors[0]) return E_RAIL_ASCEND_WEST; - else if (Neighbors[4] && Neighbors[1]) return E_RAIL_ASCEND_EAST; - else if (Neighbors[0] && Neighbors[1]) return E_RAIL_EAST_WEST; - else if (Neighbors[2] && Neighbors[3]) return E_RAIL_NORTH_SOUTH; + if (Neighbors[3] && Neighbors[0]) return E_RAIL_CURVED_ZP_XP; + else if (Neighbors[3] && Neighbors[1]) return E_RAIL_CURVED_ZP_XM; + else if (Neighbors[2] && Neighbors[0]) return E_RAIL_CURVED_ZM_XP; + else if (Neighbors[2] && Neighbors[1]) return E_RAIL_CURVED_ZM_XM; + else if (Neighbors[7] && Neighbors[2]) return E_RAIL_ASCEND_ZP; + else if (Neighbors[3] && Neighbors[6]) return E_RAIL_ASCEND_ZM; + else if (Neighbors[5] && Neighbors[0]) return E_RAIL_ASCEND_XM; + else if (Neighbors[4] && Neighbors[1]) return E_RAIL_ASCEND_XP; + else if (Neighbors[0] && Neighbors[1]) return E_RAIL_XM_XP; + else if (Neighbors[2] && Neighbors[3]) return E_RAIL_ZM_ZP; ASSERT(!"Weird neighbor count"); } return Meta; @@ -200,7 +169,7 @@ public: NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); switch (Meta) { - case E_RAIL_NORTH_SOUTH: + case E_RAIL_ZM_ZP: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_DOWN) || @@ -212,7 +181,7 @@ public: break; } - case E_RAIL_EAST_WEST: + case E_RAIL_XM_XP: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST, E_PURE_DOWN) || @@ -224,7 +193,7 @@ public: break; } - case E_RAIL_ASCEND_EAST: + case E_RAIL_ASCEND_XP: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_EAST) || @@ -236,7 +205,7 @@ public: break; } - case E_RAIL_ASCEND_WEST: + case E_RAIL_ASCEND_XM: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST) || @@ -248,7 +217,7 @@ public: break; } - case E_RAIL_ASCEND_NORTH: + case E_RAIL_ASCEND_ZM: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_NORTH) || @@ -260,7 +229,7 @@ public: break; } - case E_RAIL_ASCEND_SOUTH: + case E_RAIL_ASCEND_ZP: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || @@ -272,7 +241,7 @@ public: break; } - case E_RAIL_CURVED_SOUTH_EAST: + case E_RAIL_CURVED_ZP_XP: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH) || @@ -284,7 +253,7 @@ public: break; } - case E_RAIL_CURVED_SOUTH_WEST: + case E_RAIL_CURVED_ZP_XM: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH) || @@ -296,7 +265,7 @@ public: break; } - case E_RAIL_CURVED_NORTH_WEST: + case E_RAIL_CURVED_ZM_XM: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || @@ -308,7 +277,7 @@ public: break; } - case E_RAIL_CURVED_NORTH_EAST: + case E_RAIL_CURVED_ZM_XP: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || @@ -356,11 +325,11 @@ public: case BLOCK_FACE_NORTH: { if ( - (Meta == E_RAIL_NORTH_SOUTH) || - (Meta == E_RAIL_ASCEND_NORTH) || - (Meta == E_RAIL_ASCEND_SOUTH) || - (Meta == E_RAIL_CURVED_SOUTH_EAST) || - (Meta == E_RAIL_CURVED_SOUTH_WEST) + (Meta == E_RAIL_ZM_ZP) || + (Meta == E_RAIL_ASCEND_ZM) || + (Meta == E_RAIL_ASCEND_ZP) || + (Meta == E_RAIL_CURVED_ZP_XP) || + (Meta == E_RAIL_CURVED_ZP_XM) ) { return false; @@ -371,11 +340,11 @@ public: case BLOCK_FACE_SOUTH: { if ( - (Meta == E_RAIL_NORTH_SOUTH) || - (Meta == E_RAIL_ASCEND_NORTH) || - (Meta == E_RAIL_ASCEND_SOUTH) || - (Meta == E_RAIL_CURVED_NORTH_EAST) || - (Meta == E_RAIL_CURVED_NORTH_WEST) + (Meta == E_RAIL_ZM_ZP) || + (Meta == E_RAIL_ASCEND_ZM) || + (Meta == E_RAIL_ASCEND_ZP) || + (Meta == E_RAIL_CURVED_ZM_XP) || + (Meta == E_RAIL_CURVED_ZM_XM) ) { return false; @@ -386,11 +355,11 @@ public: case BLOCK_FACE_EAST: { if ( - (Meta == E_RAIL_EAST_WEST) || - (Meta == E_RAIL_ASCEND_EAST) || - (Meta == E_RAIL_ASCEND_WEST) || - (Meta == E_RAIL_CURVED_SOUTH_WEST) || - (Meta == E_RAIL_CURVED_NORTH_WEST) + (Meta == E_RAIL_XM_XP) || + (Meta == E_RAIL_ASCEND_XP) || + (Meta == E_RAIL_ASCEND_XM) || + (Meta == E_RAIL_CURVED_ZP_XM) || + (Meta == E_RAIL_CURVED_ZM_XM) ) { return false; @@ -400,11 +369,11 @@ public: case BLOCK_FACE_WEST: { if ( - (Meta == E_RAIL_EAST_WEST) || - (Meta == E_RAIL_ASCEND_EAST) || - (Meta == E_RAIL_ASCEND_WEST) || - (Meta == E_RAIL_CURVED_SOUTH_EAST) || - (Meta == E_RAIL_CURVED_NORTH_EAST) + (Meta == E_RAIL_XM_XP) || + (Meta == E_RAIL_ASCEND_XP) || + (Meta == E_RAIL_ASCEND_XM) || + (Meta == E_RAIL_CURVED_ZP_XP) || + (Meta == E_RAIL_CURVED_ZM_XP) ) { return false; diff --git a/source/ClientHandle.cpp b/source/ClientHandle.cpp index ea6266240..53aae4dc4 100644 --- a/source/ClientHandle.cpp +++ b/source/ClientHandle.cpp @@ -1901,9 +1901,9 @@ void cClientHandle::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, -void cClientHandle::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) // VehicleTypeType is specific to Minecarts +void cClientHandle::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) // VehicleTypeType is specific to Minecarts { - m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType, a_VehicleTypeType); + m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType, a_VehicleSubType); } diff --git a/source/ClientHandle.h b/source/ClientHandle.h index 0e871657c..65ad35165 100644 --- a/source/ClientHandle.h +++ b/source/ClientHandle.h @@ -125,7 +125,7 @@ public: void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock); void SendSpawnMob (const cMonster & a_Mob); void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch); - void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType); + void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType); void SendTabCompletionResults(const AStringVector & a_Results); void SendTeleportEntity (const cEntity & a_Entity); void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ); diff --git a/source/Entities/Entity.h b/source/Entities/Entity.h index 7ae70b8cf..119cb2fe5 100644 --- a/source/Entities/Entity.h +++ b/source/Entities/Entity.h @@ -352,9 +352,6 @@ protected: bool m_bOnGround; float m_Gravity; - // Measured in Kilograms (Kg) - double m_Mass; - // Last Position. double m_LastPosX, m_LastPosY, m_LastPosZ; @@ -402,6 +399,9 @@ private: // Measured in meter / second Vector3d m_WaterSpeed; + // Measured in Kilograms (Kg) + double m_Mass; + /// Width of the entity, in the XZ plane. Since entities are represented as cylinders, this is more of a diameter. double m_Width; diff --git a/source/Entities/Minecart.cpp b/source/Entities/Minecart.cpp index c484d8763..556454795 100644 --- a/source/Entities/Minecart.cpp +++ b/source/Entities/Minecart.cpp @@ -41,50 +41,32 @@ bool cMinecart::Initialize(cWorld * a_World) void cMinecart::SpawnOn(cClientHandle & a_ClientHandle) { - char TypeType = 0; + char SubType = 0; switch (m_Payload) { - case mpNone: TypeType = 0; break; - case mpChest: TypeType = 1; break; - case mpFurnace: TypeType = 2; break; - case mpTNT: TypeType = 3; break; - case mpHopper: TypeType = 5; break; + case mpNone: SubType = 0; break; + case mpChest: SubType = 1; break; + case mpFurnace: SubType = 2; break; + case mpTNT: SubType = 3; break; + case mpHopper: SubType = 5; break; default: { ASSERT(!"Unknown payload, cannot spawn on client"); return; } } - a_ClientHandle.SendSpawnVehicle(*this, 10, TypeType); // 10 = Minecarts, TypeType = What type of Minecart + a_ClientHandle.SendSpawnVehicle(*this, 10, SubType); // 10 = Minecarts, TypeType = What type of Minecart } -enum ENUM_RAIL_DIRECTIONS -{ - E_RAIL_NORTH_SOUTH = 0, - E_RAIL_EAST_WEST = 1, - E_RAIL_ASCEND_EAST = 2, - E_RAIL_ASCEND_WEST = 3, - E_RAIL_ASCEND_NORTH = 4, - E_RAIL_ASCEND_SOUTH = 5, - E_RAIL_CURVED_SOUTH_EAST = 6, - E_RAIL_CURVED_SOUTH_WEST = 7, - E_RAIL_CURVED_NORTH_WEST = 8, - E_RAIL_CURVED_NORTH_EAST = 9, -} ; - - - - - void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) { /* NOTE: Please bear in mind that taking away from negatives make them even more negative, - adding to negatives make them positive, etc. Also remember that - North is -Z, South +Z, West -X, and East +Z + adding to negatives make them positive, etc. */ super::Tick(a_Dt, a_Chunk); @@ -101,7 +83,7 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) switch (BelowMeta) { - case E_RAIL_NORTH_SOUTH: + case E_RAIL_ZM_ZP: { SpeedY = 0; // Don't move vertically as on ground @@ -125,7 +107,7 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) break; } - case E_RAIL_EAST_WEST: + case E_RAIL_XM_XP: { SpeedY = 0; SetPosY(ceil(GetPosY()) + 0.05); @@ -144,7 +126,7 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) break; } - case E_RAIL_ASCEND_NORTH: + case E_RAIL_ASCEND_ZM: { if (SpeedZ >= 0) { @@ -169,7 +151,7 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) break; } - case E_RAIL_ASCEND_SOUTH: + case E_RAIL_ASCEND_ZP: { if (SpeedX > 0) { @@ -194,7 +176,7 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) break; } - case E_RAIL_ASCEND_WEST: + case E_RAIL_ASCEND_XM: { if (SpeedX >= 0) { @@ -217,7 +199,7 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) break; } - case E_RAIL_ASCEND_EAST: + case E_RAIL_ASCEND_XP: { if (SpeedX > 0) { diff --git a/source/Protocol/Protocol.h b/source/Protocol/Protocol.h index 833b4d727..5071f5961 100644 --- a/source/Protocol/Protocol.h +++ b/source/Protocol/Protocol.h @@ -89,7 +89,7 @@ public: virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) = 0; virtual void SendSpawnMob (const cMonster & a_Mob) = 0; virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) = 0; - virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) = 0; + virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) = 0; virtual void SendTabCompletionResults(const AStringVector & a_Results) = 0; virtual void SendTeleportEntity (const cEntity & a_Entity) = 0; virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) = 0; diff --git a/source/Protocol/Protocol125.cpp b/source/Protocol/Protocol125.cpp index 514ef02c6..4577e0c16 100644 --- a/source/Protocol/Protocol125.cpp +++ b/source/Protocol/Protocol125.cpp @@ -747,7 +747,7 @@ void cProtocol125::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, -void cProtocol125::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) +void cProtocol125::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_SPAWN_OBJECT); @@ -758,8 +758,8 @@ void cProtocol125::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp WriteInt ((int)(a_Vehicle.GetPosZ() * 32)); WriteByte ((Byte)((a_Vehicle.GetPitch() / 360.f) * 256)); WriteByte ((Byte)((a_Vehicle.GetRotation() / 360.f) * 256)); - WriteInt (a_VehicleTypeType); - if (a_VehicleTypeType != 0) + WriteInt (a_VehicleSubType); + if (a_VehicleSubType != 0) { WriteShort((short)(a_Vehicle.GetSpeedX() * 400)); WriteShort((short)(a_Vehicle.GetSpeedY() * 400)); diff --git a/source/Protocol/Protocol125.h b/source/Protocol/Protocol125.h index 66085f661..c5c8cd1a0 100644 --- a/source/Protocol/Protocol125.h +++ b/source/Protocol/Protocol125.h @@ -66,7 +66,7 @@ public: virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; virtual void SendSpawnMob (const cMonster & a_Mob) override; virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override; - virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) override; + virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) override; virtual void SendTabCompletionResults(const AStringVector & a_Results) override; virtual void SendTeleportEntity (const cEntity & a_Entity) override; virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override; diff --git a/source/Protocol/Protocol14x.cpp b/source/Protocol/Protocol14x.cpp index c31a21c42..ba9d7c01a 100644 --- a/source/Protocol/Protocol14x.cpp +++ b/source/Protocol/Protocol14x.cpp @@ -229,7 +229,7 @@ void cProtocol146::SendSpawnObject(const cEntity & a_Entity, char a_ObjectType, -void cProtocol146::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) +void cProtocol146::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) { cCSLock Lock(m_CSPacket); WriteByte (PACKET_SPAWN_OBJECT); @@ -240,8 +240,8 @@ void cProtocol146::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleTyp WriteInt ((int)(a_Vehicle.GetPosZ() * 32)); WriteByte ((Byte)((a_Vehicle.GetPitch() / 360.f) * 256)); WriteByte ((Byte)((a_Vehicle.GetRotation() / 360.f) * 256)); - WriteInt (a_VehicleTypeType); - if (a_VehicleTypeType != 0) + WriteInt (a_VehicleSubType); + if (a_VehicleSubType != 0) { WriteShort((short)(a_Vehicle.GetSpeedX() * 400)); WriteShort((short)(a_Vehicle.GetSpeedY() * 400)); diff --git a/source/Protocol/Protocol14x.h b/source/Protocol/Protocol14x.h index ec2dc84ad..ca497bbc1 100644 --- a/source/Protocol/Protocol14x.h +++ b/source/Protocol/Protocol14x.h @@ -55,7 +55,7 @@ public: virtual void SendPickupSpawn (const cPickup & a_Pickup) override; virtual void SendSpawnFallingBlock(const cFallingBlock & a_FallingBlock) override; virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override; - virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) override; + virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) override; } ; diff --git a/source/Protocol/ProtocolRecognizer.cpp b/source/Protocol/ProtocolRecognizer.cpp index f406c1097..853018329 100644 --- a/source/Protocol/ProtocolRecognizer.cpp +++ b/source/Protocol/ProtocolRecognizer.cpp @@ -502,10 +502,10 @@ void cProtocolRecognizer::SendSpawnObject(const cEntity & a_Entity, char a_Objec -void cProtocolRecognizer::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) +void cProtocolRecognizer::SendSpawnVehicle(const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) { ASSERT(m_Protocol != NULL); - m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType, a_VehicleTypeType); + m_Protocol->SendSpawnVehicle(a_Vehicle, a_VehicleType, a_VehicleSubType); } diff --git a/source/Protocol/ProtocolRecognizer.h b/source/Protocol/ProtocolRecognizer.h index 530cfec83..2178d5e61 100644 --- a/source/Protocol/ProtocolRecognizer.h +++ b/source/Protocol/ProtocolRecognizer.h @@ -96,7 +96,7 @@ public: virtual void SendSpawnFallingBlock (const cFallingBlock & a_FallingBlock) override; virtual void SendSpawnMob (const cMonster & a_Mob) override; virtual void SendSpawnObject (const cEntity & a_Entity, char a_ObjectType, int a_ObjectData, Byte a_Yaw, Byte a_Pitch) override; - virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleTypeType) override; + virtual void SendSpawnVehicle (const cEntity & a_Vehicle, char a_VehicleType, char a_VehicleSubType) override; virtual void SendTabCompletionResults(const AStringVector & a_Results) override; virtual void SendTeleportEntity (const cEntity & a_Entity) override; virtual void SendThunderbolt (int a_BlockX, int a_BlockY, int a_BlockZ) override; -- cgit v1.2.3 From 9f59b9a0934532a0d8a047c3e3598f8c817bcdc1 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 29 Aug 2013 14:00:39 +0100 Subject: Corrected comment TypeType --- source/Entities/Minecart.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source') diff --git a/source/Entities/Minecart.cpp b/source/Entities/Minecart.cpp index 556454795..40b676193 100644 --- a/source/Entities/Minecart.cpp +++ b/source/Entities/Minecart.cpp @@ -55,7 +55,7 @@ void cMinecart::SpawnOn(cClientHandle & a_ClientHandle) return; } } - a_ClientHandle.SendSpawnVehicle(*this, 10, SubType); // 10 = Minecarts, TypeType = What type of Minecart + a_ClientHandle.SendSpawnVehicle(*this, 10, SubType); // 10 = Minecarts, SubType = What type of Minecart } -- cgit v1.2.3 From acaae7a11e81e93fb0b5288ef830052e10a3d8f5 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 29 Aug 2013 15:25:12 +0100 Subject: Physics enhancements Minecarts no longer glitch on flat rails Improved acceleration, speed limit, and stopping --- source/Entities/Entity.cpp | 21 +++++++++++++++------ source/Entities/Minecart.cpp | 45 ++++++++++++++++++++++---------------------- 2 files changed, 37 insertions(+), 29 deletions(-) (limited to 'source') diff --git a/source/Entities/Entity.cpp b/source/Entities/Entity.cpp index 19a65ef4e..b9810aabb 100644 --- a/source/Entities/Entity.cpp +++ b/source/Entities/Entity.cpp @@ -499,6 +499,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width); int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width); BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ ); + BLOCKTYPE BlockBelow = NextChunk->GetBlock( RelBlockX, BlockY - 1, RelBlockZ ); if (!g_BlockIsSolid[BlockIn]) // Making sure we are not inside a solid block { if (m_bOnGround) // check if it's still on the ground @@ -540,13 +541,21 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) } else { - //Friction - if (NextSpeed.SqrLength() > 0.0004f) + if ( + (BlockBelow != E_BLOCK_RAIL) && + (BlockBelow != E_BLOCK_DETECTOR_RAIL) && + (BlockBelow != E_BLOCK_POWERED_RAIL) && + (BlockBelow != E_BLOCK_ACTIVATOR_RAIL) + ) { - NextSpeed.x *= 0.7f/(1+a_Dt); - if ( fabs(NextSpeed.x) < 0.05 ) NextSpeed.x = 0; - NextSpeed.z *= 0.7f/(1+a_Dt); - if ( fabs(NextSpeed.z) < 0.05 ) NextSpeed.z = 0; + //Friction + if (NextSpeed.SqrLength() > 0.0004f) + { + NextSpeed.x *= 0.7f/(1+a_Dt); + if ( fabs(NextSpeed.x) < 0.05 ) NextSpeed.x = 0; + NextSpeed.z *= 0.7f/(1+a_Dt); + if ( fabs(NextSpeed.z) < 0.05 ) NextSpeed.z = 0; + } } } diff --git a/source/Entities/Minecart.cpp b/source/Entities/Minecart.cpp index 40b676193..a148886a6 100644 --- a/source/Entities/Minecart.cpp +++ b/source/Entities/Minecart.cpp @@ -88,20 +88,19 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) SpeedY = 0; // Don't move vertically as on ground // Set Y as current Y rounded up to bypass friction - // TODO: this causes positioning mismatches on the client, but Entity physics insists on friction! - SetPosY(ceil(GetPosY()) + 0.05); + SetPosY(floor(GetPosY())); if (SpeedZ != 0) // Don't do anything if cart is stationary { if (SpeedZ > 0) { // Going SOUTH, slow down - SpeedZ = SpeedZ - 0.05; + SpeedZ = SpeedZ - 0.1; } else { // Going NORTH, slow down - SpeedZ = SpeedZ + 0.05; + SpeedZ = SpeedZ + 0.1; } } break; @@ -110,17 +109,17 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) case E_RAIL_XM_XP: { SpeedY = 0; - SetPosY(ceil(GetPosY()) + 0.05); + SetPosY(floor(GetPosY())); if (SpeedX != 0) { if (SpeedX > 0) { - SpeedX = SpeedX - 0.05; + SpeedX = SpeedX - 0.1; } else { - SpeedX = SpeedX + 0.05; + SpeedX = SpeedX + 0.1; } } break; @@ -131,21 +130,21 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) if (SpeedZ >= 0) { // SpeedZ POSITIVE, going SOUTH - if (SpeedZ <= 6) // Speed limit of 6 SOUTH (m/s??) + if (SpeedZ <= 8) // Speed limit of 8 SOUTH (m/s??) { - SpeedZ = SpeedZ + 1; // Speed up + SpeedZ = SpeedZ + 0.5; // Speed up SpeedY = (0 - SpeedZ); // Downward movement is negative (0 minus positive numbers is negative) } else { - SpeedZ = 6; // Enforce speed limit + SpeedZ = 8; // Enforce speed limit SpeedY = (0 - SpeedZ); } } else { // SpeedZ NEGATIVE, going NORTH - SpeedZ = SpeedZ + 0.1; // Slow down + SpeedZ = SpeedZ + 0.6; // Slow down SpeedY = (0 - SpeedZ); // Upward movement is positive (0 minus negative number is positive number) } break; @@ -156,20 +155,20 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) if (SpeedX > 0) { // SpeedZ POSITIVE, going SOUTH - SpeedZ = SpeedZ - 0.1; // Slow down + SpeedZ = SpeedZ - 0.6; // Slow down SpeedY = SpeedZ; // Upward movement positive } else { - if (SpeedZ >= -6) // Speed limit of 6 WEST (m/s??) + if (SpeedZ >= -8) // Speed limit of 8 WEST (m/s??) { // SpeedZ NEGATIVE, going NORTH - SpeedZ = SpeedZ - 1; // Speed up + SpeedZ = SpeedZ - 0.5; // Speed up SpeedY = SpeedZ; // Downward movement negative } else { - SpeedZ = 6; // Enforce speed limit + SpeedZ = 8; // Enforce speed limit SpeedY = SpeedZ; } } @@ -180,20 +179,20 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) { if (SpeedX >= 0) { - if (SpeedX <= 6) + if (SpeedX <= 8) { - SpeedX = SpeedX + 1; + SpeedX = SpeedX + 0.5; SpeedY = (0 - SpeedX); } else { - SpeedX = 6; + SpeedX = 8; SpeedY = (0 - SpeedX); } } else { - SpeedX = SpeedX + 0.1; + SpeedX = SpeedX + 0.6; SpeedY = (0 - SpeedX); } break; @@ -203,19 +202,19 @@ void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) { if (SpeedX > 0) { - SpeedX = SpeedX - 0.1; + SpeedX = SpeedX - 0.6; SpeedY = SpeedX; } else { - if (SpeedX >= -6) + if (SpeedX >= -8) { - SpeedX = SpeedX - 1; + SpeedX = SpeedX - 0.5; SpeedY = SpeedX; } else { - SpeedX = -6; + SpeedX = -8; SpeedY = SpeedX; } } -- cgit v1.2.3 From b5c63d8fc50d9f8ff179988a9a14010de89f5d75 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 2 Sep 2013 12:01:49 +0100 Subject: Minecart enhancements [SEE DESC] Curved rails. Better physics. Better code as improved by xoft. Stuff. --- source/Entities/Minecart.cpp | 350 +++++++++++++++++++++++++++++-------------- source/Entities/Minecart.h | 5 +- 2 files changed, 242 insertions(+), 113 deletions(-) (limited to 'source') diff --git a/source/Entities/Minecart.cpp b/source/Entities/Minecart.cpp index a148886a6..9a92df38e 100644 --- a/source/Entities/Minecart.cpp +++ b/source/Entities/Minecart.cpp @@ -20,6 +20,7 @@ cMinecart::cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z) : { SetMass(20.f); SetMaxHealth(6); + SetHealth(6); } @@ -62,183 +63,308 @@ void cMinecart::SpawnOn(cClientHandle & a_ClientHandle) -void cMinecart::Tick(float a_Dt, cChunk & a_Chunk) +void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) { + if ((GetPosY() > 0) && (GetPosY() < cChunkDef::Height)) + { + BLOCKTYPE BelowType = GetWorld()->GetBlock(floor(GetPosX()), floor(GetPosY() -1 ), floor(GetPosZ())); + + if ( + (BelowType == E_BLOCK_RAIL) || + (BelowType == E_BLOCK_POWERED_RAIL) || + (BelowType == E_BLOCK_DETECTOR_RAIL) || + (BelowType == E_BLOCK_ACTIVATOR_RAIL) + ) + { + HandleRailPhysics(a_Dt, a_Chunk); + } + else + { + super::HandlePhysics(a_Dt, a_Chunk); + BroadcastMovementUpdate(); + } + } + else + { + super::HandlePhysics(a_Dt, a_Chunk); + BroadcastMovementUpdate(); + } +} + + + + + +static const double MAX_SPEED = 8; +static const double MAX_SPEED_NEGATIVE = (0 - MAX_SPEED); +void cMinecart::HandleRailPhysics(float a_Dt, cChunk & a_Chunk) +{ + + super::HandlePhysics(a_Dt, a_Chunk); // Main physics handling + /* NOTE: Please bear in mind that taking away from negatives make them even more negative, adding to negatives make them positive, etc. */ - super::Tick(a_Dt, a_Chunk); - - BLOCKTYPE BelowType; - NIBBLETYPE BelowMeta; + // Get block meta below the cart + NIBBLETYPE BelowMeta = GetWorld()->GetBlockMeta(floor(GetPosX()), floor(GetPosY() -1 ), floor(GetPosZ())); double SpeedX = GetSpeedX(), SpeedY = GetSpeedY(), SpeedZ = GetSpeedZ(); // Get current speed - - // Get block type & meta below the cart - GetWorld()->GetBlockTypeMeta(floor(GetPosX()), floor(GetPosY() -1 ), floor(GetPosZ()), BelowType, BelowMeta); - - if ((BelowType == E_BLOCK_RAIL) || (BelowType == E_BLOCK_DETECTOR_RAIL) || (BelowType == E_BLOCK_ACTIVATOR_RAIL)) + + switch (BelowMeta) { - switch (BelowMeta) + case E_RAIL_ZM_ZP: // NORTHSOUTH { - - case E_RAIL_ZM_ZP: + SetRotation(270); + SpeedY = 0; // Don't move vertically as on ground + SpeedX = 0; // Correct diagonal movement from curved rails + + // Set Y as current Y rounded up to bypass friction + SetPosY(floor(GetPosY())); + + if (SpeedZ != 0) // Don't do anything if cart is stationary { - SpeedY = 0; // Don't move vertically as on ground - - // Set Y as current Y rounded up to bypass friction - SetPosY(floor(GetPosY())); - - if (SpeedZ != 0) // Don't do anything if cart is stationary + if (SpeedZ > 0) + { + // Going SOUTH, slow down + SpeedZ = SpeedZ - 0.1; + } + else { - if (SpeedZ > 0) - { - // Going SOUTH, slow down - SpeedZ = SpeedZ - 0.1; - } - else - { - // Going NORTH, slow down - SpeedZ = SpeedZ + 0.1; - } + // Going NORTH, slow down + SpeedZ = SpeedZ + 0.1; } - break; } + break; + } - case E_RAIL_XM_XP: - { - SpeedY = 0; - SetPosY(floor(GetPosY())); + case E_RAIL_XM_XP: // EASTWEST + { + SetRotation(180); + SpeedY = 0; + SpeedZ = 0; - if (SpeedX != 0) + SetPosY(floor(GetPosY())); + + if (SpeedX != 0) + { + if (SpeedX > 0) { - if (SpeedX > 0) - { - SpeedX = SpeedX - 0.1; - } - else - { - SpeedX = SpeedX + 0.1; - } + SpeedX = SpeedX - 0.1; + } + else + { + SpeedX = SpeedX + 0.1; } - break; } + break; + } + + case E_RAIL_ASCEND_ZM: // ASCEND NORTH + { + SetRotation(270); + SetPosY(floor(GetPosY()) + 0.2); // It seems it doesn't work without levitation :/ + SpeedX = 0; - case E_RAIL_ASCEND_ZM: + if (SpeedZ >= 0) { - if (SpeedZ >= 0) + // SpeedZ POSITIVE, going SOUTH + if (SpeedZ <= MAX_SPEED) // Speed limit { - // SpeedZ POSITIVE, going SOUTH - if (SpeedZ <= 8) // Speed limit of 8 SOUTH (m/s??) - { - SpeedZ = SpeedZ + 0.5; // Speed up - SpeedY = (0 - SpeedZ); // Downward movement is negative (0 minus positive numbers is negative) - } - else - { - SpeedZ = 8; // Enforce speed limit - SpeedY = (0 - SpeedZ); - } + SpeedZ = SpeedZ + 0.5; // Speed up + SpeedY = (0 - SpeedZ); // Downward movement is negative (0 minus positive numbers is negative) } else { - // SpeedZ NEGATIVE, going NORTH - SpeedZ = SpeedZ + 0.6; // Slow down - SpeedY = (0 - SpeedZ); // Upward movement is positive (0 minus negative number is positive number) + SpeedZ = MAX_SPEED; // Enforce speed limit + SpeedY = (0 - SpeedZ); } - break; } + else + { + // SpeedZ NEGATIVE, going NORTH + SpeedZ = SpeedZ + 0.4; // Slow down + SpeedY = (0 - SpeedZ); // Upward movement is positive (0 minus negative number is positive number) + } + break; + } + + case E_RAIL_ASCEND_ZP: // ASCEND SOUTH + { + SetRotation(270); + SetPosY(floor(GetPosY()) + 0.2); + SpeedX = 0; - case E_RAIL_ASCEND_ZP: + if (SpeedZ > 0) { - if (SpeedX > 0) + // SpeedZ POSITIVE, going SOUTH + SpeedZ = SpeedZ - 0.4; // Slow down + SpeedY = SpeedZ; // Upward movement positive + } + else + { + if (SpeedZ >= MAX_SPEED_NEGATIVE) // Speed limit { - // SpeedZ POSITIVE, going SOUTH - SpeedZ = SpeedZ - 0.6; // Slow down - SpeedY = SpeedZ; // Upward movement positive + // SpeedZ NEGATIVE, going NORTH + SpeedZ = SpeedZ - 0.5; // Speed up + SpeedY = SpeedZ; // Downward movement negative } else { - if (SpeedZ >= -8) // Speed limit of 8 WEST (m/s??) - { - // SpeedZ NEGATIVE, going NORTH - SpeedZ = SpeedZ - 0.5; // Speed up - SpeedY = SpeedZ; // Downward movement negative - } - else - { - SpeedZ = 8; // Enforce speed limit - SpeedY = SpeedZ; - } + SpeedZ = MAX_SPEED_NEGATIVE; // Enforce speed limit + SpeedY = SpeedZ; } - break; } + break; + } + + case E_RAIL_ASCEND_XM: // ASCEND EAST + { + SetRotation(180); + SetPosY(floor(GetPosY()) + 0.2); + SpeedZ = 0; - case E_RAIL_ASCEND_XM: + if (SpeedX >= 0) { - if (SpeedX >= 0) + if (SpeedX <= MAX_SPEED) { - if (SpeedX <= 8) - { - SpeedX = SpeedX + 0.5; - SpeedY = (0 - SpeedX); - } - else - { - SpeedX = 8; - SpeedY = (0 - SpeedX); - } + SpeedX = SpeedX + 0.5; + SpeedY = (0 - SpeedX); } else { - SpeedX = SpeedX + 0.6; + SpeedX = MAX_SPEED; SpeedY = (0 - SpeedX); } - break; } + else + { + SpeedX = SpeedX + 0.4; + SpeedY = (0 - SpeedX); + } + break; + } + + case E_RAIL_ASCEND_XP: // ASCEND WEST + { + SetRotation(180); + SetPosY(floor(GetPosY()) + 0.2); + SpeedZ = 0; - case E_RAIL_ASCEND_XP: + if (SpeedX > 0) { - if (SpeedX > 0) + SpeedX = SpeedX - 0.4; + SpeedY = SpeedX; + } + else + { + if (SpeedX >= MAX_SPEED_NEGATIVE) { - SpeedX = SpeedX - 0.6; + SpeedX = SpeedX - 0.5; SpeedY = SpeedX; } else { - if (SpeedX >= -8) - { - SpeedX = SpeedX - 0.5; - SpeedY = SpeedX; - } - else - { - SpeedX = -8; - SpeedY = SpeedX; - } + SpeedX = MAX_SPEED_NEGATIVE; + SpeedY = SpeedX; } - break; } + break; + } + + case E_RAIL_CURVED_ZM_XM: // Ends pointing NORTH and WEST + { + SetRotation(315); // Set correct rotation server side + SetPosY(floor(GetPosY()) + 0.2); // Levitate dat cart + + if (SpeedZ > 0) // Cart moving south + { + SpeedX = (0 - SpeedZ); // Diagonally move southwest (which will make cart hit a southwest rail) + } + else if (SpeedX > 0) // Cart moving east + { + SpeedZ = (0 - SpeedX); // Diagonally move northeast + } + break; + } + + case E_RAIL_CURVED_ZM_XP: // Curved NORTH EAST + { + SetRotation(225); + SetPosY(floor(GetPosY()) + 0.2); + + if (SpeedZ > 0) + { + SpeedX = SpeedZ; + } + else if (SpeedX < 0) + { + SpeedZ = SpeedX; + } + break; + } + + case E_RAIL_CURVED_ZP_XM: // Curved SOUTH WEST + { + SetRotation(135); + SetPosY(floor(GetPosY()) + 0.2); + + if (SpeedZ < 0) + { + SpeedX = SpeedZ; + } + else if (SpeedX > 0) + { + SpeedZ = SpeedX; + } + break; + } - default: + case E_RAIL_CURVED_ZP_XP: // Curved SOUTH EAST + { + SetRotation(45); + SetPosY(floor(GetPosY()) + 0.2); + + if (SpeedZ < 0) + { + SpeedX = (0 - SpeedZ); + } + else if (SpeedX < 0) { - ASSERT(!"Unhandled rail meta!"); - break; + SpeedZ = (0 - SpeedX); } + break; + } + default: + { + ASSERT(!"Unhandled rail meta!"); // Dun dun DUN! + break; } } - + // Set speed to speed variables SetSpeedX(SpeedX); SetSpeedY(SpeedY); SetSpeedZ(SpeedZ); - // Pass to physics handlers in Entity.cpp and broadcast position to client - HandlePhysics(a_Dt, a_Chunk); + + // Broadcast position to client BroadcastMovementUpdate(); +} + + + + +void cMinecart::DoTakeDamage(TakeDamageInfo & TDI) +{ + super::DoTakeDamage(TDI); + + if (GetHealth() == 0) + { + Destroy(true); + } } diff --git a/source/Entities/Minecart.h b/source/Entities/Minecart.h index 91336673d..b3386fbc9 100644 --- a/source/Entities/Minecart.h +++ b/source/Entities/Minecart.h @@ -37,7 +37,10 @@ public: // cEntity overrides: virtual bool Initialize(cWorld * a_World) override; virtual void SpawnOn(cClientHandle & a_ClientHandle) override; - virtual void Tick(float a_Dt, cChunk & a_Chunk) override; + virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; + void HandleRailPhysics(float a_Dt, cChunk & a_Chunk); + virtual void DoTakeDamage(TakeDamageInfo & TDI) override; + ePayload GetPayload(void) const { return m_Payload; } -- cgit v1.2.3 From 9c22cf15203ba524908d4c35c98f3f24e0e34837 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 3 Sep 2013 12:33:54 +0100 Subject: Fixed inconsistent meta naming --- source/Bindings.cpp | 20 ++++----- source/BlockID.h | 20 ++++----- source/Blocks/BlockRail.h | 102 +++++++++++++++++++++---------------------- source/Entities/Minecart.cpp | 20 ++++----- 4 files changed, 81 insertions(+), 81 deletions(-) (limited to 'source') diff --git a/source/Bindings.cpp b/source/Bindings.cpp index d89592bcf..fbc25ed1c 100644 --- a/source/Bindings.cpp +++ b/source/Bindings.cpp @@ -28302,16 +28302,16 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_constant(tolua_S,"E_META_SNOW_LAYER_SIX",E_META_SNOW_LAYER_SIX); tolua_constant(tolua_S,"E_META_SNOW_LAYER_SEVEN",E_META_SNOW_LAYER_SEVEN); tolua_constant(tolua_S,"E_META_SNOW_LAYER_EIGHT",E_META_SNOW_LAYER_EIGHT); - tolua_constant(tolua_S,"E_RAIL_ZM_ZP",E_RAIL_ZM_ZP); - tolua_constant(tolua_S,"E_RAIL_XM_XP",E_RAIL_XM_XP); - tolua_constant(tolua_S,"E_RAIL_ASCEND_XP",E_RAIL_ASCEND_XP); - tolua_constant(tolua_S,"E_RAIL_ASCEND_XM",E_RAIL_ASCEND_XM); - tolua_constant(tolua_S,"E_RAIL_ASCEND_ZM",E_RAIL_ASCEND_ZM); - tolua_constant(tolua_S,"E_RAIL_ASCEND_ZP",E_RAIL_ASCEND_ZP); - tolua_constant(tolua_S,"E_RAIL_CURVED_ZP_XP",E_RAIL_CURVED_ZP_XP); - tolua_constant(tolua_S,"E_RAIL_CURVED_ZP_XM",E_RAIL_CURVED_ZP_XM); - tolua_constant(tolua_S,"E_RAIL_CURVED_ZM_XM",E_RAIL_CURVED_ZM_XM); - tolua_constant(tolua_S,"E_RAIL_CURVED_ZM_XP",E_RAIL_CURVED_ZM_XP); + tolua_constant(tolua_S,"E_META_RAIL_ZM_ZP",E_META_RAIL_ZM_ZP); + tolua_constant(tolua_S,"E_META_RAIL_XM_XP",E_META_RAIL_XM_XP); + tolua_constant(tolua_S,"E_META_RAIL_ASCEND_XP",E_META_RAIL_ASCEND_XP); + tolua_constant(tolua_S,"E_META_RAIL_ASCEND_XM",E_META_RAIL_ASCEND_XM); + tolua_constant(tolua_S,"E_META_RAIL_ASCEND_ZM",E_META_RAIL_ASCEND_ZM); + tolua_constant(tolua_S,"E_META_RAIL_ASCEND_ZP",E_META_RAIL_ASCEND_ZP); + tolua_constant(tolua_S,"E_META_RAIL_CURVED_ZP_XP",E_META_RAIL_CURVED_ZP_XP); + tolua_constant(tolua_S,"E_META_RAIL_CURVED_ZP_XM",E_META_RAIL_CURVED_ZP_XM); + tolua_constant(tolua_S,"E_META_RAIL_CURVED_ZM_XM",E_META_RAIL_CURVED_ZM_XM); + tolua_constant(tolua_S,"E_META_RAIL_CURVED_ZM_XP",E_META_RAIL_CURVED_ZM_XP); tolua_constant(tolua_S,"E_META_COAL_NORMAL",E_META_COAL_NORMAL); tolua_constant(tolua_S,"E_META_COAL_CHARCOAL",E_META_COAL_CHARCOAL); tolua_constant(tolua_S,"E_META_DYE_BLACK",E_META_DYE_BLACK); diff --git a/source/BlockID.h b/source/BlockID.h index 02d2c7193..40da3c651 100644 --- a/source/BlockID.h +++ b/source/BlockID.h @@ -561,16 +561,16 @@ enum E_META_SNOW_LAYER_EIGHT = 7, // E_BLOCK_RAIL metas - E_RAIL_ZM_ZP = 0, - E_RAIL_XM_XP = 1, - E_RAIL_ASCEND_XP = 2, - E_RAIL_ASCEND_XM = 3, - E_RAIL_ASCEND_ZM = 4, - E_RAIL_ASCEND_ZP = 5, - E_RAIL_CURVED_ZP_XP = 6, - E_RAIL_CURVED_ZP_XM = 7, - E_RAIL_CURVED_ZM_XM = 8, - E_RAIL_CURVED_ZM_XP = 9, + E_META_RAIL_ZM_ZP = 0, + E_META_RAIL_XM_XP = 1, + E_META_RAIL_ASCEND_XP = 2, + E_META_RAIL_ASCEND_XM = 3, + E_META_RAIL_ASCEND_ZM = 4, + E_META_RAIL_ASCEND_ZP = 5, + E_META_RAIL_CURVED_ZP_XP = 6, + E_META_RAIL_CURVED_ZP_XM = 7, + E_META_RAIL_CURVED_ZM_XM = 8, + E_META_RAIL_CURVED_ZM_XP = 9, /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Item metas: diff --git a/source/Blocks/BlockRail.h b/source/Blocks/BlockRail.h index d30063f9e..0e83b952d 100644 --- a/source/Blocks/BlockRail.h +++ b/source/Blocks/BlockRail.h @@ -65,13 +65,13 @@ public: NIBBLETYPE Meta = a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ); switch (Meta) { - case E_RAIL_ASCEND_XP: - case E_RAIL_ASCEND_XM: - case E_RAIL_ASCEND_ZM: - case E_RAIL_ASCEND_ZP: + case E_META_RAIL_ASCEND_XP: + case E_META_RAIL_ASCEND_XM: + case E_META_RAIL_ASCEND_ZM: + case E_META_RAIL_ASCEND_ZP: { // Mapping between the meta and the neighbors that need checking - Meta -= E_RAIL_ASCEND_XP; // Base index at zero + Meta -= E_META_RAIL_ASCEND_XP; // Base index at zero static const struct { int x, z; @@ -126,12 +126,12 @@ public: } if (RailsCnt == 1) { - if (Neighbors[7]) return E_RAIL_ASCEND_ZP; - else if (Neighbors[6]) return E_RAIL_ASCEND_ZM; - else if (Neighbors[5]) return E_RAIL_ASCEND_XM; - else if (Neighbors[4]) return E_RAIL_ASCEND_XP; - else if (Neighbors[0] || Neighbors[1]) return E_RAIL_XM_XP; - else if (Neighbors[2] || Neighbors[3]) return E_RAIL_ZM_ZP; + if (Neighbors[7]) return E_META_RAIL_ASCEND_ZP; + else if (Neighbors[6]) return E_META_RAIL_ASCEND_ZM; + else if (Neighbors[5]) return E_META_RAIL_ASCEND_XM; + else if (Neighbors[4]) return E_META_RAIL_ASCEND_XP; + else if (Neighbors[0] || Neighbors[1]) return E_META_RAIL_XM_XP; + else if (Neighbors[2] || Neighbors[3]) return E_META_RAIL_ZM_ZP; ASSERT(!"Weird neighbor count"); return Meta; } @@ -144,16 +144,16 @@ public: } if (RailsCnt > 1) { - if (Neighbors[3] && Neighbors[0]) return E_RAIL_CURVED_ZP_XP; - else if (Neighbors[3] && Neighbors[1]) return E_RAIL_CURVED_ZP_XM; - else if (Neighbors[2] && Neighbors[0]) return E_RAIL_CURVED_ZM_XP; - else if (Neighbors[2] && Neighbors[1]) return E_RAIL_CURVED_ZM_XM; - else if (Neighbors[7] && Neighbors[2]) return E_RAIL_ASCEND_ZP; - else if (Neighbors[3] && Neighbors[6]) return E_RAIL_ASCEND_ZM; - else if (Neighbors[5] && Neighbors[0]) return E_RAIL_ASCEND_XM; - else if (Neighbors[4] && Neighbors[1]) return E_RAIL_ASCEND_XP; - else if (Neighbors[0] && Neighbors[1]) return E_RAIL_XM_XP; - else if (Neighbors[2] && Neighbors[3]) return E_RAIL_ZM_ZP; + if (Neighbors[3] && Neighbors[0]) return E_META_RAIL_CURVED_ZP_XP; + else if (Neighbors[3] && Neighbors[1]) return E_META_RAIL_CURVED_ZP_XM; + else if (Neighbors[2] && Neighbors[0]) return E_META_RAIL_CURVED_ZM_XP; + else if (Neighbors[2] && Neighbors[1]) return E_META_RAIL_CURVED_ZM_XM; + else if (Neighbors[7] && Neighbors[2]) return E_META_RAIL_ASCEND_ZP; + else if (Neighbors[3] && Neighbors[6]) return E_META_RAIL_ASCEND_ZM; + else if (Neighbors[5] && Neighbors[0]) return E_META_RAIL_ASCEND_XM; + else if (Neighbors[4] && Neighbors[1]) return E_META_RAIL_ASCEND_XP; + else if (Neighbors[0] && Neighbors[1]) return E_META_RAIL_XM_XP; + else if (Neighbors[2] && Neighbors[3]) return E_META_RAIL_ZM_ZP; ASSERT(!"Weird neighbor count"); } return Meta; @@ -169,7 +169,7 @@ public: NIBBLETYPE Meta = a_World->GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ); switch (Meta) { - case E_RAIL_ZM_ZP: + case E_META_RAIL_ZM_ZP: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH, E_PURE_DOWN) || @@ -181,7 +181,7 @@ public: break; } - case E_RAIL_XM_XP: + case E_META_RAIL_XM_XP: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST, E_PURE_DOWN) || @@ -193,7 +193,7 @@ public: break; } - case E_RAIL_ASCEND_XP: + case E_META_RAIL_ASCEND_XP: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_EAST) || @@ -205,7 +205,7 @@ public: break; } - case E_RAIL_ASCEND_XM: + case E_META_RAIL_ASCEND_XM: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_EAST) || @@ -217,7 +217,7 @@ public: break; } - case E_RAIL_ASCEND_ZM: + case E_META_RAIL_ASCEND_ZM: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY + 1, a_BlockZ, BLOCK_FACE_NORTH) || @@ -229,7 +229,7 @@ public: break; } - case E_RAIL_ASCEND_ZP: + case E_META_RAIL_ASCEND_ZP: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || @@ -241,7 +241,7 @@ public: break; } - case E_RAIL_CURVED_ZP_XP: + case E_META_RAIL_CURVED_ZP_XP: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH) || @@ -253,7 +253,7 @@ public: break; } - case E_RAIL_CURVED_ZP_XM: + case E_META_RAIL_CURVED_ZP_XM: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_SOUTH) || @@ -265,7 +265,7 @@ public: break; } - case E_RAIL_CURVED_ZM_XM: + case E_META_RAIL_CURVED_ZM_XM: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || @@ -277,7 +277,7 @@ public: break; } - case E_RAIL_CURVED_ZM_XP: + case E_META_RAIL_CURVED_ZM_XP: { if ( IsNotConnected(a_World, a_BlockX, a_BlockY, a_BlockZ, BLOCK_FACE_NORTH) || @@ -325,11 +325,11 @@ public: case BLOCK_FACE_NORTH: { if ( - (Meta == E_RAIL_ZM_ZP) || - (Meta == E_RAIL_ASCEND_ZM) || - (Meta == E_RAIL_ASCEND_ZP) || - (Meta == E_RAIL_CURVED_ZP_XP) || - (Meta == E_RAIL_CURVED_ZP_XM) + (Meta == E_META_RAIL_ZM_ZP) || + (Meta == E_META_RAIL_ASCEND_ZM) || + (Meta == E_META_RAIL_ASCEND_ZP) || + (Meta == E_META_RAIL_CURVED_ZP_XP) || + (Meta == E_META_RAIL_CURVED_ZP_XM) ) { return false; @@ -340,11 +340,11 @@ public: case BLOCK_FACE_SOUTH: { if ( - (Meta == E_RAIL_ZM_ZP) || - (Meta == E_RAIL_ASCEND_ZM) || - (Meta == E_RAIL_ASCEND_ZP) || - (Meta == E_RAIL_CURVED_ZM_XP) || - (Meta == E_RAIL_CURVED_ZM_XM) + (Meta == E_META_RAIL_ZM_ZP) || + (Meta == E_META_RAIL_ASCEND_ZM) || + (Meta == E_META_RAIL_ASCEND_ZP) || + (Meta == E_META_RAIL_CURVED_ZM_XP) || + (Meta == E_META_RAIL_CURVED_ZM_XM) ) { return false; @@ -355,11 +355,11 @@ public: case BLOCK_FACE_EAST: { if ( - (Meta == E_RAIL_XM_XP) || - (Meta == E_RAIL_ASCEND_XP) || - (Meta == E_RAIL_ASCEND_XM) || - (Meta == E_RAIL_CURVED_ZP_XM) || - (Meta == E_RAIL_CURVED_ZM_XM) + (Meta == E_META_RAIL_XM_XP) || + (Meta == E_META_RAIL_ASCEND_XP) || + (Meta == E_META_RAIL_ASCEND_XM) || + (Meta == E_META_RAIL_CURVED_ZP_XM) || + (Meta == E_META_RAIL_CURVED_ZM_XM) ) { return false; @@ -369,11 +369,11 @@ public: case BLOCK_FACE_WEST: { if ( - (Meta == E_RAIL_XM_XP) || - (Meta == E_RAIL_ASCEND_XP) || - (Meta == E_RAIL_ASCEND_XM) || - (Meta == E_RAIL_CURVED_ZP_XP) || - (Meta == E_RAIL_CURVED_ZM_XP) + (Meta == E_META_RAIL_XM_XP) || + (Meta == E_META_RAIL_ASCEND_XP) || + (Meta == E_META_RAIL_ASCEND_XM) || + (Meta == E_META_RAIL_CURVED_ZP_XP) || + (Meta == E_META_RAIL_CURVED_ZM_XP) ) { return false; diff --git a/source/Entities/Minecart.cpp b/source/Entities/Minecart.cpp index 685067e79..0c0b7b58a 100644 --- a/source/Entities/Minecart.cpp +++ b/source/Entities/Minecart.cpp @@ -99,7 +99,7 @@ void cMinecart::HandleRailPhysics(float a_Dt, cChunk & a_Chunk) switch (BelowMeta) { - case E_RAIL_ZM_ZP: // NORTHSOUTH + case E_META_RAIL_ZM_ZP: // NORTHSOUTH { SetRotation(270); SpeedY = 0; // Don't move vertically as on ground @@ -124,7 +124,7 @@ void cMinecart::HandleRailPhysics(float a_Dt, cChunk & a_Chunk) break; } - case E_RAIL_XM_XP: // EASTWEST + case E_META_RAIL_XM_XP: // EASTWEST { SetRotation(180); SpeedY = 0; @@ -146,7 +146,7 @@ void cMinecart::HandleRailPhysics(float a_Dt, cChunk & a_Chunk) break; } - case E_RAIL_ASCEND_ZM: // ASCEND NORTH + case E_META_RAIL_ASCEND_ZM: // ASCEND NORTH { SetRotation(270); SetPosY(floor(GetPosY()) + 0.2); // It seems it doesn't work without levitation :/ @@ -175,7 +175,7 @@ void cMinecart::HandleRailPhysics(float a_Dt, cChunk & a_Chunk) break; } - case E_RAIL_ASCEND_ZP: // ASCEND SOUTH + case E_META_RAIL_ASCEND_ZP: // ASCEND SOUTH { SetRotation(270); SetPosY(floor(GetPosY()) + 0.2); @@ -204,7 +204,7 @@ void cMinecart::HandleRailPhysics(float a_Dt, cChunk & a_Chunk) break; } - case E_RAIL_ASCEND_XM: // ASCEND EAST + case E_META_RAIL_ASCEND_XM: // ASCEND EAST { SetRotation(180); SetPosY(floor(GetPosY()) + 0.2); @@ -231,7 +231,7 @@ void cMinecart::HandleRailPhysics(float a_Dt, cChunk & a_Chunk) break; } - case E_RAIL_ASCEND_XP: // ASCEND WEST + case E_META_RAIL_ASCEND_XP: // ASCEND WEST { SetRotation(180); SetPosY(floor(GetPosY()) + 0.2); @@ -258,7 +258,7 @@ void cMinecart::HandleRailPhysics(float a_Dt, cChunk & a_Chunk) break; } - case E_RAIL_CURVED_ZM_XM: // Ends pointing NORTH and WEST + case E_META_RAIL_CURVED_ZM_XM: // Ends pointing NORTH and WEST { SetRotation(315); // Set correct rotation server side SetPosY(floor(GetPosY()) + 0.2); // Levitate dat cart @@ -274,7 +274,7 @@ void cMinecart::HandleRailPhysics(float a_Dt, cChunk & a_Chunk) break; } - case E_RAIL_CURVED_ZM_XP: // Curved NORTH EAST + case E_META_RAIL_CURVED_ZM_XP: // Curved NORTH EAST { SetRotation(225); SetPosY(floor(GetPosY()) + 0.2); @@ -290,7 +290,7 @@ void cMinecart::HandleRailPhysics(float a_Dt, cChunk & a_Chunk) break; } - case E_RAIL_CURVED_ZP_XM: // Curved SOUTH WEST + case E_META_RAIL_CURVED_ZP_XM: // Curved SOUTH WEST { SetRotation(135); SetPosY(floor(GetPosY()) + 0.2); @@ -306,7 +306,7 @@ void cMinecart::HandleRailPhysics(float a_Dt, cChunk & a_Chunk) break; } - case E_RAIL_CURVED_ZP_XP: // Curved SOUTH EAST + case E_META_RAIL_CURVED_ZP_XP: // Curved SOUTH EAST { SetRotation(45); SetPosY(floor(GetPosY()) + 0.2); -- cgit v1.2.3