diff options
author | Mattes D <github@xoft.cz> | 2016-08-29 13:32:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-29 13:32:34 +0200 |
commit | c6c2c5afdf883e2a330b02425e59e5ac5ff25ae3 (patch) | |
tree | f1d9104b186d02f5da8f31ed8ce124bfbff3f6b2 /src/Entities | |
parent | Fixed SendUnloadChunk bug (#3353) (diff) | |
parent | Proper respawn packets on dimension travel (diff) | |
download | cuberite-c6c2c5afdf883e2a330b02425e59e5ac5ff25ae3.tar cuberite-c6c2c5afdf883e2a330b02425e59e5ac5ff25ae3.tar.gz cuberite-c6c2c5afdf883e2a330b02425e59e5ac5ff25ae3.tar.bz2 cuberite-c6c2c5afdf883e2a330b02425e59e5ac5ff25ae3.tar.lz cuberite-c6c2c5afdf883e2a330b02425e59e5ac5ff25ae3.tar.xz cuberite-c6c2c5afdf883e2a330b02425e59e5ac5ff25ae3.tar.zst cuberite-c6c2c5afdf883e2a330b02425e59e5ac5ff25ae3.zip |
Diffstat (limited to 'src/Entities')
-rw-r--r-- | src/Entities/Entity.cpp | 47 | ||||
-rw-r--r-- | src/Entities/Player.cpp | 9 | ||||
-rw-r--r-- | src/Entities/Player.h | 3 |
3 files changed, 50 insertions, 9 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 2adbc3142..b2fa56143 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1433,19 +1433,22 @@ bool cEntity::DetectPortal() } m_PortalCooldownData.m_TicksDelayed = 0; + // Nether portal in the nether if (GetWorld()->GetDimension() == dimNether) { if (GetWorld()->GetLinkedOverworldName().empty()) { return false; } + cWorld * DestinationWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName()); + eDimension DestionationDim = DestinationWorld->GetDimension(); m_PortalCooldownData.m_ShouldPreventTeleportation = true; // Stop portals from working on respawn if (IsPlayer()) { // Send a respawn packet before world is loaded / generated so the client isn't left in limbo - (reinterpret_cast<cPlayer *>(this))->GetClientHandle()->SendRespawn(dimOverworld); + (reinterpret_cast<cPlayer *>(this))->GetClientHandle()->SendRespawn(DestionationDim); } Vector3d TargetPos = GetPosition(); @@ -1454,23 +1457,30 @@ bool cEntity::DetectPortal() cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName()); ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start() - LOGD("Jumping nether -> overworld"); + LOGD("Jumping %s -> %s", DimensionToString(dimNether).c_str(), DimensionToString(DestionationDim).c_str()); new cNetherPortalScanner(this, TargetWorld, TargetPos, 256); return true; } + // Nether portal in the overworld else { if (GetWorld()->GetLinkedNetherWorldName().empty()) { return false; } + cWorld * DestinationWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedNetherWorldName()); + eDimension DestionationDim = DestinationWorld->GetDimension(); m_PortalCooldownData.m_ShouldPreventTeleportation = true; if (IsPlayer()) { - reinterpret_cast<cPlayer *>(this)->AwardAchievement(achEnterPortal); - reinterpret_cast<cPlayer *>(this)->GetClientHandle()->SendRespawn(dimNether); + if (DestionationDim == dimNether) + { + reinterpret_cast<cPlayer *>(this)->AwardAchievement(achEnterPortal); + } + + reinterpret_cast<cPlayer *>(this)->GetClientHandle()->SendRespawn(DestionationDim); } Vector3d TargetPos = GetPosition(); @@ -1479,7 +1489,7 @@ bool cEntity::DetectPortal() cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedNetherWorldName()); ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start() - LOGD("Jumping overworld -> nether"); + LOGD("Jumping %s -> %s", DimensionToString(dimOverworld).c_str(), DimensionToString(DestionationDim).c_str()); new cNetherPortalScanner(this, TargetWorld, TargetPos, 128); return true; } @@ -1491,6 +1501,7 @@ bool cEntity::DetectPortal() return false; } + // End portal in the end if (GetWorld()->GetDimension() == dimEnd) { @@ -1498,37 +1509,55 @@ bool cEntity::DetectPortal() { return false; } + cWorld * DestinationWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName()); + eDimension DestionationDim = DestinationWorld->GetDimension(); + m_PortalCooldownData.m_ShouldPreventTeleportation = true; if (IsPlayer()) { cPlayer * Player = reinterpret_cast<cPlayer *>(this); - Player->TeleportToCoords(Player->GetLastBedPos().x, Player->GetLastBedPos().y, Player->GetLastBedPos().z); - Player->GetClientHandle()->SendRespawn(dimOverworld); + if (Player->GetBedWorld() == DestinationWorld) + { + Player->TeleportToCoords(Player->GetLastBedPos().x, Player->GetLastBedPos().y, Player->GetLastBedPos().z); + } + else + { + Player->TeleportToCoords(DestinationWorld->GetSpawnX(), DestinationWorld->GetSpawnY(), DestinationWorld->GetSpawnZ()); + } + Player->GetClientHandle()->SendRespawn(DestionationDim); } cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedOverworldName()); ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start() + LOGD("Jumping %s -> %s", DimensionToString(dimEnd).c_str(), DimensionToString(DestionationDim).c_str()); return MoveToWorld(TargetWorld, false); } + // End portal in the overworld else { if (GetWorld()->GetLinkedEndWorldName().empty()) { return false; } + cWorld * DestinationWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedEndWorldName()); + eDimension DestionationDim = DestinationWorld->GetDimension(); m_PortalCooldownData.m_ShouldPreventTeleportation = true; if (IsPlayer()) { - reinterpret_cast<cPlayer *>(this)->AwardAchievement(achEnterTheEnd); - reinterpret_cast<cPlayer *>(this)->GetClientHandle()->SendRespawn(dimEnd); + if (DestionationDim == dimEnd) + { + reinterpret_cast<cPlayer *>(this)->AwardAchievement(achEnterTheEnd); + } + reinterpret_cast<cPlayer *>(this)->GetClientHandle()->SendRespawn(DestionationDim); } cWorld * TargetWorld = cRoot::Get()->GetWorld(GetWorld()->GetLinkedEndWorldName()); ASSERT(TargetWorld != nullptr); // The linkage checker should have prevented this at startup. See cWorld::start() + LOGD("Jumping %s -> %s", DimensionToString(dimOverworld).c_str(), DimensionToString(DestionationDim).c_str()); return MoveToWorld(TargetWorld, false); } diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 50bec3608..f28258969 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -893,6 +893,15 @@ void cPlayer::SetBedPos(const Vector3i & a_Pos, cWorld * a_World) +cWorld * cPlayer::GetBedWorld() +{ + return m_SpawnWorld; +} + + + + + void cPlayer::SetFlying(bool a_IsFlying) { if (a_IsFlying == m_IsFlying) diff --git a/src/Entities/Player.h b/src/Entities/Player.h index f6e9da45e..25796ee50 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -467,6 +467,9 @@ public: // tolua_end + // TODO lua export GetBedPos and GetBedWorld + cWorld * GetBedWorld(); + /** Update movement-related statistics. */ void UpdateMovementStats(const Vector3d & a_DeltaPos, bool a_PreviousIsOnGround); |