summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Entities/Entity.cpp')
-rw-r--r--src/Entities/Entity.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 593bc6aca..b207e79c9 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1499,12 +1499,28 @@ bool cEntity::DoMoveToWorld(cWorld * a_World, bool a_ShouldSendRespawn, Vector3d
return false;
}
- // Remove all links to the old world
- SetWorldTravellingFrom(GetWorld()); // cChunk::Tick() handles entity removal
+ // Remove entity from chunk
+ if (!GetWorld()->DoWithChunk(GetChunkX(), GetChunkZ(), [this](cChunk & a_Chunk) -> bool
+ {
+ a_Chunk.SafeRemoveEntity(this);
+ return true;
+ }))
+ {
+ LOGD("Entity Teleportation failed! Didn't find the source chunk!\n");
+ return false;
+ }
+
GetWorld()->BroadcastDestroyEntity(*this);
SetPosition(a_NewPosition);
+ if (this->IsMob())
+ {
+ cMonster * Monster = static_cast<cMonster*>(this);
+ Monster->SetTarget(nullptr);
+ Monster->StopEveryoneFromTargetingMe();
+ }
+
// Queue add to new world
a_World->AddEntity(this);
cWorld * OldWorld = cRoot::Get()->GetWorld(GetWorld()->GetName()); // Required for the hook HOOK_ENTITY_CHANGED_WORLD