summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-06-10 21:43:27 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-06-10 21:43:27 +0200
commit35b79e5d710862f957bc494638a8d8906992665d (patch)
tree1c8945ad44eed86c5c572e99b277152b2d6e90e1 /src/Entities/Entity.cpp
parentCapitalising (diff)
downloadcuberite-35b79e5d710862f957bc494638a8d8906992665d.tar
cuberite-35b79e5d710862f957bc494638a8d8906992665d.tar.gz
cuberite-35b79e5d710862f957bc494638a8d8906992665d.tar.bz2
cuberite-35b79e5d710862f957bc494638a8d8906992665d.tar.lz
cuberite-35b79e5d710862f957bc494638a8d8906992665d.tar.xz
cuberite-35b79e5d710862f957bc494638a8d8906992665d.tar.zst
cuberite-35b79e5d710862f957bc494638a8d8906992665d.zip
Diffstat (limited to 'src/Entities/Entity.cpp')
-rw-r--r--src/Entities/Entity.cpp130
1 files changed, 89 insertions, 41 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 2d8f385cb..4b376a1fe 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -12,6 +12,7 @@
#include "../Bindings/PluginManager.h"
#include "../Tracer.h"
#include "Player.h"
+#include "BlockArea.h"
@@ -1047,6 +1048,28 @@ void cEntity::DetectPortal()
return;
}
+ class cPortalChunkLoader : public cChunkStay
+ {
+ public:
+ cPortalChunkLoader(cEntity * a_Entity, Vector3i & a_PortalPos) :
+ m_Entity(a_Entity),
+ m_PortalPos(a_PortalPos)
+ {}
+
+ private:
+ virtual bool OnAllChunksAvailable(void) override
+ {
+ m_Entity->CreateExitPortal(m_PortalPos.x, m_PortalPos.y, m_PortalPos.z);
+ return true;
+ }
+
+ virtual void OnChunkAvailable(int a_ChunkX, int a_ChunkZ) override {};
+ virtual void OnDisabled(void) override {};
+
+ cEntity * m_Entity;
+ Vector3i m_PortalPos;
+ };
+
int X = POSX_TOINT, Y = POSY_TOINT, Z = POSZ_TOINT;
if ((Y > 0) && (Y < cChunkDef::Height))
{
@@ -1061,31 +1084,31 @@ void cEntity::DetectPortal()
switch (GetWorld()->GetDimension())
{
- case dimNether:
+ case dimNether: MoveToWorld(GetWorld()->GetLinkedOverworldName(), cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName())); break;
+ case dimOverworld:
{
- cIniFile OwnIni;
- OwnIni.ReadFile(GetWorld()->GetIniFileName());
- AString OverworldName = OwnIni.GetValue("General", "OverworldName", cRoot::Get()->GetDefaultWorld()->GetName());
+ if (IsPlayer())
+ {
+ ((cPlayer *)this)->AwardAchievement(achEnterPortal);
+ }
+ MoveToWorld(GetWorld()->GetNetherWorldName(), cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetNetherWorldName(), dimNether, GetWorld()->GetName()));
+
+ cChunkStay * Stay = new cPortalChunkLoader(this, Vector3i(X, Y, Z));
- cFile::CreateFolder(FILE_IO_PREFIX + OverworldName);
- cIniFile File;
- File.ReadFile(OverworldName + "/world.ini");
- File.SetValue("General", "Dimension", "Overworld");
- File.WriteFile(OverworldName + "/world.ini");
+ int MinChunkX, MaxChunkX;
+ int MinChunkZ, MaxChunkZ;
+ cChunkDef::BlockToChunk(X - 128, Z - 128, MinChunkX, MinChunkZ);
+ cChunkDef::BlockToChunk(X + 128, Z + 128, MaxChunkX, MaxChunkZ);
- MoveToWorld(OverworldName, cRoot::Get()->CreateAndInitializeWorld(OverworldName));
- break;
- }
- case dimOverworld:
- {
- cFile::CreateFolder(FILE_IO_PREFIX + GetWorld()->GetNetherWorldName());
- cIniFile File;
- File.ReadFile(GetWorld()->GetNetherWorldName() + "/world.ini");
- File.SetValue("General", "Dimension", "Nether");
- File.SetValue("General", "OverworldName", GetWorld()->GetName());
- File.WriteFile(GetWorld()->GetNetherWorldName() + "/world.ini");
-
- MoveToWorld(GetWorld()->GetNetherWorldName(), cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetNetherWorldName()));
+ for (int OtherMinChunkX = MinChunkX; OtherMinChunkX <= MaxChunkX; ++OtherMinChunkX)
+ {
+ for (int OtherMinChunkZ = MinChunkZ; OtherMinChunkZ <= MaxChunkZ; ++OtherMinChunkZ)
+ {
+ Stay->Add(OtherMinChunkX, OtherMinChunkZ);
+ }
+ }
+
+ Stay->Enable(*GetWorld()->GetChunkMap());
break;
}
default: break;
@@ -1103,17 +1126,7 @@ void cEntity::DetectPortal()
{
case dimEnd:
{
- cIniFile OwnIni;
- OwnIni.ReadFile(GetWorld()->GetIniFileName());
- AString OverworldName = OwnIni.GetValue("General", "OverworldName", cRoot::Get()->GetDefaultWorld()->GetName());
-
- 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));
+ MoveToWorld(GetWorld()->GetLinkedOverworldName(), cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetLinkedOverworldName()));
if (IsPlayer())
{
@@ -1124,14 +1137,11 @@ void cEntity::DetectPortal()
}
case dimOverworld:
{
- cFile::CreateFolder(FILE_IO_PREFIX + GetWorld()->GetEndWorldName());
- cIniFile File;
- File.ReadFile(GetWorld()->GetEndWorldName() + "/world.ini");
- File.SetValue("General", "Dimension", "End");
- File.SetValue("General", "OverworldName", GetWorld()->GetName());
- File.WriteFile(GetWorld()->GetEndWorldName() + "/world.ini");
-
- MoveToWorld(GetWorld()->GetEndWorldName(), cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetEndWorldName()));
+ if (IsPlayer())
+ {
+ ((cPlayer *)this)->AwardAchievement(achEnterTheEnd);
+ }
+ MoveToWorld(GetWorld()->GetEndWorldName(), cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetEndWorldName(), dimEnd, GetWorld()->GetName()));
break;
}
default: break;
@@ -1146,6 +1156,44 @@ void cEntity::DetectPortal()
+void cEntity::CreateExitPortal(int a_BlockX, int a_BlockY, int a_BlockZ)
+{
+ cBlockArea Area;
+ Area.Read(GetWorld(), a_BlockX - 128, a_BlockX + 128, 0, 128, a_BlockZ - 128, a_BlockZ + 128);
+ for (int x = a_BlockX - 128; x <= a_BlockX + 128; ++x) for (int y = 0; y <= 128; ++y) for (int z = a_BlockZ - 128; z <= a_BlockZ + 128; ++z)
+ {
+ if (
+ (Area.GetBlockType(x, y, z) == E_BLOCK_NETHER_PORTAL) &&
+ (
+ (Area.GetBlockType(x, (int)floor(y + GetHeight()), z) == E_BLOCK_NETHER_PORTAL) ||
+ (Area.GetBlockType(x, (int)floor(y - GetHeight()), z) == E_BLOCK_NETHER_PORTAL)
+ )
+ )
+ {
+ TeleportToCoords(x, y, z);
+ return;
+ }
+ }
+
+ int MinX = std::max(a_BlockX - (int)ceil(GetWidth()), a_BlockX - 2), MaxX = std::max(a_BlockX + (int)ceil(GetWidth()), a_BlockX + 1);
+ int MinY = std::max(a_BlockY - (int)ceil(GetHeight()), a_BlockY - 2), MaxY = std::max(a_BlockY + (int)ceil(GetHeight()), a_BlockY + 1);
+
+ for (int y = MinY; y < MaxY + 1; y += MaxY - MinY) for (int x = MinX; x < MaxX + 1; ++x)
+ {
+ Area.SetBlockType(x, y, a_BlockZ, E_BLOCK_OBSIDIAN);
+ }
+ for (int y = MinY; y < MaxY + 1; ++y) for (int x = MinX; x < MaxX + 1; x += MaxX - MinX)
+ {
+ Area.SetBlockType(x, y, a_BlockZ, E_BLOCK_OBSIDIAN);
+ }
+
+ Area.Write(GetWorld(), MinX, MinY, a_BlockZ);
+}
+
+
+
+
+
bool cEntity::MoveToWorld(const AString & a_WorldName, cWorld * a_World)
{
cWorld * World;