From ec6c510bd404524dc63d130b41329fb365423b4b Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 12 Jan 2014 13:28:37 +0000 Subject: Multiple enhancements and fixes to minecarts + They are destroyed instantly by creative mode * Physics is much improved + Basic implementation of powered rails --- src/BlockID.cpp | 1 + src/Entities/Entity.cpp | 5 +- src/Entities/Minecart.cpp | 310 +++++++++++++++++++++++++++------------------- src/Entities/Minecart.h | 7 +- 4 files changed, 191 insertions(+), 132 deletions(-) diff --git a/src/BlockID.cpp b/src/BlockID.cpp index 69a3a817c..095865d07 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -767,6 +767,7 @@ public: g_BlockIsSolid[E_BLOCK_MELON_STEM] = false; g_BlockIsSolid[E_BLOCK_NETHER_PORTAL] = false; g_BlockIsSolid[E_BLOCK_PISTON_EXTENSION] = false; + g_BlockIsSolid[E_BLOCK_POWERED_RAIL] = false; g_BlockIsSolid[E_BLOCK_RAIL] = false; g_BlockIsSolid[E_BLOCK_REDSTONE_TORCH_OFF] = false; g_BlockIsSolid[E_BLOCK_REDSTONE_TORCH_ON] = false; diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 8a74c9da4..fbf76e008 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -321,7 +321,10 @@ void cEntity::DoTakeDamage(TakeDamageInfo & a_TDI) m_Health = 0; } - AddSpeed(a_TDI.Knockback * 2); + if (IsMob() || IsPlayer()) // Knockback for only players and mobs + { + AddSpeed(a_TDI.Knockback * 2); + } m_World->BroadcastEntityStatus(*this, ENTITY_STATUS_HURT); diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index f75e23d8b..710e033f0 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -11,6 +11,9 @@ #include "../Chunk.h" #include "Player.h" +#define MAX_SPEED 8 +#define MAX_SPEED_NEGATIVE -MAX_SPEED + @@ -70,286 +73,329 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) // Inside an unloaded chunk, bail out all processing return; } - BLOCKTYPE BelowType = Chunk->GetBlock(RelPosX, PosY - 1, RelPosZ); - BLOCKTYPE InsideType = Chunk->GetBlock(RelPosX, PosY, RelPosZ); - if (IsBlockRail(BelowType)) + BLOCKTYPE InsideType; + NIBBLETYPE InsideMeta; + Chunk->GetBlockTypeMeta(RelPosX, PosY, RelPosZ, InsideType, InsideMeta); + + if (!IsBlockRail(InsideType)) { - HandleRailPhysics(a_Dt, *Chunk); + Chunk->GetBlockTypeMeta(RelPosX, PosY + 1, RelPosZ, InsideType, InsideMeta); + if (IsBlockRail(InsideType)) AddPosY(1); } - else + + if (IsBlockRail(InsideType)) { - if (IsBlockRail(InsideType)) - { - SetPosY(PosY + 1); - HandleRailPhysics(a_Dt, *Chunk); - } - else + SnapToRail(InsideMeta); + + switch (InsideType) { - super::HandlePhysics(a_Dt, *Chunk); - BroadcastMovementUpdate(); + case E_BLOCK_RAIL: HandleRailPhysics(InsideMeta); break; + case E_BLOCK_DETECTOR_RAIL: break; + case E_BLOCK_ACTIVATOR_RAIL: break; + case E_BLOCK_POWERED_RAIL: HandlePoweredRailPhysics(InsideMeta); break; + default: VERIFY(!"Unhandled rail type despite checking if block was rail!"); break; } + + AddPosition(GetSpeed() * (a_Dt / 1000)); + } + else + { + 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); } + + 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) +void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta) { - - 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. */ - // Get block meta below the cart - int RelPosX = (int)floor(GetPosX()) - a_Chunk.GetPosX() * cChunkDef::Width; - int RelPosZ = (int)floor(GetPosZ()) - a_Chunk.GetPosZ() * cChunkDef::Width; - NIBBLETYPE BelowMeta = a_Chunk.GetMeta(RelPosX, (int)floor(GetPosY() - 1), RelPosZ); - double SpeedX = GetSpeedX(), SpeedY = GetSpeedY(), SpeedZ = GetSpeedZ(); // Get current speed - - switch (BelowMeta) + switch (a_RailMeta) { case E_META_RAIL_ZM_ZP: // NORTHSOUTH { SetRotation(270); - SpeedY = 0; // Don't move vertically as on ground - SpeedX = 0; // Correct diagonal movement from curved rails + SetPosY(floor(GetPosY()) + 0.55); + SetSpeedY(0); // Don't move vertically as on ground + SetSpeedX(0); // Correct diagonal movement from curved rails - if (SpeedZ != 0) // Don't do anything if cart is stationary + if (GetSpeedZ() != 0) // Don't do anything if cart is stationary { - if (SpeedZ > 0) + if (GetSpeedZ() > 0) { // Going SOUTH, slow down - SpeedZ = SpeedZ - 0.1; + AddSpeedZ(-0.1); } else { // Going NORTH, slow down - SpeedZ = SpeedZ + 0.1; + AddSpeedZ(0.1); } } break; } - case E_META_RAIL_XM_XP: // EASTWEST { SetRotation(180); - SpeedY = 0; - SpeedZ = 0; + SetPosY(floor(GetPosY()) + 0.55); + SetSpeedY(0); + SetSpeedZ(0); - if (SpeedX != 0) + if (GetSpeedX() != 0) { - if (SpeedX > 0) + if (GetSpeedX() > 0) { - SpeedX = SpeedX - 0.1; + AddSpeedX(-0.1); } else { - SpeedX = SpeedX + 0.1; + AddSpeedX(0.1); } } break; } - case E_META_RAIL_ASCEND_ZM: // ASCEND NORTH { SetRotation(270); - SetPosY(floor(GetPosY()) + 0.2); // It seems it doesn't work without levitation :/ - SpeedX = 0; + SetSpeedX(0); - if (SpeedZ >= 0) + if (GetSpeedZ() >= 0) { // SpeedZ POSITIVE, going SOUTH - if (SpeedZ <= MAX_SPEED) // Speed limit + if (GetSpeedZ() <= MAX_SPEED) // Speed limit { - SpeedZ = SpeedZ + 0.5; // Speed up - SpeedY = (0 - SpeedZ); // Downward movement is negative (0 minus positive numbers is negative) - } - else - { - SpeedZ = MAX_SPEED; // Enforce speed limit - SpeedY = (0 - SpeedZ); + AddSpeedZ(0.5); // Speed up + SetSpeedY(-GetSpeedZ()); // Downward movement is negative (0 minus positive numbers is negative) } } 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) + AddSpeedZ(1); // Slow down + SetSpeedY(-GetSpeedZ()); // Upward movement is positive (0 minus negative number is positive number) } break; } - case E_META_RAIL_ASCEND_ZP: // ASCEND SOUTH { SetRotation(270); - SetPosY(floor(GetPosY()) + 0.2); - SpeedX = 0; + SetSpeedX(0); - if (SpeedZ > 0) + if (GetSpeedZ() > 0) { // SpeedZ POSITIVE, going SOUTH - SpeedZ = SpeedZ - 0.4; // Slow down - SpeedY = SpeedZ; // Upward movement positive + AddSpeedZ(-1); // Slow down + SetSpeedY(GetSpeedZ()); // Upward movement positive } else { - if (SpeedZ >= MAX_SPEED_NEGATIVE) // Speed limit + if (GetSpeedZ() >= MAX_SPEED_NEGATIVE) // Speed limit { // SpeedZ NEGATIVE, going NORTH - SpeedZ = SpeedZ - 0.5; // Speed up - SpeedY = SpeedZ; // Downward movement negative - } - else - { - SpeedZ = MAX_SPEED_NEGATIVE; // Enforce speed limit - SpeedY = SpeedZ; + AddSpeedZ(-0.5); // Speed up + SetSpeedY(GetSpeedZ()); // Downward movement negative } } break; } - case E_META_RAIL_ASCEND_XM: // ASCEND EAST { SetRotation(180); - SetPosY(floor(GetPosY()) + 0.2); - SpeedZ = 0; + SetSpeedZ(0); - if (SpeedX >= 0) + if (GetSpeedX() >= 0) { - if (SpeedX <= MAX_SPEED) - { - SpeedX = SpeedX + 0.5; - SpeedY = (0 - SpeedX); - } - else + if (GetSpeedX() <= MAX_SPEED) { - SpeedX = MAX_SPEED; - SpeedY = (0 - SpeedX); + AddSpeedX(0.5); + SetSpeedY(-GetSpeedX()); } } else { - SpeedX = SpeedX + 0.4; - SpeedY = (0 - SpeedX); + AddSpeedX(1); + SetSpeedY(-GetSpeedX()); } break; } - case E_META_RAIL_ASCEND_XP: // ASCEND WEST { SetRotation(180); - SetPosY(floor(GetPosY()) + 0.2); - SpeedZ = 0; + SetSpeedZ(0); - if (SpeedX > 0) + if (GetSpeedX() > 0) { - SpeedX = SpeedX - 0.4; - SpeedY = SpeedX; + AddSpeedX(-1); + SetSpeedY(GetSpeedX()); } else { - if (SpeedX >= MAX_SPEED_NEGATIVE) - { - SpeedX = SpeedX - 0.5; - SpeedY = SpeedX; - } - else + if (GetSpeedX() >= MAX_SPEED_NEGATIVE) { - SpeedX = MAX_SPEED_NEGATIVE; - SpeedY = SpeedX; + AddSpeedX(-0.5); + SetSpeedY(GetSpeedX()); } } break; } - 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 + SetPosY(floor(GetPosY()) + 0.3); // Levitate dat cart - if (SpeedZ > 0) // Cart moving south + if (GetSpeedZ() > 0) // Cart moving south { - SpeedX = (0 - SpeedZ); // Diagonally move southwest (which will make cart hit a southwest rail) + SetSpeedX(-GetSpeedZ()); // Diagonally move southwest (which will make cart hit a southwest rail) } - else if (SpeedX > 0) // Cart moving east + else if (GetSpeedX() > 0) // Cart moving east { - SpeedZ = (0 - SpeedX); // Diagonally move northeast + SetSpeedZ(-GetSpeedX()); // Diagonally move northeast } break; } - case E_META_RAIL_CURVED_ZM_XP: // Curved NORTH EAST { SetRotation(225); - SetPosY(floor(GetPosY()) + 0.2); + SetPosY(floor(GetPosY()) + 0.3); - if (SpeedZ > 0) + if (GetSpeedZ() > 0) { - SpeedX = SpeedZ; + SetSpeedX(GetSpeedZ()); } - else if (SpeedX < 0) + else if (GetSpeedX() < 0) { - SpeedZ = SpeedX; + SetSpeedZ(GetSpeedX()); } break; } - case E_META_RAIL_CURVED_ZP_XM: // Curved SOUTH WEST { SetRotation(135); - SetPosY(floor(GetPosY()) + 0.2); + SetPosY(floor(GetPosY()) + 0.3); - if (SpeedZ < 0) + if (GetSpeedZ() < 0) { - SpeedX = SpeedZ; + SetSpeedX(GetSpeedZ()); } - else if (SpeedX > 0) + else if (GetSpeedX() > 0) { - SpeedZ = SpeedX; + SetSpeedZ(GetSpeedX()); } break; } - case E_META_RAIL_CURVED_ZP_XP: // Curved SOUTH EAST { SetRotation(45); - SetPosY(floor(GetPosY()) + 0.2); + SetPosY(floor(GetPosY()) + 0.3); - if (SpeedZ < 0) + if (GetSpeedZ() < 0) { - SpeedX = (0 - SpeedZ); + SetSpeedX(-GetSpeedZ()); } - else if (SpeedX < 0) + else if (GetSpeedX() < 0) { - SpeedZ = (0 - SpeedX); + SetSpeedZ(-GetSpeedX()); } break; } - default: { ASSERT(!"Unhandled rail meta!"); // Dun dun DUN! break; } } +} - // Set speed to speed variables - SetSpeedX(SpeedX); - SetSpeedY(SpeedY); - SetSpeedZ(SpeedZ); - // Broadcast position to client - BroadcastMovementUpdate(); + +void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) +{ + if ((a_RailMeta & 0x8) == 0x8) + { + switch (a_RailMeta & 0x07) + { + case E_META_RAIL_ZM_ZP: // NORTHSOUTH + { + SetRotation(270); + SetPosY(floor(GetPosY()) + 0.55); + SetSpeedY(0); // Don't move vertically as on ground + SetSpeedX(0); // Correct diagonal movement from curved rails + + if (GetSpeedZ() != 0) // Don't do anything if cart is stationary + { + if (GetSpeedZ() > 0) + { + // Going SOUTH, slow down + AddSpeedZ(1); + } + else + { + // Going NORTH, slow down + AddSpeedZ(-1); + } + } + break; + } + case E_META_RAIL_XM_XP: // EASTWEST + { + SetRotation(180); + SetPosY(floor(GetPosY()) + 0.55); + SetSpeedY(0); + SetSpeedZ(0); + + if (GetSpeedX() != 0) + { + if (GetSpeedX() > 0) + { + AddSpeedX(-1); + } + else + { + AddSpeedX(1); + } + } + break; + } + } + } +} + + + + + +void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) +{ + switch (a_RailMeta) + { + case E_META_RAIL_ASCEND_XM: + case E_META_RAIL_ASCEND_XP: + case E_META_RAIL_XM_XP: + { + SetSpeedZ(0); + SetPosZ(floor(GetPosZ()) + 0.3); + break; + } + case E_META_RAIL_ASCEND_ZM: + case E_META_RAIL_ASCEND_ZP: + case E_META_RAIL_ZM_ZP: + { + SetSpeedX(0); + SetPosX(floor(GetPosX()) + 0.3); + break; + } + default: break; + } } @@ -358,6 +404,14 @@ void cMinecart::HandleRailPhysics(float a_Dt, cChunk & a_Chunk) void cMinecart::DoTakeDamage(TakeDamageInfo & TDI) { + if (TDI.Attacker->IsPlayer() && ((cPlayer *)TDI.Attacker)->IsGameModeCreative()) + { + Destroy(); + TDI.FinalDamage = GetMaxHealth(); // Instant hit for creative + super::DoTakeDamage(TDI); + return; // No drops for creative + } + m_LastDamage = TDI.FinalDamage; super::DoTakeDamage(TDI); @@ -365,7 +419,7 @@ void cMinecart::DoTakeDamage(TakeDamageInfo & TDI) if (GetHealth() <= 0) { - Destroy(true); + Destroy(); cItems Drops; switch (m_Payload) diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index b1b48be4e..e353e18d9 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -53,15 +53,16 @@ public: virtual void DoTakeDamage(TakeDamageInfo & TDI) override; int LastDamage(void) const { return m_LastDamage; } - void HandleRailPhysics(float a_Dt, cChunk & a_Chunk); ePayload GetPayload(void) const { return m_Payload; } protected: ePayload m_Payload; + int m_LastDamage; cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z); - - int m_LastDamage; + void HandleRailPhysics(NIBBLETYPE a_RailMeta); + void HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta); + void SnapToRail(NIBBLETYPE a_RailMeta); } ; -- cgit v1.2.3 From e932c69b82b3383abf7720d91ba2bd911d7d7a65 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 12 Jan 2014 13:59:39 +0000 Subject: Fixed VS2013 compile and updated Core --- MCServer/Plugins/Core | 2 +- VC2013/CryptoPP.vcxproj.filters | 6 ++--- VC2013/MCServer.vcxproj | 5 ++-- VC2013/MCServer.vcxproj.filters | 55 ++++++++++++++++++++++------------------- 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/MCServer/Plugins/Core b/MCServer/Plugins/Core index c65b56767..944b0e953 160000 --- a/MCServer/Plugins/Core +++ b/MCServer/Plugins/Core @@ -1 +1 @@ -Subproject commit c65b56767a5e59ca387a05be72ef18791baa9aed +Subproject commit 944b0e95303a17200e52699c3bc7c349424be581 diff --git a/VC2013/CryptoPP.vcxproj.filters b/VC2013/CryptoPP.vcxproj.filters index becd042b8..d47a1c34c 100644 --- a/VC2013/CryptoPP.vcxproj.filters +++ b/VC2013/CryptoPP.vcxproj.filters @@ -2,15 +2,15 @@ - {3c30caed-20a3-4bd8-b12e-fdd1e13455e5} + {59bfc075-705c-42cd-adf7-40cef1aed8e1} .cpp - {770573d2-b90d-43f4-ac1c-464ab10c46ec} + {407d7f02-df9e-485b-a95f-2f1dad08cbed} .;.h - {1ac058bb-f217-4ac3-a14b-9c6ba021e030} + {293a01a6-81d1-4272-a7ff-310526bbc77f} diff --git a/VC2013/MCServer.vcxproj b/VC2013/MCServer.vcxproj index d52c16323..ada5c5134 100644 --- a/VC2013/MCServer.vcxproj +++ b/VC2013/MCServer.vcxproj @@ -226,6 +226,7 @@ + @@ -234,8 +235,6 @@ - - @@ -374,7 +373,6 @@ - @@ -618,6 +616,7 @@ + diff --git a/VC2013/MCServer.vcxproj.filters b/VC2013/MCServer.vcxproj.filters index 30e90a9b0..176afad2e 100644 --- a/VC2013/MCServer.vcxproj.filters +++ b/VC2013/MCServer.vcxproj.filters @@ -10,73 +10,73 @@ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - {813698c3-b2c1-4f3d-a89c-7ac6239fff97} + {46ffa881-c36b-41b0-85df-90e0f78c6285} - {b120a538-d8b9-4576-8675-36cf01fd69fc} + {5eb3c155-b618-4232-92a5-52b3ae70ec96} - {85037cf1-81a5-47c7-8c2e-899ea706b8e7} + {5f745788-b9aa-4dde-9763-cdfaddb3dfdf} - {46c9cb22-7c7f-4589-b9b2-1fc79d2bdbdf} + {acb44271-df18-41b2-8a50-656a49c39d3c} - {f12178cb-2ecb-4e48-9a8d-ba3e2e73cfbc} + {1091cb9f-3d9d-4ed5-9359-fc762be21759} - {488bc224-735f-405c-83de-870373cb52cb} + {c40bec86-f173-440a-b07e-bab15c8ce965} - {41c0d7c9-43b5-4d17-b50e-3c8ac3aa2905} + {4180990c-1257-4d07-9009-08535fedfbf8} - {2c71a15a-8c65-4be7-bdfb-e083f4841c4a} + {ffc2297f-c790-4190-a56f-ac6a1f97a30c} - {2227f719-f0ac-444e-af14-230853017c45} + {011ff757-845a-4342-862e-44207ec46a94} - {eb070b55-ba10-4bce-ba06-5d785a055e54} + {7f7a0b8c-4ee6-4a3a-92d6-5ba242a565f3} - {779dac55-c718-4fe1-8b67-547d431b9ebc} + {07157169-9da7-4998-9f00-4580641cf811} - {89847a5d-608a-4137-a766-1557276b4fcf} + {5b92b198-0a58-4399-9c8e-662bd5062b6c} - {e159d08d-daec-46de-9b60-9f8e660da91d} + {16a88457-3862-4ff0-a591-a7160ea956f5} - {0278092b-abe5-4276-81cf-59e4079e5bc7} + {a3561ecf-a501-4c76-b176-1f214b7a5523} - {e4879cf2-e769-4e1d-8905-0f6c40ee5bc1} + {a35eb320-d10b-4592-92ed-2d2f242dbed7} - {d641a9d4-f5dc-4808-bee6-194306505244} + {1c271d11-30ce-4aef-b8a9-7c8ee560d5d6} - {a1e39415-2aca-4779-a558-2567a9de304f} + {223bdf26-d107-498f-8c42-00c19ef80348} - {eb5f3060-03ed-4548-8bde-340454d3d23a} + {99140e5f-0287-4601-ad28-bad2533d8876} - {7c681450-041a-4846-acf6-951c1f4e32a4} + {beb25b3b-31f3-468e-a721-6d0dc297e4b5} - {e961964c-9fb7-4513-89fa-05e0b760e0f1} + {f848f39d-680d-4f9c-8dcb-da9a0bb871f5} - {70696c83-2307-43c6-8851-81aa3baa8523} + {7c735e41-f3b2-4500-856b-54845f834eb2} - {d3b692db-0684-4b89-9d38-2e5af12e9a6e} + {83d5aac9-2975-4334-9acc-b48e96a16b23} - {6eee304c-f055-4758-a248-a125e1af7e73} + {e5167107-9cc8-4e03-b519-c3a13b9b7955} @@ -96,6 +96,9 @@ Source Files + + Source Files + Source Files @@ -513,9 +516,6 @@ Source Files\Bindings - - Source Files\Bindings - Source Files\Bindings @@ -1114,6 +1114,9 @@ Source Files + + Source Files + Source Files -- cgit v1.2.3 From e114008559d2de9a90e9c9bb04bf8f60de535734 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 12 Jan 2014 14:03:50 +0000 Subject: Fixed settings plugin generation after IniFile --- src/Bindings/PluginManager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Bindings/PluginManager.cpp b/src/Bindings/PluginManager.cpp index 68e6aea33..24bb914d1 100644 --- a/src/Bindings/PluginManager.cpp +++ b/src/Bindings/PluginManager.cpp @@ -169,9 +169,9 @@ void cPluginManager::InsertDefaultPlugins(cIniFile & a_SettingsIni) a_SettingsIni.AddKeyComment("Plugins", " Plugin=HookNotify"); a_SettingsIni.AddKeyComment("Plugins", " Plugin=ChunkWorx"); a_SettingsIni.AddKeyComment("Plugins", " Plugin=APIDump"); - a_SettingsIni.SetValue("Plugins", "Plugin", "Core"); - a_SettingsIni.SetValue("Plugins", "Plugin", "TransAPI"); - a_SettingsIni.SetValue("Plugins", "Plugin", "ChatLog"); + a_SettingsIni.AddValue("Plugins", "Plugin", "Core"); + a_SettingsIni.AddValue("Plugins", "Plugin", "TransAPI"); + a_SettingsIni.AddValue("Plugins", "Plugin", "ChatLog"); } -- cgit v1.2.3 From 1d81db64462d7b37bad32d0a7c86a798cff21d93 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 12 Jan 2014 23:19:08 +0000 Subject: Fixed wire, rail, and pressure plate unpowering --- src/Simulator/RedstoneSimulator.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Simulator/RedstoneSimulator.cpp b/src/Simulator/RedstoneSimulator.cpp index 6ab915d03..469680098 100644 --- a/src/Simulator/RedstoneSimulator.cpp +++ b/src/Simulator/RedstoneSimulator.cpp @@ -69,7 +69,7 @@ void cRedstoneSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChu // Changeable sources ((Block == E_BLOCK_REDSTONE_WIRE) && (Meta == 0)) || ((Block == E_BLOCK_LEVER) && !IsLeverOn(Meta)) || - ((Block == E_BLOCK_DETECTOR_RAIL) && (Meta & 0x08) == 0x08) || + ((Block == E_BLOCK_DETECTOR_RAIL) && (Meta & 0x08) == 0) || (((Block == E_BLOCK_STONE_BUTTON) || (Block == E_BLOCK_WOODEN_BUTTON)) && (!IsButtonOn(Meta))) || (((Block == E_BLOCK_STONE_PRESSURE_PLATE) || (Block == E_BLOCK_WOODEN_PRESSURE_PLATE)) && (Meta == 0)) ) @@ -505,8 +505,7 @@ void cRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_BlockY, int a_Bl // transferring power to other wires around. // However, self not directly powered anymore, so source must have been removed, // therefore, self must be set to meta zero - m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0); - m_World.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ); + m_World.SetBlock(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_REDSTONE_WIRE, 0); // SetMeta & WakeUpSims doesn't seem to work here, so SetBlock return; // No need to process block power sets because self not powered } else @@ -903,6 +902,7 @@ void cRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_BlockY, int a_B else { m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x0); + m_World.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ); } break; } @@ -965,6 +965,7 @@ void cRedstoneSimulator::HandlePressurePlate(int a_BlockX, int a_BlockY, int a_B else { m_World.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, 0x0); + m_World.WakeUpSimulators(a_BlockX, a_BlockY, a_BlockZ); } break; } -- cgit v1.2.3 From edefa27a48e2b5e7c82e74ca0e924172181fb098 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 12 Jan 2014 23:23:36 +0000 Subject: Detaching improvements * Players now search for an area around themselves to teleport to when detaching from something --- src/Entities/Entity.cpp | 8 +++++--- src/Entities/Entity.h | 2 +- src/Entities/Player.cpp | 26 ++++++++++++++++++++++++++ src/Entities/Player.h | 2 ++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index fbf76e008..bc66305b1 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1107,9 +1107,11 @@ void cEntity::AttachTo(cEntity * a_AttachTo) // Already attached to that entity, nothing to do here return; } - - // Detach from any previous entity: - Detach(); + if (m_AttachedTo != NULL) + { + // Detach from any previous entity: + Detach(); + } // Attach to the new entity: m_AttachedTo = a_AttachTo; diff --git a/src/Entities/Entity.h b/src/Entities/Entity.h index 2ba1b303d..878e69668 100644 --- a/src/Entities/Entity.h +++ b/src/Entities/Entity.h @@ -327,7 +327,7 @@ public: void AttachTo(cEntity * a_AttachTo); /// Detaches from the currently attached entity, if any - void Detach(void); + virtual void Detach(void); /// Makes sure head yaw is not over the specified range. void WrapHeadYaw(); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index bc92790aa..cdedb0c5a 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1884,3 +1884,29 @@ void cPlayer::ApplyFoodExhaustionFromMovement() + +void cPlayer::Detach() +{ + super::Detach(); + int PosX = (int)floor(GetPosX()); + int PosY = (int)floor(GetPosY()); + int PosZ = (int)floor(GetPosZ()); + + // Search for a position within an area to teleport player after detachment + // Position must be solid land, and occupied by a nonsolid block + // If nothing found, player remains where they are + for (int x = PosX - 2; x <= (PosX + 2); ++x) + { + for (int y = PosY; y <= (PosY + 3); ++y) + { + for (int z = PosZ - 2; z <= (PosZ + 2); ++z) + { + if (!g_BlockIsSolid[m_World->GetBlock(x, y, z)] && g_BlockIsSolid[m_World->GetBlock(x, y - 1, z)]) + { + TeleportToCoords(x, y, z); + return; + } + } + } + } +} \ No newline at end of file diff --git a/src/Entities/Player.h b/src/Entities/Player.h index f9ce950ba..bf3ca08e8 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -350,6 +350,8 @@ public: virtual bool IsCrouched (void) const { return m_IsCrouched; } virtual bool IsSprinting(void) const { return m_IsSprinting; } virtual bool IsRclking (void) const { return IsEating(); } + + virtual void Detach(void); protected: typedef std::map< std::string, bool > PermissionMap; -- cgit v1.2.3 From a66e154b90a96d41fd2cc0c9ac30f2e55e692546 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 13 Jan 2014 22:37:09 +0000 Subject: Final improvements to Minecarts * Fixed curved rails being a little broken + Implemented detector rails + Implemented block collisions on rails * Fixed snapping to rail - Removed minecart physics conditions in Entity.cpp as minecarts use their own simulator when on rails Fixes #148 and #217; partially implemented #215. This is Cave Johnson, and we're done here. --- src/Entities/Entity.cpp | 44 ++----- src/Entities/Minecart.cpp | 319 ++++++++++++++++++++++++++++++++++++++-------- src/Entities/Minecart.h | 22 +++- 3 files changed, 292 insertions(+), 93 deletions(-) diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index bc66305b1..cd97c6766 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -629,11 +629,6 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) { fallspeed = m_Gravity * a_Dt / 3; // Fall 3x slower in water. } - else if (IsBlockRail(BlockBelow) && IsMinecart()) // Rails aren't solid, except for Minecarts - { - fallspeed = 0; - m_bOnGround = true; - } else if (BlockIn == E_BLOCK_COBWEB) { NextSpeed.y *= 0.05; // Reduce overall falling speed @@ -648,41 +643,18 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) } else { - if (IsMinecart()) + // Friction + if (NextSpeed.SqrLength() > 0.0004f) { - if (!IsBlockRail(BlockBelow)) + NextSpeed.x *= 0.7f / (1 + a_Dt); + if (fabs(NextSpeed.x) < 0.05) { - // Friction if minecart is off track, otherwise, Minecart.cpp handles this - 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; - } - } + NextSpeed.x = 0; } - } - else - { - // Friction for non-minecarts - if (NextSpeed.SqrLength() > 0.0004f) + NextSpeed.z *= 0.7f / (1 + a_Dt); + if (fabs(NextSpeed.z) < 0.05) { - 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; - } + NextSpeed.z = 0; } } } diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index 710e033f0..be95b2128 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -2,6 +2,7 @@ // Minecart.cpp // Implements the cMinecart class representing a minecart in the world +// Handles physics when a minecart is on any type of rail (overrides simulator in Entity.cpp) // Indiana Jones! #include "Globals.h" @@ -10,6 +11,7 @@ #include "../ClientHandle.h" #include "../Chunk.h" #include "Player.h" +#include "../BoundingBox.h" #define MAX_SPEED 8 #define MAX_SPEED_NEGATIVE -MAX_SPEED @@ -21,11 +23,15 @@ 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_LastDamage(0) + m_LastDamage(0), + m_DetectorRailPosition(0, 0, 0), + m_bIsOnDetectorRail(false) { SetMass(20.f); SetMaxHealth(6); SetHealth(6); + SetWidth(1.2); + SetHeight(0.9); } @@ -56,6 +62,11 @@ void cMinecart::SpawnOn(cClientHandle & a_ClientHandle) void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) { + if (IsDestroyed()) // Mainly to stop detector rails triggering again after minecart is dead + { + return; + } + int PosY = (int)floor(GetPosY()); if ((PosY <= 0) || (PosY >= cChunkDef::Height)) { @@ -80,31 +91,45 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) if (!IsBlockRail(InsideType)) { - Chunk->GetBlockTypeMeta(RelPosX, PosY + 1, RelPosZ, InsideType, InsideMeta); - if (IsBlockRail(InsideType)) AddPosY(1); + Chunk->GetBlockTypeMeta(RelPosX, PosY + 1, RelPosZ, InsideType, InsideMeta); // When an descending minecart hits a flat rail, it goes through the ground; check for this + if (IsBlockRail(InsideType)) AddPosY(1); // Push cart upwards } if (IsBlockRail(InsideType)) { + bool WasDetectorRail = false; SnapToRail(InsideMeta); switch (InsideType) { - case E_BLOCK_RAIL: HandleRailPhysics(InsideMeta); break; - case E_BLOCK_DETECTOR_RAIL: break; + case E_BLOCK_RAIL: HandleRailPhysics(InsideMeta, a_Dt); break; case E_BLOCK_ACTIVATOR_RAIL: break; case E_BLOCK_POWERED_RAIL: HandlePoweredRailPhysics(InsideMeta); break; + case E_BLOCK_DETECTOR_RAIL: + { + HandleDetectorRailPhysics(InsideMeta, a_Dt); + WasDetectorRail = true; + break; + } default: VERIFY(!"Unhandled rail type despite checking if block was rail!"); break; } - AddPosition(GetSpeed() * (a_Dt / 1000)); + 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 { + // Not on rail, default physics 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); } + // Broadcast positioning changes to client BroadcastMovementUpdate(); } @@ -112,7 +137,7 @@ void cMinecart::HandlePhysics(float a_Dt, cChunk & a_Chunk) -void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta) +void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt) { /* NOTE: Please bear in mind that taking away from negatives make them even more negative, @@ -127,6 +152,8 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta) SetPosY(floor(GetPosY()) + 0.55); SetSpeedY(0); // Don't move vertically as on ground SetSpeedX(0); // Correct diagonal movement from curved rails + + if (TestBlockCollision(a_RailMeta)) return; if (GetSpeedZ() != 0) // Don't do anything if cart is stationary { @@ -150,6 +177,8 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta) SetSpeedY(0); SetSpeedZ(0); + if (TestBlockCollision(a_RailMeta)) return; + if (GetSpeedX() != 0) { if (GetSpeedX() > 0) @@ -250,60 +279,94 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta) case E_META_RAIL_CURVED_ZM_XM: // Ends pointing NORTH and WEST { SetRotation(315); // Set correct rotation server side - SetPosY(floor(GetPosY()) + 0.3); // Levitate dat cart + SetPosY(floor(GetPosY()) + 0.55); // Levitate dat cart + + if (TestBlockCollision(a_RailMeta)) return; if (GetSpeedZ() > 0) // Cart moving south { - SetSpeedX(-GetSpeedZ()); // Diagonally move southwest (which will make cart hit a southwest rail) + int OldX = (int)floor(GetPosX()); + AddSpeedX(-GetSpeedZ() + 0.5); // See below + AddPosX(-GetSpeedZ() * (a_Dt / 1000)); // Diagonally move southwest (which will make cart hit a southwest rail) + // If we are already at southwest rail, set Z speed to zero as we can be moving so fast, MCS doesn't tick fast enough to active the handle for the rail... + // ...and so we derail unexpectedly. + if (GetPosX() <= OldX - 1) SetSpeedZ(0); } else if (GetSpeedX() > 0) // Cart moving east { - SetSpeedZ(-GetSpeedX()); // Diagonally move northeast + int OldZ = (int)floor(GetPosZ()); + AddSpeedZ(-GetSpeedX() + 0.5); + AddPosZ(-GetSpeedX() * (a_Dt / 1000)); // Diagonally move northeast + if (GetPosZ() <= OldZ - 1) SetSpeedX(0); } break; } case E_META_RAIL_CURVED_ZM_XP: // Curved NORTH EAST { SetRotation(225); - SetPosY(floor(GetPosY()) + 0.3); + SetPosY(floor(GetPosY()) + 0.55); + + if (TestBlockCollision(a_RailMeta)) return; if (GetSpeedZ() > 0) { - SetSpeedX(GetSpeedZ()); + int OldX = (int)floor(GetPosX()); + AddSpeedX(GetSpeedZ() - 0.5); + AddPosX(GetSpeedZ() * (a_Dt / 1000)); + if (GetPosX() >= OldX + 1) SetSpeedZ(0); } else if (GetSpeedX() < 0) { - SetSpeedZ(GetSpeedX()); + int OldZ = (int)floor(GetPosZ()); + AddSpeedZ(GetSpeedX() + 0.5); + AddPosZ(GetSpeedX() * (a_Dt / 1000)); + if (GetPosZ() <= OldZ - 1) SetSpeedX(0); } break; } case E_META_RAIL_CURVED_ZP_XM: // Curved SOUTH WEST { SetRotation(135); - SetPosY(floor(GetPosY()) + 0.3); + SetPosY(floor(GetPosY()) + 0.55); + + if (TestBlockCollision(a_RailMeta)) return; if (GetSpeedZ() < 0) { - SetSpeedX(GetSpeedZ()); + int OldX = (int)floor(GetPosX()); + AddSpeedX(GetSpeedZ() + 0.5); + AddPosX(GetSpeedZ() * (a_Dt / 1000)); + if (GetPosX() <= OldX - 1) SetSpeedZ(0); } else if (GetSpeedX() > 0) { - SetSpeedZ(GetSpeedX()); + int OldZ = (int)floor(GetPosZ()); + AddSpeedZ(GetSpeedX() - 0.5); + AddPosZ(GetSpeedX() * (a_Dt / 1000)); + if (GetPosZ() >= OldZ + 1) SetSpeedX(0); } break; } case E_META_RAIL_CURVED_ZP_XP: // Curved SOUTH EAST { SetRotation(45); - SetPosY(floor(GetPosY()) + 0.3); + SetPosY(floor(GetPosY()) + 0.55); + + if (TestBlockCollision(a_RailMeta)) return; if (GetSpeedZ() < 0) { - SetSpeedX(-GetSpeedZ()); + int OldX = (int)floor(GetPosX()); + AddSpeedX(-GetSpeedZ() - 0.5); + AddPosX(-GetSpeedZ() * (a_Dt / 1000)); + if (GetPosX() >= OldX + 1) SetSpeedZ(0); } else if (GetSpeedX() < 0) { - SetSpeedZ(-GetSpeedX()); + int OldZ = (int)floor(GetPosZ()); + AddSpeedZ(-GetSpeedX() - 0.5); + AddPosZ(-GetSpeedX() * (a_Dt / 1000)); + if (GetPosZ() >= OldZ + 1) SetSpeedX(0); } break; } @@ -320,52 +383,62 @@ void cMinecart::HandleRailPhysics(NIBBLETYPE a_RailMeta) void cMinecart::HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta) { + // Initialise to 'slow down' values + int AccelDecelSpeed = -1; + int AccelDecelNegSpeed = 1; + if ((a_RailMeta & 0x8) == 0x8) { - switch (a_RailMeta & 0x07) + // Rail powered - set variables to 'speed up' values + AccelDecelSpeed = 1; + AccelDecelNegSpeed = -1; + } + + switch (a_RailMeta & 0x07) + { + case E_META_RAIL_ZM_ZP: // NORTHSOUTH { - case E_META_RAIL_ZM_ZP: // NORTHSOUTH - { - SetRotation(270); - SetPosY(floor(GetPosY()) + 0.55); - SetSpeedY(0); // Don't move vertically as on ground - SetSpeedX(0); // Correct diagonal movement from curved rails + SetRotation(270); + SetPosY(floor(GetPosY()) + 0.55); + SetSpeedY(0); + SetSpeedX(0); + + if (TestBlockCollision(a_RailMeta)) return; - if (GetSpeedZ() != 0) // Don't do anything if cart is stationary + if (GetSpeedZ() != 0) + { + if (GetSpeedZ() > 0) { - if (GetSpeedZ() > 0) - { - // Going SOUTH, slow down - AddSpeedZ(1); - } - else - { - // Going NORTH, slow down - AddSpeedZ(-1); - } + AddSpeedZ(AccelDecelNegSpeed); + } + else + { + AddSpeedZ(AccelDecelSpeed); } - break; } - case E_META_RAIL_XM_XP: // EASTWEST - { - SetRotation(180); - SetPosY(floor(GetPosY()) + 0.55); - SetSpeedY(0); - SetSpeedZ(0); + break; + } + case E_META_RAIL_XM_XP: // EASTWEST + { + SetRotation(180); + SetPosY(floor(GetPosY()) + 0.55); + SetSpeedY(0); + SetSpeedZ(0); - if (GetSpeedX() != 0) + if (TestBlockCollision(a_RailMeta)) return; + + if (GetSpeedX() != 0) + { + if (GetSpeedX() > 0) { - if (GetSpeedX() > 0) - { - AddSpeedX(-1); - } - else - { - AddSpeedX(1); - } + AddSpeedX(AccelDecelSpeed); + } + else + { + AddSpeedX(AccelDecelNegSpeed); } - break; } + break; } } } @@ -374,6 +447,20 @@ 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); +} + + + + + void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) { switch (a_RailMeta) @@ -383,7 +470,7 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) case E_META_RAIL_XM_XP: { SetSpeedZ(0); - SetPosZ(floor(GetPosZ()) + 0.3); + SetPosZ(floor(GetPosZ()) + 0.5); break; } case E_META_RAIL_ASCEND_ZM: @@ -391,7 +478,7 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) case E_META_RAIL_ZM_ZP: { SetSpeedX(0); - SetPosX(floor(GetPosX()) + 0.3); + SetPosX(floor(GetPosX()) + 0.5); break; } default: break; @@ -402,6 +489,114 @@ void cMinecart::SnapToRail(NIBBLETYPE a_RailMeta) +bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) +{ + switch (a_RailMeta) + { + case E_META_RAIL_ZM_ZP: + { + if (GetSpeedZ() > 0) + { + BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)ceil(GetPosZ())); + if (!IsBlockRail(Block) && g_BlockIsSolid[Block]) + { + // We could try to detect a block in front based purely on coordinates, but xoft made a bounding box system - why not use? :P + cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()), (int)floor(GetPosY()), (int)ceil(GetPosZ())), 0.5, 1); + cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); + + if (bbBlock.DoesIntersect(bbMinecart)) + { + SetSpeed(0, 0, 0); + SetPosZ(floor(GetPosZ()) + 0.4); + return true; + } + } + } + else + { + BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1); + if (!IsBlockRail(Block) && g_BlockIsSolid[Block]) + { + cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1), 0.5, 1); + cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ() - 1), GetWidth() / 2, GetHeight()); + + if (bbBlock.DoesIntersect(bbMinecart)) + { + SetSpeed(0, 0, 0); + SetPosZ(floor(GetPosZ()) + 0.65); + return true; + } + } + } + break; + } + case E_META_RAIL_XM_XP: + { + if (GetSpeedX() > 0) + { + BLOCKTYPE Block = m_World->GetBlock((int)ceil(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())); + if (!IsBlockRail(Block) && g_BlockIsSolid[Block]) + { + cBoundingBox bbBlock(Vector3d((int)ceil(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())), 0.5, 1); + cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); + + if (bbBlock.DoesIntersect(bbMinecart)) + { + SetSpeed(0, 0, 0); + SetPosX(floor(GetPosX()) + 0.4); + return true; + } + } + } + else + { + BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())); + if (!IsBlockRail(Block) && g_BlockIsSolid[Block]) + { + cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())), 0.5, 1); + cBoundingBox bbMinecart(Vector3d(GetPosX() - 1, floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); + + if (bbBlock.DoesIntersect(bbMinecart)) + { + SetSpeed(0, 0, 0); + SetPosX(floor(GetPosX()) + 0.65); + return true; + } + } + } + break; + } + 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: + { + BLOCKTYPE BlockXM = m_World->GetBlock((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())); + BLOCKTYPE BlockXP = m_World->GetBlock((int)floor(GetPosX()) + 1, (int)floor(GetPosY()), (int)floor(GetPosZ())); + BLOCKTYPE BlockZM = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1); + BLOCKTYPE BlockZP = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1); + if ( + (!IsBlockRail(BlockXM) && g_BlockIsSolid[BlockXM]) || + (!IsBlockRail(BlockXP) && g_BlockIsSolid[BlockXP]) || + (!IsBlockRail(BlockZM) && g_BlockIsSolid[BlockZM]) || + (!IsBlockRail(BlockZP) && g_BlockIsSolid[BlockZP]) + ) + { + SetSpeed(0, 0, 0); + SetPosition((int)floor(GetPosX()) + 0.5, GetPosY(), (int)floor(GetPosZ()) + 0.5); + return true; + } + break; + } + default: break; + } + return false; +} + + + + + void cMinecart::DoTakeDamage(TakeDamageInfo & TDI) { if (TDI.Attacker->IsPlayer() && ((cPlayer *)TDI.Attacker)->IsGameModeCreative()) @@ -464,6 +659,18 @@ void cMinecart::DoTakeDamage(TakeDamageInfo & TDI) +void cMinecart::Destroyed() +{ + if (m_bIsOnDetectorRail) + { + m_World->SetBlock(m_DetectorRailPosition.x, m_DetectorRailPosition.y, m_DetectorRailPosition.z, E_BLOCK_DETECTOR_RAIL, m_World->GetBlockMeta(m_DetectorRailPosition) & 0x07); + } +} + + + + + /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cEmptyMinecart: diff --git a/src/Entities/Minecart.h b/src/Entities/Minecart.h index e353e18d9..feb700b71 100644 --- a/src/Entities/Minecart.h +++ b/src/Entities/Minecart.h @@ -51,6 +51,7 @@ public: virtual void SpawnOn(cClientHandle & a_ClientHandle) override; virtual void HandlePhysics(float a_Dt, cChunk & a_Chunk) override; virtual void DoTakeDamage(TakeDamageInfo & TDI) override; + virtual void Destroyed() override; int LastDamage(void) const { return m_LastDamage; } ePayload GetPayload(void) const { return m_Payload; } @@ -58,11 +59,30 @@ public: protected: ePayload m_Payload; int m_LastDamage; + Vector3i m_DetectorRailPosition; + bool m_bIsOnDetectorRail; cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z); - void HandleRailPhysics(NIBBLETYPE a_RailMeta); + + /** Handles physics on normal rails + For each tick, slow down on flat rails, speed up or slow down on ascending/descending rails (depending on direction), and turn on curved rails + */ + void HandleRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt); + + /** Handles powered rail physics + Each tick, speed up or slow down cart, depending on metadata of rail (powered or not) + */ void HandlePoweredRailPhysics(NIBBLETYPE a_RailMeta); + + /** Handles detector rail activation + Activates detector rails when a minecart is on them. Calls HandleRailPhysics() for physics simulations + */ + void HandleDetectorRailPhysics(NIBBLETYPE a_RailMeta, float a_Dt); + + /** Snaps a minecart to a rail's axis, resetting its speed */ void SnapToRail(NIBBLETYPE a_RailMeta); + /** Tests is 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); } ; -- cgit v1.2.3 From e3b839b69ff74323f6eccba999dc4635f3520fc9 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 14 Jan 2014 18:16:13 +0000 Subject: Yes newline at end of file :D --- src/Entities/Player.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index cdedb0c5a..fa6422389 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1909,4 +1909,8 @@ void cPlayer::Detach() } } } -} \ No newline at end of file +} + + + + -- cgit v1.2.3