summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-05-31 23:28:51 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-05-31 23:28:51 +0200
commit8bff3e5af220070ecc789ef551c0b8428b8953ef (patch)
tree4e0b04d1595f8441a9ca5f319ea94244143294db /src/Entities/Entity.cpp
parentVery minor code changes (diff)
downloadcuberite-8bff3e5af220070ecc789ef551c0b8428b8953ef.tar
cuberite-8bff3e5af220070ecc789ef551c0b8428b8953ef.tar.gz
cuberite-8bff3e5af220070ecc789ef551c0b8428b8953ef.tar.bz2
cuberite-8bff3e5af220070ecc789ef551c0b8428b8953ef.tar.lz
cuberite-8bff3e5af220070ecc789ef551c0b8428b8953ef.tar.xz
cuberite-8bff3e5af220070ecc789ef551c0b8428b8953ef.tar.zst
cuberite-8bff3e5af220070ecc789ef551c0b8428b8953ef.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Entity.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 1226a2319..b5c272cf2 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -629,6 +629,7 @@ void cEntity::Tick(float a_Dt, cChunk & a_Chunk)
// Handle drowning
HandleAir();
}
+ DetectPortal();
// None of the above functions change position, we remain in the chunk of NextChunk
HandlePhysics(a_Dt, *NextChunk);
@@ -1039,6 +1040,122 @@ void cEntity::DetectCacti(void)
+void cEntity::DetectPortal()
+{
+ int X = POSX_TOINT, Y = POSY_TOINT, Z = POSZ_TOINT;
+ if ((Y > 0) && (Y < cChunkDef::Height))
+ {
+ switch (GetWorld()->GetBlock(X, Y, Z))
+ {
+ case E_BLOCK_NETHER_PORTAL:
+ {
+ switch (GetWorld()->GetDimension())
+ {
+ case dimNether:
+ {
+ AString OverworldName = GetWorld()->GetName().substr(0, GetWorld()->GetName().size() - 7);
+ cFile::CreateFolder(FILE_IO_PREFIX + OverworldName);
+ cIniFile File;
+ File.ReadFile(OverworldName + "/world.ini");
+ File.SetValue("General", "Dimension", "Overworld");
+ File.WriteFile(OverworldName + "/world.ini");
+
+ MoveToWorld(OverworldName, cRoot::Get()->CreateAndInitializeWorld(OverworldName));
+ break;
+ }
+ case dimOverworld:
+ {
+ AString NetherWorldName = GetWorld()->GetName() + "_nether";
+ cFile::CreateFolder(FILE_IO_PREFIX + NetherWorldName);
+ cIniFile File;
+ File.ReadFile(NetherWorldName + "/world.ini");
+ File.SetValue("General", "Dimension", "Nether");
+ File.WriteFile(NetherWorldName + "/world.ini");
+
+ MoveToWorld(NetherWorldName, cRoot::Get()->CreateAndInitializeWorld(NetherWorldName));
+ break;
+ }
+ default: break;
+ }
+ break;
+ }
+ case E_BLOCK_END_PORTAL:
+ {
+ switch (GetWorld()->GetDimension())
+ {
+ case dimEnd:
+ {
+ AString OverworldName = GetWorld()->GetName().substr(0, GetWorld()->GetName().size() - 4);
+ cFile::CreateFolder(FILE_IO_PREFIX + OverworldName);
+ cIniFile File;
+ File.ReadFile(OverworldName + "/world.ini");
+ File.SetValue("General", "Dimension", "Overworld");
+ File.WriteFile(OverworldName + "/world.ini");
+
+ MoveToWorld(OverworldName, cRoot::Get()->CreateAndInitializeWorld(OverworldName));
+ break;
+ }
+ case dimOverworld:
+ {
+ AString EndWorldName = GetWorld()->GetName() + "_end";
+ cFile::CreateFolder(FILE_IO_PREFIX + EndWorldName);
+ cIniFile File;
+ File.ReadFile(EndWorldName + "/world.ini");
+ File.SetValue("General", "Dimension", "End");
+ File.WriteFile(EndWorldName + "/world.ini");
+
+ MoveToWorld(EndWorldName, cRoot::Get()->CreateAndInitializeWorld(EndWorldName));
+ break;
+ }
+ default: break;
+ }
+ }
+ default: break;
+ }
+ }
+}
+
+
+
+
+
+bool cEntity::MoveToWorld(const AString & a_WorldName, cWorld * a_World)
+{
+ cWorld * World;
+ if (a_World == NULL)
+ {
+ World = cRoot::Get()->GetWorld(a_WorldName);
+ if (World == NULL)
+ {
+ LOG("%s: Couldn't find world \"%s\".", __FUNCTION__, a_WorldName);
+ return false;
+ }
+ }
+ else
+ {
+ World = a_World;
+ }
+
+ if (GetWorld() == World)
+ {
+ return false;
+ }
+
+ // Remove all links to the old world
+ GetWorld()->RemoveEntity(this);
+ GetWorld()->BroadcastDestroyEntity(*this);
+
+ // Add to all the necessary parts of the new world
+ SetWorld(World);
+ World->AddEntity(this);
+
+ return true;
+}
+
+
+
+
+
void cEntity::SetSwimState(cChunk & a_Chunk)
{
int RelY = (int)floor(GetPosY() + 0.1);